rr 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. data/CHANGES +5 -0
  2. data/README +13 -0
  3. data/Rakefile +1 -1
  4. data/lib/rr.rb +3 -3
  5. data/lib/rr/adapters/rr_methods.rb +5 -5
  6. data/lib/rr/double.rb +5 -5
  7. data/lib/rr/double_creator.rb +13 -13
  8. data/lib/rr/double_definition.rb +3 -3
  9. data/lib/rr/double_injection.rb +24 -24
  10. data/lib/rr/double_matches.rb +29 -29
  11. data/lib/rr/errors/{scenario_definition_error.rb → double_definition_error.rb} +0 -0
  12. data/lib/rr/errors/{scenario_not_found_error.rb → double_not_found_error.rb} +0 -0
  13. data/lib/rr/errors/{scenario_order_error.rb → double_order_error.rb} +0 -0
  14. data/lib/rr/expectations/times_called_expectation.rb +4 -4
  15. data/lib/rr/space.rb +22 -22
  16. data/spec/rr/adapters/rr_methods_creator_spec.rb +69 -69
  17. data/spec/rr/adapters/rr_methods_space_spec.rb +11 -11
  18. data/spec/rr/double/double_injection_dispatching_spec.rb +66 -66
  19. data/spec/rr/double/double_injection_register_scenario_spec.rb +8 -8
  20. data/spec/rr/double/double_injection_verify_spec.rb +4 -4
  21. data/spec/rr/double_creator_spec.rb +65 -65
  22. data/spec/rr/double_definition_spec.rb +9 -9
  23. data/spec/rr/double_method_proxy_spec.rb +7 -7
  24. data/spec/rr/double_spec.rb +199 -199
  25. data/spec/rr/expectations/times_called_expectation/times_called_expectation_any_times_spec.rb +1 -1
  26. data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_least_spec.rb +1 -1
  27. data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_most_spec.rb +1 -1
  28. data/spec/rr/expectations/times_called_expectation/times_called_expectation_helper.rb +3 -3
  29. data/spec/rr/expectations/times_called_expectation/times_called_expectation_integer_spec.rb +1 -1
  30. data/spec/rr/expectations/times_called_expectation/times_called_expectation_proc_spec.rb +1 -1
  31. data/spec/rr/expectations/times_called_expectation/times_called_expectation_range_spec.rb +1 -1
  32. data/spec/rr/expectations/times_called_expectation/times_called_expectation_spec.rb +4 -4
  33. data/spec/rr/rspec/rspec_adapter_spec.rb +2 -2
  34. data/spec/rr/space/space_create_spec.rb +37 -37
  35. data/spec/rr/space/space_register_spec.rb +9 -9
  36. data/spec/rr/space/space_reset_spec.rb +7 -7
  37. data/spec/rr/space/space_verify_spec.rb +31 -31
  38. metadata +5 -5
@@ -8,7 +8,7 @@ module RR
8
8
 
9
9
  before do
10
10
  @at_least = TimesCalledMatchers::AnyTimesMatcher.new
11
- @expectation = TimesCalledExpectation.new(scenario, at_least)
11
+ @expectation = TimesCalledExpectation.new(double, at_least)
12
12
  end
13
13
 
14
14
  describe "#verify!" do
@@ -9,7 +9,7 @@ module Expectations
9
9
  before do
10
10
  @times = 3
11
11
  @at_least = TimesCalledMatchers::AtLeastMatcher.new(times)
12
- @expectation = TimesCalledExpectation.new(scenario, at_least)
12
+ @expectation = TimesCalledExpectation.new(double, at_least)
13
13
  end
14
14
 
15
15
  describe "#verify!" do
@@ -9,7 +9,7 @@ module RR
9
9
  before do
10
10
  @times = 3
11
11
  @at_most = TimesCalledMatchers::AtMostMatcher.new(times)
12
- @expectation = TimesCalledExpectation.new(scenario, at_most)
12
+ @expectation = TimesCalledExpectation.new(double, at_most)
13
13
  end
14
14
 
15
15
  describe "#verify!" do
