nakajima / fixjour

Word to your object mother.

This URL has Read+Write access

fixjour / spec / overrides_hash_spec.rb
100644 62 lines (51 sloc) 1.4 kb
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
require 'spec/spec_helper'
 
describe Fixjour::OverridesHash do
  attr_reader :overrides
 
  before(:each) do
    @overrides = Fixjour::OverridesHash.new(:name => "Pat")
  end
 
  it "inherits from Hash" do
    Fixjour::OverridesHash.superclass.should == Hash
  end
 
  describe "#process" do
    context "when the option isn't present" do
      it "doesn't do anything" do
        called = false
        overrides.process(:not_there) do
          called = true
        end
        called.should_not be
      end
 
      it "returns nil" do
        overrides.process(:not_there).should be_nil
      end
    end
 
    context "when the option is present" do
      it "deletes the option from the hash" do
        overrides.process(:name)
        overrides.should_not have_key(:name)
      end
 
      it "passes the value to the block" do
        overrides.process(:name) do |value|
          value.should == "Pat"
        end
      end
 
      it "allows values to be re-assigned in hash" do
        overrides.process(:name) do |value|
          overrides[:result] = value
        end
        overrides[:result].should == "Pat"
      end
 
      it "returns the value" do
        overrides.process(:name).should == "Pat"
      end
    end
  end
 
  describe "#delete" do
    it "is private" do
      proc {
        overrides.delete(:name)
      }.should raise_error(NoMethodError, /private/)
    end
  end
end