File: options_test.rb

package info (click to toggle)
ruby-uber 0.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 216 kB
  • sloc: ruby: 466; makefile: 4
file content (33 lines) | stat: -rw-r--r-- 1,016 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
require 'test_helper'
require 'uber/options'

class UberOptionsTest < Minitest::Spec
  Options = Uber::Options

  let (:dynamic) { Options.new(:volume =>1, :style => "Punkrock", :track => Proc.new { |i| i.to_s }) }

  describe "#evaluate" do
    it { dynamic.evaluate(Object.new, 999).must_equal({:volume =>1, :style => "Punkrock", :track => "999"}) }

    describe "static" do
      let (:static) { Options.new(:volume =>1, :style => "Punkrock") }

      it { static.evaluate(nil).must_equal({:volume =>1, :style => "Punkrock"}) }

      it "doesn't evaluate internally" do
        static.instance_eval do
          def evaluate_for(*)
            raise "i shouldn't be called!"
          end
        end
        static.evaluate(nil).must_equal({:volume =>1, :style => "Punkrock"})
      end
    end
  end

  describe "#eval" do
    it { dynamic.eval(:volume, 999).must_equal 1 }
    it { dynamic.eval(:style, 999).must_equal "Punkrock" }
    it { dynamic.eval(:track, Object.new, 999).must_equal "999" }
  end
end