@@ -3,14 +3,14 @@ require "spec/spec_helper"
3
3
  module RR
4
4
  module Expectations
5
5
  describe TimesCalledExpectation, :shared => true do
6
- attr_reader :space, :object, :method_name, :double_insertion, :scenario, :expectation
6
+ attr_reader :space, :object, :method_name, :double_insertion, :double, :expectation
7
7
  before do
8
8
  @space = Space.new
9
9
  @object = Object.new
10
10
  @method_name = :foobar
11
11
  @double_insertion = space.double_insertion(object, method_name)
12
- @scenario = space.scenario(double_insertion)
13
- scenario.with_any_args
12
+ @double = space.double(double_insertion)
13
+ double.with_any_args
14
14
  end
15
15
 
16
16
  def raises_expectation_error(&block)
@@ -8,7 +8,7 @@ module RR
8
8
 
9
9
  before do
10
10
  @matcher = TimesCalledMatchers::IntegerMatcher.new(2)
11
- @expectation = TimesCalledExpectation.new(scenario, matcher)
11
+ @expectation = TimesCalledExpectation.new(double, matcher)
12
12
  @expected_line = __LINE__ - 1
13
13
  end
14
14
 
@@ -8,7 +8,7 @@ module RR
8
8
 
9
9
  before do
10
10
  @matcher = TimesCalledMatchers::ProcMatcher.new(proc {|value| value == 2})
11
- @expectation = TimesCalledExpectation.new(scenario, matcher)
11
+ @expectation = TimesCalledExpectation.new(double, matcher)
12
12
  end
13
13
 
14
14
  describe "#verify" do
@@ -8,7 +8,7 @@ module RR
8
8
 
9
9
  before do
10
10
  @matcher = TimesCalledMatchers::RangeMatcher.new(1..2)
11
- @expectation = TimesCalledExpectation.new(scenario, matcher)
11
+ @expectation = TimesCalledExpectation.new(double, matcher)
12
12
  end
13
13
 
14
14
  describe "#verify" do
@@ -9,16 +9,16 @@ module RR
9
9
  before do
10
10
  @times = 0
11
11
  @matcher = TimesCalledMatchers::IntegerMatcher.new(times)
12
- @expectation = TimesCalledExpectation.new(scenario, matcher)
12
+ @expectation = TimesCalledExpectation.new(double, matcher)
13
13
  end
14
14
 
15
15
  describe "#attempt!" do
16
- it "raises error that includes the scenario" do
16
+ it "raises error that includes the double" do
17
17
  proc do
18
18
  expectation.attempt!
19
19
  end.should raise_error(
20
20
  Errors::TimesCalledError,
21
- "#{scenario.formatted_name}\n#{matcher.error_message(1)}"
21
+ "#{double.formatted_name}\n#{matcher.error_message(1)}"
22
22
  )
23
23
  end
24
24
  end
@@ -30,7 +30,7 @@ module RR
30
30
  expectation.verify!
31
31
  end.should raise_error(
32
32
  Errors::TimesCalledError,
33
- "#{scenario.formatted_name}\n#{matcher.error_message(1)}"
33
+ "#{double.formatted_name}\n#{matcher.error_message(1)}"
34
34
  )
35
35
  end
36
36
  end
@@ -32,9 +32,9 @@ module RR
32
32
 
33
33
  it "verifies the double_insertions" do
34
34
  double_insertion = RR::Space.double_insertion(@subject, @method_name)
35
- scenario = RR::Space.scenario(double_insertion)
35
+ double = RR::Space.double(double_insertion)
36
36
 
37
- scenario.once
37
+ double.once
38
38
 
39
39
  proc do
40
40
  @fixture.verify_mocks_for_rspec
@@ -1,7 +1,7 @@
1
1
  require "spec/spec_helper"
2
2
 
3
3
  module RR
4
- describe Space, "#scenario_method_proxy", :shared => true do
4
+ describe Space, "#double_method_proxy", :shared => true do
5
5
  it_should_behave_like "RR::Space"
6
6
 
7
7
  before do
