rr 0.3.11 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (150) hide show
  1. data/CHANGES +8 -3
  2. data/README +130 -39
  3. data/Rakefile +6 -5
  4. data/lib/rr.rb +8 -8
  5. data/lib/rr/adapters/rr_methods.rb +228 -0
  6. data/lib/rr/adapters/rspec.rb +1 -1
  7. data/lib/rr/adapters/test_unit.rb +1 -1
  8. data/lib/rr/double.rb +294 -89
  9. data/lib/rr/{scenario_creator.rb → double_creator.rb} +65 -66
  10. data/lib/rr/{scenario_definition.rb → double_definition.rb} +36 -36
  11. data/lib/rr/{scenario_definition_builder.rb → double_definition_builder.rb} +3 -3
  12. data/lib/rr/double_insertion.rb +132 -0
  13. data/lib/rr/{scenario_matches.rb → double_matches.rb} +2 -2
  14. data/lib/rr/{scenario_method_proxy.rb → double_method_proxy.rb} +2 -2
  15. data/lib/rr/errors/argument_equality_error.rb +3 -3
  16. data/lib/rr/errors/rr_error.rb +13 -13
  17. data/lib/rr/errors/scenario_definition_error.rb +3 -3
  18. data/lib/rr/errors/scenario_not_found_error.rb +3 -3
  19. data/lib/rr/errors/scenario_order_error.rb +3 -3
  20. data/lib/rr/errors/times_called_error.rb +3 -3
  21. data/lib/rr/expectations/any_argument_expectation.rb +1 -1
  22. data/lib/rr/expectations/argument_equality_expectation.rb +1 -1
  23. data/lib/rr/expectations/times_called_expectation.rb +1 -1
  24. data/lib/rr/hash_with_object_id_key.rb +1 -1
  25. data/lib/rr/space.rb +40 -40
  26. data/lib/rr/times_called_matchers/any_times_matcher.rb +13 -13
  27. data/lib/rr/times_called_matchers/at_least_matcher.rb +11 -11
  28. data/lib/rr/times_called_matchers/at_most_matcher.rb +16 -16
  29. data/lib/rr/times_called_matchers/integer_matcher.rb +13 -13
  30. data/lib/rr/times_called_matchers/non_terminal.rb +21 -21
  31. data/lib/rr/times_called_matchers/proc_matcher.rb +7 -7
  32. data/lib/rr/times_called_matchers/range_matcher.rb +14 -14
  33. data/lib/rr/times_called_matchers/terminal.rb +16 -16
  34. data/lib/rr/times_called_matchers/times_called_matcher.rb +32 -32
  35. data/spec/core_spec_suite.rb +18 -0
  36. data/{examples → spec}/environment_fixture_setup.rb +0 -1
  37. data/{examples/high_level_example.rb → spec/high_level_spec.rb} +11 -11
  38. data/spec/rr/adapters/rr_methods_argument_matcher_spec.rb +67 -0
  39. data/spec/rr/adapters/rr_methods_creator_spec.rb +365 -0
  40. data/spec/rr/adapters/rr_methods_space_spec.rb +134 -0
  41. data/spec/rr/adapters/rr_methods_spec_helper.rb +11 -0
  42. data/{examples/rr/extensions/instance_methods_times_matcher_example.rb → spec/rr/adapters/rr_methods_times_matcher_spec.rb} +4 -4
  43. data/spec/rr/double/double_insertion_bind_spec.rb +78 -0
  44. data/spec/rr/double/double_insertion_dispatching_spec.rb +221 -0
  45. data/spec/rr/double/double_insertion_has_original_method_spec.rb +56 -0
  46. data/spec/rr/double/double_insertion_register_scenario_spec.rb +24 -0
  47. data/spec/rr/double/double_insertion_reset_spec.rb +89 -0
  48. data/spec/rr/double/double_insertion_spec.rb +66 -0
  49. data/spec/rr/double/double_insertion_verify_spec.rb +23 -0
  50. data/spec/rr/double_creator_spec.rb +454 -0
  51. data/{examples/rr/scenario_definition_example.rb → spec/rr/double_definition_spec.rb} +143 -143
  52. data/spec/rr/double_method_proxy_spec.rb +71 -0
  53. data/spec/rr/double_spec.rb +654 -0
  54. data/spec/rr/errors/rr_error_spec.rb +65 -0
  55. data/spec/rr/expectations/any_argument_expectation_spec.rb +47 -0
  56. data/spec/rr/expectations/anything_argument_equality_expectation_spec.rb +38 -0
  57. data/spec/rr/expectations/argument_equality_expectation_spec.rb +58 -0
  58. data/spec/rr/expectations/boolean_argument_equality_expectation_spec.rb +53 -0
  59. data/spec/rr/expectations/duck_type_argument_equality_expectation_spec.rb +71 -0
  60. data/spec/rr/expectations/is_a_argument_equality_expectation_spec.rb +51 -0
  61. data/spec/rr/expectations/numeric_argument_equality_expectation_spec.rb +47 -0
  62. data/spec/rr/expectations/range_argument_equality_expectation_spec.rb +59 -0
  63. data/spec/rr/expectations/regexp_argument_equality_expectation_spec.rb +72 -0
  64. data/spec/rr/expectations/times_called_expectation/times_called_expectation_any_times_spec.rb +43 -0
  65. data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_least_spec.rb +67 -0
  66. data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_most_spec.rb +71 -0
  67. data/spec/rr/expectations/times_called_expectation/times_called_expectation_helper.rb +21 -0
  68. data/spec/rr/expectations/times_called_expectation/times_called_expectation_integer_spec.rb +103 -0
  69. data/spec/rr/expectations/times_called_expectation/times_called_expectation_proc_spec.rb +79 -0
  70. data/spec/rr/expectations/times_called_expectation/times_called_expectation_range_spec.rb +81 -0
  71. data/spec/rr/expectations/times_called_expectation/times_called_expectation_spec.rb +40 -0
  72. data/spec/rr/rspec/rspec_adapter_spec.rb +65 -0
  73. data/spec/rr/rspec/rspec_backtrace_tweaking_spec.rb +52 -0
  74. data/spec/rr/rspec/rspec_usage_spec.rb +67 -0
  75. data/spec/rr/space/hash_with_object_id_key_spec.rb +88 -0
  76. data/spec/rr/space/space_create_spec.rb +278 -0
  77. data/spec/rr/space/space_helper.rb +7 -0
  78. data/spec/rr/space/space_register_spec.rb +32 -0
  79. data/spec/rr/space/space_reset_spec.rb +131 -0
  80. data/spec/rr/space/space_spec.rb +32 -0
  81. data/spec/rr/space/space_verify_spec.rb +181 -0
  82. data/{examples → spec}/rr/test_unit/test_helper.rb +1 -1
  83. data/{examples → spec}/rr/test_unit/test_unit_backtrace_test.rb +0 -0
  84. data/{examples → spec}/rr/test_unit/test_unit_integration_test.rb +4 -4
  85. data/spec/rr/times_called_matchers/any_times_matcher_spec.rb +47 -0
  86. data/spec/rr/times_called_matchers/at_least_matcher_spec.rb +55 -0
  87. data/spec/rr/times_called_matchers/at_most_matcher_spec.rb +70 -0
  88. data/spec/rr/times_called_matchers/integer_matcher_spec.rb +70 -0
  89. data/spec/rr/times_called_matchers/proc_matcher_spec.rb +55 -0
  90. data/spec/rr/times_called_matchers/range_matcher_spec.rb +76 -0
  91. data/spec/rr/times_called_matchers/times_called_matcher_spec.rb +118 -0
  92. data/spec/rspec_spec_suite.rb +16 -0
  93. data/spec/spec_helper.rb +9 -0
  94. data/{examples/example_suite.rb → spec/spec_suite.rb} +3 -3
  95. data/{examples/test_unit_example_suite.rb → spec/test_unit_spec_suite.rb} +0 -0
  96. metadata +93 -93
  97. data/examples/core_example_suite.rb +0 -31
  98. data/examples/example_helper.rb +0 -9
  99. data/examples/rr/double/double_bind_example.rb +0 -70
  100. data/examples/rr/double/double_dispatching_example.rb +0 -236
  101. data/examples/rr/double/double_example.rb +0 -66
  102. data/examples/rr/double/double_has_original_method_example.rb +0 -56
  103. data/examples/rr/double/double_register_scenario_example.rb +0 -24
  104. data/examples/rr/double/double_reset_example.rb +0 -89
  105. data/examples/rr/double/double_verify_example.rb +0 -23
  106. data/examples/rr/errors/rr_error_example.rb +0 -65
  107. data/examples/rr/expectations/any_argument_expectation_example.rb +0 -52
  108. data/examples/rr/expectations/anything_argument_equality_expectation_example.rb +0 -38
  109. data/examples/rr/expectations/argument_equality_expectation_example.rb +0 -62
  110. data/examples/rr/expectations/boolean_argument_equality_expectation_example.rb +0 -48
  111. data/examples/rr/expectations/duck_type_argument_equality_expectation_example.rb +0 -67
  112. data/examples/rr/expectations/is_a_argument_equality_expectation_example.rb +0 -50
  113. data/examples/rr/expectations/numeric_argument_equality_expectation_example.rb +0 -46
  114. data/examples/rr/expectations/range_argument_equality_expectation_example.rb +0 -59
  115. data/examples/rr/expectations/regexp_argument_equality_expectation_example.rb +0 -67
  116. data/examples/rr/expectations/times_called_expectation/times_called_expectation_any_times_example.rb +0 -50
  117. data/examples/rr/expectations/times_called_expectation/times_called_expectation_at_least_example.rb +0 -73
  118. data/examples/rr/expectations/times_called_expectation/times_called_expectation_at_most_example.rb +0 -77
  119. data/examples/rr/expectations/times_called_expectation/times_called_expectation_example.rb +0 -42
  120. data/examples/rr/expectations/times_called_expectation/times_called_expectation_helper.rb +0 -20
  121. data/examples/rr/expectations/times_called_expectation/times_called_expectation_integer_example.rb +0 -111
  122. data/examples/rr/expectations/times_called_expectation/times_called_expectation_proc_example.rb +0 -88
  123. data/examples/rr/expectations/times_called_expectation/times_called_expectation_range_example.rb +0 -90
  124. data/examples/rr/extensions/instance_methods_argument_matcher_example.rb +0 -65
  125. data/examples/rr/extensions/instance_methods_creator_example.rb +0 -363
  126. data/examples/rr/extensions/instance_methods_example_helper.rb +0 -11
  127. data/examples/rr/extensions/instance_methods_space_example.rb +0 -122
  128. data/examples/rr/rspec/rspec_adapter_example.rb +0 -63
  129. data/examples/rr/rspec/rspec_backtrace_tweaking_example.rb +0 -36
  130. data/examples/rr/rspec/rspec_usage_example.rb +0 -65
  131. data/examples/rr/scenario_creator_example.rb +0 -459
  132. data/examples/rr/scenario_example.rb +0 -701
  133. data/examples/rr/scenario_method_proxy_example.rb +0 -71
  134. data/examples/rr/space/hash_with_object_id_key_example.rb +0 -86
  135. data/examples/rr/space/space_create_example.rb +0 -278
  136. data/examples/rr/space/space_example.rb +0 -29
  137. data/examples/rr/space/space_helper.rb +0 -7
  138. data/examples/rr/space/space_register_example.rb +0 -32
  139. data/examples/rr/space/space_reset_example.rb +0 -120
  140. data/examples/rr/space/space_verify_example.rb +0 -169
  141. data/examples/rr/times_called_matchers/any_times_matcher_example.rb +0 -63
  142. data/examples/rr/times_called_matchers/at_least_matcher_example.rb +0 -70
  143. data/examples/rr/times_called_matchers/at_most_matcher_example.rb +0 -85
  144. data/examples/rr/times_called_matchers/integer_matcher_example.rb +0 -91
  145. data/examples/rr/times_called_matchers/proc_matcher_example.rb +0 -77
  146. data/examples/rr/times_called_matchers/range_matcher_example.rb +0 -97
  147. data/examples/rr/times_called_matchers/times_called_matcher_example.rb +0 -53
  148. data/examples/rspec_example_suite.rb +0 -25
  149. data/lib/rr/extensions/instance_methods.rb +0 -228
  150. data/lib/rr/scenario.rb +0 -337