@@ -10,12 +10,12 @@ module RR
10
10
  end
11
11
 
12
12
  it "creates a DoubleMethodProxy" do
13
- proxy = @space.scenario_method_proxy(@creator, @object)
13
+ proxy = @space.double_method_proxy(@creator, @object)
14
14
  proxy.should be_instance_of(DoubleMethodProxy)
15
15
  end
16
16
 
17
17
  it "sets space to self" do
18
- proxy = @space.scenario_method_proxy(@creator, @object)
18
+ proxy = @space.double_method_proxy(@creator, @object)
19
19
  class << proxy
20
20
  attr_reader :space
21
21
  end
@@ -23,7 +23,7 @@ module RR
23
23
  end
24
24
 
25
25
  it "sets creator to passed in creator" do
26
- proxy = @space.scenario_method_proxy(@creator, @object)
26
+ proxy = @space.double_method_proxy(@creator, @object)
27
27
  class << proxy
28
28
  attr_reader :creator
29
29
  end
@@ -32,27 +32,27 @@ module RR
32
32
 
33
33
  it "raises error if passed a method name and a block" do
34
34
  proc do
35
- @space.scenario_method_proxy(@creator, @object, :foobar) {}
35
+ @space.double_method_proxy(@creator, @object, :foobar) {}
36
36
  end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
37
37
  end
38
38
  end
39
39
 
40
- describe Space, "#scenario_method_proxy with a Mock strategy" do
41
- it_should_behave_like "RR::Space#scenario_method_proxy"
40
+ describe Space, "#double_method_proxy with a Mock strategy" do
41
+ it_should_behave_like "RR::Space#double_method_proxy"
42
42
 
43
43
  before do
44
- @creator = @space.scenario_creator
44
+ @creator = @space.double_creator
45
45
  @creator.mock
46
46
  end
47
47
 
48
48
  it "creates a mock Double for method when passed a second argument" do
49
- @space.scenario_method_proxy(@creator, @object, :foobar).with(1) {:baz}
49
+ @space.double_method_proxy(@creator, @object, :foobar).with(1) {:baz}
50
50
  @object.foobar(1).should == :baz
51
51
  proc {@object.foobar(1)}.should raise_error(Errors::TimesCalledError)
52
52
  end
53
53
 
54
54
  it "uses block definition when passed a block" do
55
- @space.scenario_method_proxy(@creator, @object) do |c|
55
+ @space.double_method_proxy(@creator, @object) do |c|
56
56
  c.foobar(1) {:baz}
57
57
  end
58
58
  @object.foobar(1).should == :baz
@@ -60,22 +60,22 @@ module RR
60
60
  end
61
61
  end
62
62
 
63
- describe Space, "#scenario_method_proxy with a Stub strategy" do
64
- it_should_behave_like "RR::Space#scenario_method_proxy"
63
+ describe Space, "#double_method_proxy with a Stub strategy" do
64
+ it_should_behave_like "RR::Space#double_method_proxy"
65
65
 
66
66
  before do
67
- @creator = @space.scenario_creator
67
+ @creator = @space.double_creator
68
68
  @creator.stub
69
69
  end
70
70
 
71
71
  it "creates a stub Double for method when passed a second argument" do
72
- @space.scenario_method_proxy(@creator, @object, :foobar).with(1) {:baz}
72
+ @space.double_method_proxy(@creator, @object, :foobar).with(1) {:baz}
73
73
  @object.foobar(1).should == :baz
74
74
  @object.foobar(1).should == :baz
75
75
  end
76
76
 
77
77
  it "uses block definition when passed a block" do
78
- @space.scenario_method_proxy(@creator, @object) do |c|
78
+ @space.double_method_proxy(@creator, @object) do |c|
79
79
  c.foobar(1) {:return_value}
80
80
  c.foobar.with_any_args {:default}
81
81
  c.baz(1) {:baz_value}
@@ -86,11 +86,11 @@ module RR
86
86
  end
87
87
  end
88
88
 
89
- describe Space, "#scenario_method_proxy with a Mock Proxy strategy" do
90
- it_should_behave_like "RR::Space#scenario_method_proxy"
89
+ describe Space, "#double_method_proxy with a Mock Proxy strategy" do
90
+ it_should_behave_like "RR::Space#double_method_proxy"
91
91
 
92
92
  before do
93
- @creator = @space.scenario_creator
93
+ @creator = @space.double_creator
94
94
  @creator.mock.proxy
95
95
  def @object.foobar(*args)
96
96
  :original_foobar
@@ -98,13 +98,13 @@ module RR
98
98
  end
99
99
 
100
100
  it "creates a mock proxy Double for method when passed a second argument" do
101
- @space.scenario_method_proxy(@creator, @object, :foobar).with(1)
101
+ @space.double_method_proxy(@creator, @object, :foobar).with(1)
102
102
  @object.foobar(1).should == :original_foobar
103
103
  proc {@object.foobar(1)}.should raise_error(Errors::TimesCalledError)
104
104
  end
105
105
 
106
106
  it "uses block definition when passed a block" do
107
- @space.scenario_method_proxy(@creator, @object) do |c|
107
+ @space.double_method_proxy(@creator, @object) do |c|
108
108
  c.foobar(1)
109
109
  end
110
110
  @object.foobar(1).should == :original_foobar
@@ -112,11 +112,11 @@ module RR
112
112
  end
113
113
  end
114
114
 
115
- describe Space, "#scenario_method_proxy with a Stub proxy strategy" do
116
- it_should_behave_like "RR::Space#scenario_method_proxy"
115
+ describe Space, "#double_method_proxy with a Stub proxy strategy" do
116
+ it_should_behave_like "RR::Space#double_method_proxy"
117
117
 
118
118
  before do
119
- @creator = @space.scenario_creator
119
+ @creator = @space.double_creator
120
120
  @creator.stub.proxy
121
121
  def @object.foobar(*args)
122
122
  :original_foobar
@@ -124,13 +124,13 @@ module RR
124
124
  end
125
125
 
126
126
  it "creates a stub proxy Double for method when passed a second argument" do
127
- @space.scenario_method_proxy(@creator, @object, :foobar)
127
+ @space.double_method_proxy(@creator, @object, :foobar)
128
128
  @object.foobar(1).should == :original_foobar
129
129
  @object.foobar(1).should == :original_foobar
130
130
  end
131
131
 
132
132
  it "uses block definition when passed a block" do
133
- @space.scenario_method_proxy(@creator, @object) do |c|
133
+ @space.double_method_proxy(@creator, @object) do |c|
134
134
  c.foobar(1)
135
135
  end
136
136
  @object.foobar(1).should == :original_foobar
@@ -138,34 +138,34 @@ module RR
138
138
  end
139
139
  end
140
140
 
141
- describe Space, "#scenario_method_proxy with a Do Not Allow strategy" do
142
- it_should_behave_like "RR::Space#scenario_method_proxy"
141
+ describe Space, "#double_method_proxy with a Do Not Allow strategy" do
142
+ it_should_behave_like "RR::Space#double_method_proxy"
143
143
 
144
144
  before do
145
- @creator = @space.scenario_creator
145
+ @creator = @space.double_creator
146
146
  @creator.dont_allow
147
147
  end
148
148
 
149
149
  it "creates a do not allow Double for method when passed a second argument" do
150
- @space.scenario_method_proxy(@creator, @object, :foobar).with(1)
150
+ @space.double_method_proxy(@creator, @object, :foobar).with(1)
151
151
  proc {@object.foobar(1)}.should raise_error(Errors::TimesCalledError)
152
152
  end
153
153
 
154
154
  it "uses block definition when passed a block" do
155
- @space.scenario_method_proxy(@creator, @object) do |c|
155
+ @space.double_method_proxy(@creator, @object) do |c|
156
156
  c.foobar(1)
157
157
  end
158
158
  proc {@object.foobar(1)}.should raise_error(Errors::TimesCalledError)
159
159
  end
160
160
  end
161
161
 