@@ -1,63 +0,0 @@
1
- require "examples/example_helper"
2
-
3
- module RR
4
- module Adapters
5
- describe Rspec, "#setup_mocks_for_rspec" do
6
- before do
7
- @fixture = Object.new
8
- @fixture.extend Rspec
9
-
10
- @subject = Object.new
11
- @method_name = :foobar
12
- end
13
-
14
- it "resets the doubles" do
15
- RR::Space.double(@subject, @method_name)
16
- RR::Space.doubles.should_not be_empty
17
-
18
- @fixture.setup_mocks_for_rspec
19
- RR::Space.doubles.should be_empty
20
- end
21
- end
22
-
23
- describe Rspec, "#verify_mocks_for_rspec" do
24
- before do
25
- @fixture = Object.new
26
- @fixture.extend Rspec
27
-
28
- @subject = Object.new
29
- @method_name = :foobar
30
- end
31
-
32
- it "verifies the doubles" do
33
- double = RR::Space.double(@subject, @method_name)
34
- scenario = RR::Space.scenario(double)
35
-
36
- scenario.once
37
-
38
- proc do
39
- @fixture.verify_mocks_for_rspec
40
- end.should raise_error(::RR::Errors::TimesCalledError)
41
- RR::Space.doubles.should be_empty
42
- end
43
- end
44
-
45
- describe Rspec, "#teardown_mocks_for_rspec" do
46
- before do
47
- @fixture = Object.new
48
- @fixture.extend Rspec
49
-
50
- @subject = Object.new
51
- @method_name = :foobar
52
- end
53
-
54
- it "resets the doubles" do
55
- RR::Space.double(@subject, @method_name)
56
- RR::Space.doubles.should_not be_empty
57
-
58
- @fixture.teardown_mocks_for_rspec
59
- RR::Space.doubles.should be_empty
60
- end
61
- end
62
- end
63
- end
@@ -1,36 +0,0 @@
1
- require "examples/example_helper"
2
-
3
- describe RR, " backtrace tweaking" do
4
- it "does not set trim_backtrace" do
5
- RR::Space.trim_backtrace.should == false
6
- end
7
-
8
- it "hides rr library from the backtrace by default" do
9
- output = StringIO.new("")
10
- backtrace_tweaker = ::Spec::Runner::QuietBacktraceTweaker.new
11
- formatter = ::Spec::Runner::Formatter::BaseTextFormatter.new(output)
12
- reporter = ::Spec::Runner::Reporter.new([formatter], backtrace_tweaker)
13
-
14
- behaviour = ::Spec::DSL::Behaviour.new("example") {}
15
- subject = @subject
16
- behaviour.it("hides RR framework in backtrace") do
17
- mock(subject).foobar()
18
- RR::Space::instance.verify_double(subject, :foobar)
19
- end
20
-
21
- reporter.add_behaviour(behaviour)
22
-
23
- behaviour.run(reporter)
24
- reporter.dump
25
-
26
- output.string.should_not include("lib/rr")
27
- end
28
-
29
- it "does not add backtrace identifier twice" do
30
- length = ::Spec::Runner::QuietBacktraceTweaker::IGNORE_PATTERNS.length
31
- class << Object.new
32
- include ::RR::Adapters::Rspec
33
- end
34
- ::Spec::Runner::QuietBacktraceTweaker::IGNORE_PATTERNS.length.should == length
35
- end
36
- end
@@ -1,65 +0,0 @@
1
- require "examples/example_helper"
2
-
3
- describe RR, "#mock" do
4
- before do
5
- @subject = Object.new
6
- end
7
-
8
- it "creates a mock Double Scenario" do
9
- mock(@subject).foobar(1, 2) {:baz}
10
- @subject.foobar(1, 2).should == :baz
11
- end
12
- end
13
-
14
- describe RR, "#stub" do
15
- before do
16
- @subject = Object.new
17
- end
18
-
19
- it "creates a stub Double Scenario" do
20
- stub(@subject).foobar {:baz}
21
- @subject.foobar("any", "thing").should == :baz
22
- end
23
- end
24
-
25
- describe RR, "#mock and #probe" do
26
- before do
27
- @subject = Object.new
28
- def @subject.foobar
29
- :baz
30
- end
31
- end
32
-
33
- it "creates a probe Double Scenario" do
34
- mock.probe(@subject).foobar
35
- @subject.foobar.should == :baz
36
- end
37
- end
38
-
39
- describe RR, "#stub and #probe" do
40
- before do
41
- @subject = Object.new
42
- def @subject.foobar
43
- :baz
44
- end
45
- end
46
-
47
- it "creates a probe Double Scenario" do
48
- stub.probe(@subject).foobar
49
- @subject.foobar.should == :baz
50
- end
51
- end
52
-
53
- describe RR, "#stub and #proxy" do
54
- before do
55
- @subject = Object.new
56
- def @subject.foobar
57
- :baz
58
- end
59
- end
60
-
61
- it "creates a probe Double Scenario" do
62
- stub.proxy(@subject).foobar
63
- @subject.foobar.should == :baz
64
- end
65
- end
@@ -1,459 +0,0 @@
1
- require "examples/example_helper"
2
-
3
- module RR
4
- describe ScenarioCreator, :shared => true do
5
- before(:each) do
6
- @space = Space.new
7
- @subject = Object.new
8
- @creator = ScenarioCreator.new(@space)
9
- end
10
- end
11
-
12
- describe ScenarioCreator, " strategy definition", :shared => true do
13
- it_should_behave_like "RR::ScenarioCreator"
14
-
15
- it "returns self when passing no args" do
16
- @creator.__send__(@method_name).should === @creator
17
- end
18
-
19
- it "returns a ScenarioMethodProxy when passed a subject" do
20
- scenario = @creator.__send__(@method_name, @subject).foobar
21
- scenario.should be_instance_of(ScenarioDefinition)
22
- end
23
-
24
- it "returns a ScenarioMethodProxy when passed Kernel" do
25
- scenario = @creator.__send__(@method_name, Kernel).foobar
26
- scenario.should be_instance_of(ScenarioDefinition)
27
- end
28
-
29
- it "raises error if passed a method name and a block" do
30
- proc do
31
- @creator.__send__(@method_name, @subject, :foobar) {}
32
- end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
33
- end
34
-
35
- it "raises error when using mock strategy" do
36
- @creator.mock
37
- proc do
38
- @creator.__send__(@method_name)
39
- end.should raise_error(
40
- Errors::ScenarioDefinitionError,
41
- "This Scenario already has a mock strategy"
42
- )
43
- end
44
-
45
- it "raises error when using stub strategy" do
46
- @creator.stub
47
- proc do
48
- @creator.__send__(@method_name)
49
- end.should raise_error(
50
- Errors::ScenarioDefinitionError,
51
- "This Scenario already has a stub strategy"
52
- )
53
- end
54
-
55
- it "raises error when using do_not_call strategy" do
56
- @creator.do_not_call
57
- proc do
58
- @creator.__send__(@method_name)
59
- end.should raise_error(
60
- Errors::ScenarioDefinitionError,
61
- "This Scenario already has a do_not_call strategy"
62
- )
63
- end
64
- end
65
-
66
- describe ScenarioCreator, "#mock" do
67
- it_should_behave_like "RR::ScenarioCreator strategy definition"
68
-
69
- before do
70
- @method_name = :mock
71
- end
72
-
73
- it "sets up the RR mock call chain" do
74
- should create_mock_call_chain(@creator.mock(@subject))
75
- end
76
-
77
- it "creates a mock Scenario for method when passed a second argument with rr_mock" do
78
- should create_scenario_with_method_name(
79
- @creator.mock(@subject, :foobar)
80
- )
81
- end
82
-
83
- it "sets up the ScenarioDefinition to be in returns block_callback_strategy" do
84
- scenario = @creator.mock(@subject, :foobar)
85
- scenario.block_callback_strategy.should == :returns
86
- end
87
-
88
- def create_scenario_with_method_name(scenario)
89
- scenario.with(1, 2) {:baz}
90
- scenario.times_matcher.should == TimesCalledMatchers::IntegerMatcher.new(1)
91
- scenario.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
92
- scenario.argument_expectation.expected_arguments.should == [1, 2]
93
-
94
- @subject.foobar(1, 2).should == :baz
95
- end
96
-
97
- def create_mock_call_chain(creator)
98
- scenario = creator.foobar(1, 2) {:baz}
99
- scenario.times_matcher.should == TimesCalledMatchers::IntegerMatcher.new(1)
100
- scenario.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
101
- scenario.argument_expectation.expected_arguments.should == [1, 2]
102
-
103
- @subject.foobar(1, 2).should == :baz
104
- end
105
- end
106
-
107
- describe ScenarioCreator, "#stub" do
108
- it_should_behave_like "RR::ScenarioCreator strategy definition"
109
-
110
- before do
111
- @method_name = :stub
112
- end
113
-
114
- it "sets up the RR stub call chain" do
115
- should create_stub_call_chain(@creator.stub(@subject))
116
- end
117
-
118
- it "creates a stub Scenario for method when passed a second argument" do
119
- should create_scenario_with_method_name(@creator.stub(@subject, :foobar))
120
- end
121
-
122
- it "sets up the ScenarioDefinition to be in returns block_callback_strategy" do
123
- scenario = @creator.stub(@subject, :foobar)
124
- scenario.block_callback_strategy.should == :returns
125
- end
126
-
127
- def create_scenario_with_method_name(scenario)
128
- scenario.with(1, 2) {:baz}
129
- scenario.times_matcher.should == TimesCalledMatchers::AnyTimesMatcher.new
130
- scenario.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
131
- @subject.foobar(1, 2).should == :baz
132
- end
133
-
134
- def create_stub_call_chain(creator)
135
- scenario = creator.foobar(1, 2) {:baz}
136
- scenario.times_matcher.should == TimesCalledMatchers::AnyTimesMatcher.new
137
- scenario.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
138
- @subject.foobar(1, 2).should == :baz
139
- end
140
- end
141
-
142
- describe ScenarioCreator, "#do_not_call" do
143
- it_should_behave_like "RR::ScenarioCreator strategy definition"
144
-
145
- before do
146
- @method_name = :do_not_call
147
- end
148
-
149
- it "raises error when probed" do
150
- @creator.probe
151
- proc do
152
- @creator.do_not_call
153
- end.should raise_error(
154
- Errors::ScenarioDefinitionError,
155
- "Scenarios cannot be probed when using do_not_call strategy"
156
- )
157
- end
158
-
159
- it "sets up the RR do_not_call call chain" do
160
- should create_do_not_call_call_chain(@creator.do_not_call(@subject))
161
- end
162
-
163
- it "sets up the RR do_not_call call chain" do
164
- should create_do_not_call_call_chain(@creator.dont_call(@subject))
165
- end
166
-
167
- it "sets up the RR do_not_call call chain" do
168
- should create_do_not_call_call_chain(@creator.do_not_allow(@subject))
169
- end
170
-
171
- it "sets up the RR do_not_call call chain" do
172
- should create_do_not_call_call_chain(@creator.dont_allow(@subject))
173
- end
174
-
175
- it "creates a mock Scenario for method when passed a second argument" do
176
- should create_scenario_with_method_name(@creator.do_not_call(@subject, :foobar))
177
- end
178
-
179
- it "creates a mock Scenario for method when passed a second argument" do
180
- should create_scenario_with_method_name(@creator.dont_call(@subject, :foobar))
181
- end
182
-
183
- it "creates a mock Scenario for method when passed a second argument" do
184
- should create_scenario_with_method_name(@creator.do_not_allow(@subject, :foobar))
185
- end
186
-
187
- it "creates a mock Scenario for method when passed a second argument" do
188
- should create_scenario_with_method_name(@creator.dont_allow(@subject, :foobar))
189
- end
190
-
191
- def create_scenario_with_method_name(scenario)
192
- scenario.with(1, 2)
193
- scenario.times_matcher.should == TimesCalledMatchers::IntegerMatcher.new(0)
194
- scenario.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
195
- scenario.argument_expectation.expected_arguments.should == [1, 2]
196
-
197
- proc do
198
- @subject.foobar(1, 2)
199
- end.should raise_error(Errors::TimesCalledError)
200
- reset
201
- nil
202
- end
203
-
204
- def create_do_not_call_call_chain(creator)
205
- scenario = creator.foobar(1, 2)
206
- scenario.times_matcher.should == TimesCalledMatchers::IntegerMatcher.new(0)
207
- scenario.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
208
- scenario.argument_expectation.expected_arguments.should == [1, 2]
209
-
210
- proc do
211
- @subject.foobar(1, 2)
212
- end.should raise_error(Errors::TimesCalledError)
213
- reset
214
- nil
215
- end
216
- end
217
-
218
- describe ScenarioCreator, "(#probe or #proxy) and #stub" do
219
- it_should_behave_like "RR::ScenarioCreator"
220
-
221
- before do
222
- class << @subject
223
- def foobar(*args)
224
- :original_foobar
225
- end
226
- end
227
- end
228
-
229
- it "raises error when using do_not_call strategy" do
230
- @creator.do_not_call
231
- proc do
232
- @creator.probe
233
- end.should raise_error(
234
- Errors::ScenarioDefinitionError,
235
- "Scenarios cannot be probed when using do_not_call strategy"
236
- )
237
- end
238
-
239
- it "sets up the RR probe call chain" do
240
- scenario = @creator.stub.probe(@subject).foobar(1, 2) {:baz}
241
- scenario.times_matcher.should == TimesCalledMatchers::AnyTimesMatcher.new
242
- scenario.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
243
- @subject.foobar(1, 2).should == :baz
244
- end
245
-
246
- it "sets up the RR proxy call chain" do
247
- scenario = @creator.stub.proxy(@subject).foobar(1, 2) {:baz}
248
- scenario.times_matcher.should == TimesCalledMatchers::AnyTimesMatcher.new
249
- scenario.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
250
- @subject.foobar(1, 2).should == :baz
251
- end
252
-
253
- it "creates a probe Scenario for method when passed a second argument" do
254
- scenario = @creator.stub.probe(@subject, :foobar)
255
- scenario.with(1, 2) {:baz}
256
- scenario.times_matcher.should == TimesCalledMatchers::AnyTimesMatcher.new
257
- scenario.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
258
- @subject.foobar(1, 2).should == :baz
259
- end
260
-
261
- it "creates a proxy Scenario for method when passed a second argument" do
262
- scenario = @creator.stub.proxy(@subject, :foobar)
263
- scenario.with(1, 2) {:baz}
264
- scenario.times_matcher.should == TimesCalledMatchers::AnyTimesMatcher.new
265
- scenario.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
266
- @subject.foobar(1, 2).should == :baz
267
- end
268
-
269
- it "sets up the ScenarioDefinition to be in after_call block_callback_strategy" do
270
- def @subject.foobar
271
- :original_implementation_value
272
- end
273
-
274
- args = nil
275
- scenario = @creator.stub.proxy(@subject, :foobar).with() do |*args|
276
- args = args
277
- end
278
- @subject.foobar
279
- args.should == [:original_implementation_value]
280
- scenario.block_callback_strategy.should == :after_call
281
- end
282
- end
283
-
284
- describe ScenarioCreator, "#instance_of" do
285
- it_should_behave_like "RR::ScenarioCreator"
286
-
287
- it "raises an error when not passed a class" do
288
- proc do
289
- @creator.instance_of(Object.new)
290
- end.should raise_error(ArgumentError, "instance_of only accepts class objects")
291
- end
292
-
293
- it "sets up the RR probe call chain" do
294
- klass = Class.new
295
- scenario = @creator.stub.instance_of(klass).foobar(1, 2) {:baz}
296
- scenario.times_matcher.should == TimesCalledMatchers::AnyTimesMatcher.new
297
- scenario.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
298
- klass.new.foobar(1, 2).should == :baz
299
- end
300
-
301
- it "creates a probe Scenario for method when passed a second argument" do
302
- klass = Class.new
303
- scenario = @creator.stub.instance_of(klass, :foobar)
304
- scenario.with(1, 2) {:baz}
305
- scenario.times_matcher.should == TimesCalledMatchers::AnyTimesMatcher.new
306
- scenario.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
307
- klass.new.foobar(1, 2).should == :baz
308
- end
309
- end
310
-
311
- describe ScenarioCreator, "#create! using no strategy" do
312
- it_should_behave_like "RR::ScenarioCreator"
313
-
314
- it "raises error" do
315
- proc do
316
- @creator.create!(@subject, :foobar, 1, 2)
317
- end.should raise_error(
318
- Errors::ScenarioDefinitionError,
319
- "This Scenario has no strategy"
320
- )
321
- end
322
- end
323
-
324
- describe ScenarioCreator, "#create! using mock strategy" do
325
- it_should_behave_like "RR::ScenarioCreator"
326
-
327
- before do
328
- @creator.mock
329
- end
330
-
331
- it "sets expectations on the subject" do
332
- @creator.create!(@subject, :foobar, 1, 2) {:baz}.twice
333
-
334
- @subject.foobar(1, 2).should == :baz
335
- @subject.foobar(1, 2).should == :baz
336
- proc {@subject.foobar(1, 2)}.should raise_error(Errors::TimesCalledError)
337
- end
338
- end
339
-
340
- describe ScenarioCreator, "#create! using stub strategy" do
341
- it_should_behave_like "RR::ScenarioCreator"
342
-
343
- before do
344
- @creator.stub
345
- end
346
-
347
- it "stubs the subject without any args" do
348
- @creator.create!(@subject, :foobar) {:baz}
349
- @subject.foobar.should == :baz
350
- end
351
-
352
- it "stubs the subject mapping passed in args with the output" do
353
- @creator.create!(@subject, :foobar, 1, 2) {:one_two}
354
- @creator.create!(@subject, :foobar, 1) {:one}
355
- @creator.create!(@subject, :foobar) {:nothing}
356
- @subject.foobar.should == :nothing
357
- @subject.foobar(1).should == :one
358
- @subject.foobar(1, 2).should == :one_two
359
- end
360
- end
361
-
362
- describe ScenarioCreator, "#create! using do_not_call strategy" do
363
- it_should_behave_like "RR::ScenarioCreator"
364
-
365
- before do
366
- @creator.do_not_call
367
- end
368
-
369
- it "sets expectation for method to never be called with any arguments when on arguments passed in" do
370
- @creator.create!(@subject, :foobar)
371
- proc {@subject.foobar}.should raise_error(Errors::TimesCalledError)
372
- proc {@subject.foobar(1, 2)}.should raise_error(Errors::TimesCalledError)
373
- end
374
-
375
- it "sets expectation for method to never be called with passed in arguments" do
376
- @creator.create!(@subject, :foobar, 1, 2)
377
- proc {@subject.foobar}.should raise_error(Errors::ScenarioNotFoundError)
378
- proc {@subject.foobar(1, 2)}.should raise_error(Errors::TimesCalledError)
379
- end
380
-
381
- it "sets expectation for method to never be called with no arguments when with_no_args is set" do
382
- @creator.create!(@subject, :foobar).with_no_args
383
- proc {@subject.foobar}.should raise_error(Errors::TimesCalledError)
384
- proc {@subject.foobar(1, 2)}.should raise_error(Errors::ScenarioNotFoundError)
385
- end
386
- end
387
-
388
- describe ScenarioCreator, "#create! using mock strategy with probe" do
389
- it_should_behave_like "RR::ScenarioCreator"
390
-
391
- before do
392
- @creator.mock
393
- @creator.probe
394
- end
395
-
396
- it "sets expectations on the subject while calling the original method" do
397
- def @subject.foobar(*args); :baz; end
398
- @creator.create!(@subject, :foobar,1, 2).twice
399
- @subject.foobar(1, 2).should == :baz
400
- @subject.foobar(1, 2).should == :baz
401
- proc {@subject.foobar(1, 2)}.should raise_error(Errors::TimesCalledError)
402
- end
403
-
404
- it "sets after_call on the scenario when passed a block" do
405
- real_value = Object.new
406
- (class << @subject; self; end).class_eval do
407
- define_method(:foobar) {real_value}
408
- end
409
- @creator.create!(@subject, :foobar, 1, 2) do |value|
410
- mock(value).a_method {99}
411
- value
412
- end
413
-
414
- return_value = @subject.foobar(1, 2)
415
- return_value.should === return_value
416
- return_value.a_method.should == 99
417
- end
418
- end
419
-
420
- describe ScenarioCreator, "#create! using stub strategy with probe" do
421
- it_should_behave_like "RR::ScenarioCreator"
422
-
423
- before do
424
- @creator.stub
425
- @creator.probe
426
- end
427
-
428
- it "sets up a scenario with passed in arguments" do
429
- def @subject.foobar(*args); :baz; end
430
- @creator.create!(@subject, :foobar, 1, 2)
431
- proc do
432
- @subject.foobar
433
- end.should raise_error(Errors::ScenarioNotFoundError)
434
- end
435
-
436
- it "sets expectations on the subject while calling the original method" do
437
- def @subject.foobar(*args); :baz; end
438
- @creator.create!(@subject, :foobar, 1, 2) {:new_value}
439
- 10.times do
440
- @subject.foobar(1, 2).should == :new_value
441
- end
442
- end
443
-
444
- it "sets after_call on the scenario when passed a block" do
445
- real_value = Object.new
446
- (class << @subject; self; end).class_eval do
447
- define_method(:foobar) {real_value}
448
- end
449
- @creator.create!(@subject, :foobar, 1, 2) do |value|
450
- mock(value).a_method {99}
451
- value
452
- end
453
-
454
- return_value = @subject.foobar(1, 2)
455
- return_value.should === return_value
456
- return_value.a_method.should == 99
457
- end
458
- end
459
- end