162
- describe Space, "#scenario_creator" do
162
+ describe Space, "#double_creator" do
163
163
  it_should_behave_like "RR::Space"
164
164
 
165
165
  before do
166
166
  @space = Space.new
167
167
  @object = Object.new
168
- @creator = @space.scenario_creator
168
+ @creator = @space.double_creator
169
169
  end
170
170
 
171
171
  it "sets the space" do
@@ -177,7 +177,7 @@ module RR
177
177
  end
178
178
  end
179
179
 
180
- describe Space, "#scenario" do
180
+ describe Space, "#double" do
181
181
  it_should_behave_like "RR::Space"
182
182
 
183
183
  before do
@@ -188,12 +188,12 @@ module RR
188
188
 
189
189
  it "creates a Double and registers it to the double_insertion" do
190
190
  double_insertion = @space.double_insertion(@object, @method_name)
191
- def double_insertion.scenarios
192
- @scenarios
191
+ def double_insertion.doubles
192
+ @doubles
193
193
  end
194
194
 
195
- scenario = @space.scenario(double_insertion)
196
- double_insertion.scenarios.should include(scenario)
195
+ double = @space.double(double_insertion)
196
+ double_insertion.doubles.should include(double)
197
197
  end
198
198
  end
199
199
 
@@ -1,7 +1,7 @@
1
1
  require "spec/spec_helper"
2
2
 
3
3
  module RR
4
- describe Space, "#register_ordered_scenario" do
4
+ describe Space, "#register_ordered_double" do
5
5
  it_should_behave_like "RR::Space"
6
6
 
7
7
  before(:each) do
@@ -17,16 +17,16 @@ module RR
17
17
  Space.instance = @original_space
18
18
  end
19
19
 
20
- it "adds the ordered scenario to the ordered_scenarios collection" do
21
- scenario1 = @space.scenario(@double_insertion)
20
+ it "adds the ordered double to the ordered_doubles collection" do
21
+ double1 = @space.double(@double_insertion)
22
22
 
23
- @space.ordered_scenarios.should == []
24
- @space.register_ordered_scenario scenario1
25
- @space.ordered_scenarios.should == [scenario1]
23
+ @space.ordered_doubles.should == []
24
+ @space.register_ordered_double double1
25
+ @space.ordered_doubles.should == [double1]
26
26
 
27
- scenario2 = @space.scenario(@double_insertion)
28
- @space.register_ordered_scenario scenario2
29
- @space.ordered_scenarios.should == [scenario1, scenario2]
27
+ double2 = @space.double(@double_insertion)
28
+ @space.register_ordered_double double2
29
+ @space.ordered_doubles.should == [double1, double2]
30
30
  end
31
31
  end
32
32
  end
@@ -11,20 +11,20 @@ module RR
11
11
  @method_name = :foobar
12
12
  end
13
13
 
14
- it "removes the ordered scenarios" do
14
+ it "removes the ordered doubles" do
15
15
  double1 = @space.double_insertion(@object1, :foobar1)
16
16
  double2 = @space.double_insertion(@object1, :foobar2)
17
17
 
18
- scenario1 = @space.scenario(double1)
19
- scenario2 = @space.scenario(double2)
18
+ double1 = @space.double(double1)
19
+ double2 = @space.double(double2)
20
20
 
21
- scenario1.ordered
22
- scenario2.ordered
21
+ double1.ordered
22
+ double2.ordered
23
23
 
24
- @space.ordered_scenarios.should_not be_empty
24
+ @space.ordered_doubles.should_not be_empty
25
25
 
26
26
  @space.reset
27
- @space.ordered_scenarios.should be_empty
27
+ @space.ordered_doubles.should be_empty
28
28
  end
29
29
 
30
30
  it "resets all double_insertions" do
@@ -1,7 +1,7 @@
1
1
  require "spec/spec_helper"
2
2
 
3
3
  module RR
4
- describe Space, "#verify_ordered_scenario", :shared => true do
4
+ describe Space, "#verify_ordered_double", :shared => true do
5
5
  before do
6
6
  @space = Space.new
7
7
  @object = Object.new
@@ -10,14 +10,14 @@ module RR
10
10
  end
11
11
 
12
12
  it "raises an error when Double is NonTerminal" do
13
- scenario = @space.scenario(@double_insertion)
14
- @space.register_ordered_scenario(scenario)
13
+ double = @space.double(@double_insertion)
14
+ @space.register_ordered_double(double)
15
15
 
16
- scenario.any_number_of_times
17
- scenario.should_not be_terminal
16
+ double.any_number_of_times
17
+ double.should_not be_terminal
18
18
 
19
19
  proc do
20
- @space.verify_ordered_scenario(scenario)
20
+ @space.verify_ordered_double(double)
21
21
  end.should raise_error(
22
22
  Errors::DoubleOrderError,
23
23
  "Ordered Doubles cannot have a NonTerminal TimesCalledExpectation"
@@ -127,42 +127,42 @@ module RR
127
127
  end
128
128
  end
129
129
 
130
- describe "#verify_ordered_scenario where the passed in scenario is at the front of the queue" do
131
- it_should_behave_like "RR::Space#verify_ordered_scenario"
130
+ describe "#verify_ordered_double where the passed in double is at the front of the queue" do
131
+ it_should_behave_like "RR::Space#verify_ordered_double"
132
132
 
133
- it "keeps the scenario when times called is not verified" do
134
- scenario = @space.scenario(@double_insertion)
135
- @space.register_ordered_scenario(scenario)
133
+ it "keeps the double when times called is not verified" do
134
+ double = @space.double(@double_insertion)
135
+ @space.register_ordered_double(double)
136
136
 
137
- scenario.twice
138
- scenario.should be_attempt
137
+ double.twice
138
+ double.should be_attempt
139
139
 
140
- @space.verify_ordered_scenario(scenario)
141
- @space.ordered_scenarios.should include(scenario)
140
+ @space.verify_ordered_double(double)
141
+ @space.ordered_doubles.should include(double)
142
142
  end
143
143
 
144
- it "removes the scenario when times called expectation should no longer be attempted" do
145
- scenario = @space.scenario(@double_insertion)
146
- @space.register_ordered_scenario(scenario)
144
+ it "removes the double when times called expectation should no longer be attempted" do
145
+ double = @space.double(@double_insertion)
146
+ @space.register_ordered_double(double)
147
147
 
148
- scenario.with(1).once
148
+ double.with(1).once
149
149
  @object.foobar(1)
150
- scenario.should_not be_attempt
150
+ double.should_not be_attempt
151
151
 
152
- @space.verify_ordered_scenario(scenario)
153
- @space.ordered_scenarios.should_not include(scenario)
152
+ @space.verify_ordered_double(double)
153
+ @space.ordered_doubles.should_not include(double)
154
154
  end
155
155
  end
156
156
 
157
- describe "#verify_ordered_scenario where the passed in scenario is not at the front of the queue" do
158
- it_should_behave_like "RR::Space#verify_ordered_scenario"
157
+ describe "#verify_ordered_double where the passed in double is not at the front of the queue" do
158
+ it_should_behave_like "RR::Space#verify_ordered_double"
159
159
 
160
160
  it "raises error" do
161
- first_scenario = scenario
162
- second_scenario = scenario
161
+ first_double = double
162
+ second_double = double
163
163
 
164
164
  proc do
165
- @space.verify_ordered_scenario(second_scenario)
165
+ @space.verify_ordered_double(second_double)
166
166
  end.should raise_error(
167
167
  Errors::DoubleOrderError,
168
168
  "foobar() called out of order in list\n" <<
@@ -171,10 +171,10 @@ module RR
171
171
  )
172
172
  end
173
173
 
174
- def scenario
175
- scenario_definition = @space.scenario(@double_insertion).once
176
- @space.register_ordered_scenario(scenario_definition.scenario)
177
- scenario_definition.scenario
174
+ def double
175
+ double_definition = @space.double(@double_insertion).once
176
+ @space.register_ordered_double(double_definition.double)
177
+ double_definition.double
178
178
  end
179
179
  end
180
180
  end