rr 0.3.11 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +8 -3
- data/README +130 -39
- data/Rakefile +6 -5
- data/lib/rr.rb +8 -8
- data/lib/rr/adapters/rr_methods.rb +228 -0
- data/lib/rr/adapters/rspec.rb +1 -1
- data/lib/rr/adapters/test_unit.rb +1 -1
- data/lib/rr/double.rb +294 -89
- data/lib/rr/{scenario_creator.rb → double_creator.rb} +65 -66
- data/lib/rr/{scenario_definition.rb → double_definition.rb} +36 -36
- data/lib/rr/{scenario_definition_builder.rb → double_definition_builder.rb} +3 -3
- data/lib/rr/double_insertion.rb +132 -0
- data/lib/rr/{scenario_matches.rb → double_matches.rb} +2 -2
- data/lib/rr/{scenario_method_proxy.rb → double_method_proxy.rb} +2 -2
- data/lib/rr/errors/argument_equality_error.rb +3 -3
- data/lib/rr/errors/rr_error.rb +13 -13
- data/lib/rr/errors/scenario_definition_error.rb +3 -3
- data/lib/rr/errors/scenario_not_found_error.rb +3 -3
- data/lib/rr/errors/scenario_order_error.rb +3 -3
- data/lib/rr/errors/times_called_error.rb +3 -3
- data/lib/rr/expectations/any_argument_expectation.rb +1 -1
- data/lib/rr/expectations/argument_equality_expectation.rb +1 -1
- data/lib/rr/expectations/times_called_expectation.rb +1 -1
- data/lib/rr/hash_with_object_id_key.rb +1 -1
- data/lib/rr/space.rb +40 -40
- data/lib/rr/times_called_matchers/any_times_matcher.rb +13 -13
- data/lib/rr/times_called_matchers/at_least_matcher.rb +11 -11
- data/lib/rr/times_called_matchers/at_most_matcher.rb +16 -16
- data/lib/rr/times_called_matchers/integer_matcher.rb +13 -13
- data/lib/rr/times_called_matchers/non_terminal.rb +21 -21
- data/lib/rr/times_called_matchers/proc_matcher.rb +7 -7
- data/lib/rr/times_called_matchers/range_matcher.rb +14 -14
- data/lib/rr/times_called_matchers/terminal.rb +16 -16
- data/lib/rr/times_called_matchers/times_called_matcher.rb +32 -32
- data/spec/core_spec_suite.rb +18 -0
- data/{examples → spec}/environment_fixture_setup.rb +0 -1
- data/{examples/high_level_example.rb → spec/high_level_spec.rb} +11 -11
- data/spec/rr/adapters/rr_methods_argument_matcher_spec.rb +67 -0
- data/spec/rr/adapters/rr_methods_creator_spec.rb +365 -0
- data/spec/rr/adapters/rr_methods_space_spec.rb +134 -0
- data/spec/rr/adapters/rr_methods_spec_helper.rb +11 -0
- data/{examples/rr/extensions/instance_methods_times_matcher_example.rb → spec/rr/adapters/rr_methods_times_matcher_spec.rb} +4 -4
- data/spec/rr/double/double_insertion_bind_spec.rb +78 -0
- data/spec/rr/double/double_insertion_dispatching_spec.rb +221 -0
- data/spec/rr/double/double_insertion_has_original_method_spec.rb +56 -0
- data/spec/rr/double/double_insertion_register_scenario_spec.rb +24 -0
- data/spec/rr/double/double_insertion_reset_spec.rb +89 -0
- data/spec/rr/double/double_insertion_spec.rb +66 -0
- data/spec/rr/double/double_insertion_verify_spec.rb +23 -0
- data/spec/rr/double_creator_spec.rb +454 -0
- data/{examples/rr/scenario_definition_example.rb → spec/rr/double_definition_spec.rb} +143 -143
- data/spec/rr/double_method_proxy_spec.rb +71 -0
- data/spec/rr/double_spec.rb +654 -0
- data/spec/rr/errors/rr_error_spec.rb +65 -0
- data/spec/rr/expectations/any_argument_expectation_spec.rb +47 -0
- data/spec/rr/expectations/anything_argument_equality_expectation_spec.rb +38 -0
- data/spec/rr/expectations/argument_equality_expectation_spec.rb +58 -0
- data/spec/rr/expectations/boolean_argument_equality_expectation_spec.rb +53 -0
- data/spec/rr/expectations/duck_type_argument_equality_expectation_spec.rb +71 -0
- data/spec/rr/expectations/is_a_argument_equality_expectation_spec.rb +51 -0
- data/spec/rr/expectations/numeric_argument_equality_expectation_spec.rb +47 -0
- data/spec/rr/expectations/range_argument_equality_expectation_spec.rb +59 -0
- data/spec/rr/expectations/regexp_argument_equality_expectation_spec.rb +72 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_any_times_spec.rb +43 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_least_spec.rb +67 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_most_spec.rb +71 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_helper.rb +21 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_integer_spec.rb +103 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_proc_spec.rb +79 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_range_spec.rb +81 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_spec.rb +40 -0
- data/spec/rr/rspec/rspec_adapter_spec.rb +65 -0
- data/spec/rr/rspec/rspec_backtrace_tweaking_spec.rb +52 -0
- data/spec/rr/rspec/rspec_usage_spec.rb +67 -0
- data/spec/rr/space/hash_with_object_id_key_spec.rb +88 -0
- data/spec/rr/space/space_create_spec.rb +278 -0
- data/spec/rr/space/space_helper.rb +7 -0
- data/spec/rr/space/space_register_spec.rb +32 -0
- data/spec/rr/space/space_reset_spec.rb +131 -0
- data/spec/rr/space/space_spec.rb +32 -0
- data/spec/rr/space/space_verify_spec.rb +181 -0
- data/{examples → spec}/rr/test_unit/test_helper.rb +1 -1
- data/{examples → spec}/rr/test_unit/test_unit_backtrace_test.rb +0 -0
- data/{examples → spec}/rr/test_unit/test_unit_integration_test.rb +4 -4
- data/spec/rr/times_called_matchers/any_times_matcher_spec.rb +47 -0
- data/spec/rr/times_called_matchers/at_least_matcher_spec.rb +55 -0
- data/spec/rr/times_called_matchers/at_most_matcher_spec.rb +70 -0
- data/spec/rr/times_called_matchers/integer_matcher_spec.rb +70 -0
- data/spec/rr/times_called_matchers/proc_matcher_spec.rb +55 -0
- data/spec/rr/times_called_matchers/range_matcher_spec.rb +76 -0
- data/spec/rr/times_called_matchers/times_called_matcher_spec.rb +118 -0
- data/spec/rspec_spec_suite.rb +16 -0
- data/spec/spec_helper.rb +9 -0
- data/{examples/example_suite.rb → spec/spec_suite.rb} +3 -3
- data/{examples/test_unit_example_suite.rb → spec/test_unit_spec_suite.rb} +0 -0
- metadata +93 -93
- data/examples/core_example_suite.rb +0 -31
- data/examples/example_helper.rb +0 -9
- data/examples/rr/double/double_bind_example.rb +0 -70
- data/examples/rr/double/double_dispatching_example.rb +0 -236
- data/examples/rr/double/double_example.rb +0 -66
- data/examples/rr/double/double_has_original_method_example.rb +0 -56
- data/examples/rr/double/double_register_scenario_example.rb +0 -24
- data/examples/rr/double/double_reset_example.rb +0 -89
- data/examples/rr/double/double_verify_example.rb +0 -23
- data/examples/rr/errors/rr_error_example.rb +0 -65
- data/examples/rr/expectations/any_argument_expectation_example.rb +0 -52
- data/examples/rr/expectations/anything_argument_equality_expectation_example.rb +0 -38
- data/examples/rr/expectations/argument_equality_expectation_example.rb +0 -62
- data/examples/rr/expectations/boolean_argument_equality_expectation_example.rb +0 -48
- data/examples/rr/expectations/duck_type_argument_equality_expectation_example.rb +0 -67
- data/examples/rr/expectations/is_a_argument_equality_expectation_example.rb +0 -50
- data/examples/rr/expectations/numeric_argument_equality_expectation_example.rb +0 -46
- data/examples/rr/expectations/range_argument_equality_expectation_example.rb +0 -59
- data/examples/rr/expectations/regexp_argument_equality_expectation_example.rb +0 -67
- data/examples/rr/expectations/times_called_expectation/times_called_expectation_any_times_example.rb +0 -50
- data/examples/rr/expectations/times_called_expectation/times_called_expectation_at_least_example.rb +0 -73
- data/examples/rr/expectations/times_called_expectation/times_called_expectation_at_most_example.rb +0 -77
- data/examples/rr/expectations/times_called_expectation/times_called_expectation_example.rb +0 -42
- data/examples/rr/expectations/times_called_expectation/times_called_expectation_helper.rb +0 -20
- data/examples/rr/expectations/times_called_expectation/times_called_expectation_integer_example.rb +0 -111
- data/examples/rr/expectations/times_called_expectation/times_called_expectation_proc_example.rb +0 -88
- data/examples/rr/expectations/times_called_expectation/times_called_expectation_range_example.rb +0 -90
- data/examples/rr/extensions/instance_methods_argument_matcher_example.rb +0 -65
- data/examples/rr/extensions/instance_methods_creator_example.rb +0 -363
- data/examples/rr/extensions/instance_methods_example_helper.rb +0 -11
- data/examples/rr/extensions/instance_methods_space_example.rb +0 -122
- data/examples/rr/rspec/rspec_adapter_example.rb +0 -63
- data/examples/rr/rspec/rspec_backtrace_tweaking_example.rb +0 -36
- data/examples/rr/rspec/rspec_usage_example.rb +0 -65
- data/examples/rr/scenario_creator_example.rb +0 -459
- data/examples/rr/scenario_example.rb +0 -701
- data/examples/rr/scenario_method_proxy_example.rb +0 -71
- data/examples/rr/space/hash_with_object_id_key_example.rb +0 -86
- data/examples/rr/space/space_create_example.rb +0 -278
- data/examples/rr/space/space_example.rb +0 -29
- data/examples/rr/space/space_helper.rb +0 -7
- data/examples/rr/space/space_register_example.rb +0 -32
- data/examples/rr/space/space_reset_example.rb +0 -120
- data/examples/rr/space/space_verify_example.rb +0 -169
- data/examples/rr/times_called_matchers/any_times_matcher_example.rb +0 -63
- data/examples/rr/times_called_matchers/at_least_matcher_example.rb +0 -70
- data/examples/rr/times_called_matchers/at_most_matcher_example.rb +0 -85
- data/examples/rr/times_called_matchers/integer_matcher_example.rb +0 -91
- data/examples/rr/times_called_matchers/proc_matcher_example.rb +0 -77
- data/examples/rr/times_called_matchers/range_matcher_example.rb +0 -97
- data/examples/rr/times_called_matchers/times_called_matcher_example.rb +0 -53
- data/examples/rspec_example_suite.rb +0 -25
- data/lib/rr/extensions/instance_methods.rb +0 -228
- data/lib/rr/scenario.rb +0 -337
@@ -1,71 +0,0 @@
|
|
1
|
-
require "examples/example_helper"
|
2
|
-
|
3
|
-
module RR
|
4
|
-
describe ScenarioMethodProxy, :shared => true do
|
5
|
-
before(:each) do
|
6
|
-
@space = Space.new
|
7
|
-
@subject = Object.new
|
8
|
-
@creator = @space.scenario_creator
|
9
|
-
@creator.mock
|
10
|
-
end
|
11
|
-
|
12
|
-
it "initializes proxy with passed in creator" do
|
13
|
-
class << @proxy
|
14
|
-
attr_reader :creator
|
15
|
-
end
|
16
|
-
@proxy.creator.should === @creator
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
describe ScenarioMethodProxy, ".new without block" do
|
21
|
-
it_should_behave_like "RR::ScenarioMethodProxy"
|
22
|
-
|
23
|
-
before do
|
24
|
-
@proxy = ScenarioMethodProxy.new(@space, @creator, @subject)
|
25
|
-
end
|
26
|
-
|
27
|
-
it "clears out all methods from proxy" do
|
28
|
-
proxy_subclass = Class.new(ScenarioMethodProxy) do
|
29
|
-
def i_should_be_a_scenario
|
30
|
-
end
|
31
|
-
end
|
32
|
-
proxy_subclass.instance_methods.should include('i_should_be_a_scenario')
|
33
|
-
|
34
|
-
proxy = proxy_subclass.new(@space, @creator, @subject)
|
35
|
-
proxy.i_should_be_a_scenario.should be_instance_of(ScenarioDefinition)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
describe ScenarioMethodProxy, ".new with block" do
|
40
|
-
it_should_behave_like "RR::ScenarioMethodProxy"
|
41
|
-
|
42
|
-
before do
|
43
|
-
@proxy = ScenarioMethodProxy.new(@space, @creator, @subject) do |b|
|
44
|
-
b.foobar(1, 2) {:one_two}
|
45
|
-
b.foobar(1) {:one}
|
46
|
-
b.foobar.with_any_args {:default}
|
47
|
-
b.baz() {:baz_result}
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
it "creates doubles" do
|
52
|
-
@subject.foobar(1, 2).should == :one_two
|
53
|
-
@subject.foobar(1).should == :one
|
54
|
-
@subject.foobar(:something).should == :default
|
55
|
-
@subject.baz.should == :baz_result
|
56
|
-
end
|
57
|
-
|
58
|
-
it "clears out all methods from proxy" do
|
59
|
-
proxy_subclass = Class.new(ScenarioMethodProxy) do
|
60
|
-
def i_should_be_a_scenario
|
61
|
-
end
|
62
|
-
end
|
63
|
-
proxy_subclass.instance_methods.should include('i_should_be_a_scenario')
|
64
|
-
|
65
|
-
proxy_subclass.new(@space, @creator, @subject) do |m|
|
66
|
-
m.i_should_be_a_scenario.should be_instance_of(ScenarioDefinition)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
end
|
@@ -1,86 +0,0 @@
|
|
1
|
-
require "examples/example_helper"
|
2
|
-
|
3
|
-
module RR
|
4
|
-
describe HashWithObjectIdKey, "#[] and #[]=" do
|
5
|
-
it "stores object via object id" do
|
6
|
-
hash = HashWithObjectIdKey.new
|
7
|
-
array_1 = []
|
8
|
-
hash[array_1] = 1
|
9
|
-
array_2 = []
|
10
|
-
hash[array_2] = 2
|
11
|
-
|
12
|
-
hash[array_1].should_not == hash[array_2]
|
13
|
-
end
|
14
|
-
|
15
|
-
it "stores the passed in object" do
|
16
|
-
hash = HashWithObjectIdKey.new
|
17
|
-
obj = Object.new
|
18
|
-
hash[obj] = 1
|
19
|
-
hash.instance_eval {@keys}.should == {obj.__id__ => obj}
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe HashWithObjectIdKey, "#each" do
|
24
|
-
it "iterates through the items in the hash" do
|
25
|
-
hash = HashWithObjectIdKey.new
|
26
|
-
hash['one'] = 1
|
27
|
-
hash['two'] = 2
|
28
|
-
|
29
|
-
keys = []
|
30
|
-
values = []
|
31
|
-
hash.each do |key, value|
|
32
|
-
keys << key
|
33
|
-
values << value
|
34
|
-
end
|
35
|
-
|
36
|
-
keys.sort.should == ['one', 'two']
|
37
|
-
values.sort.should == [1, 2]
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
describe HashWithObjectIdKey, "#delete" do
|
42
|
-
before do
|
43
|
-
@hash = HashWithObjectIdKey.new
|
44
|
-
@key = Object.new
|
45
|
-
@hash[@key] = 1
|
46
|
-
end
|
47
|
-
|
48
|
-
it "removes the object from the hash" do
|
49
|
-
@hash.delete(@key)
|
50
|
-
@hash[@key].should == {}
|
51
|
-
end
|
52
|
-
|
53
|
-
it "removes the object from the keys hash" do
|
54
|
-
@hash.delete(@key)
|
55
|
-
@hash.instance_eval {@keys}.should == {}
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
describe HashWithObjectIdKey, "#keys" do
|
60
|
-
before do
|
61
|
-
@hash = HashWithObjectIdKey.new
|
62
|
-
@key = Object.new
|
63
|
-
@hash[@key] = 1
|
64
|
-
end
|
65
|
-
|
66
|
-
it "returns an array of the keys" do
|
67
|
-
@hash.keys.should == [@key]
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
describe HashWithObjectIdKey, "#include?" do
|
72
|
-
before do
|
73
|
-
@hash = HashWithObjectIdKey.new
|
74
|
-
@key = Object.new
|
75
|
-
@hash[@key] = 1
|
76
|
-
end
|
77
|
-
|
78
|
-
it "returns true when the key is in the Hash" do
|
79
|
-
@hash.should include(@key)
|
80
|
-
end
|
81
|
-
|
82
|
-
it "returns false when the key is not in the Hash" do
|
83
|
-
@hash.should_not include(Object.new)
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
@@ -1,278 +0,0 @@
|
|
1
|
-
require "examples/example_helper"
|
2
|
-
|
3
|
-
module RR
|
4
|
-
describe Space, "#scenario_method_proxy", :shared => true do
|
5
|
-
it_should_behave_like "RR::Space"
|
6
|
-
|
7
|
-
before do
|
8
|
-
@space = Space.new
|
9
|
-
@object = Object.new
|
10
|
-
end
|
11
|
-
|
12
|
-
it "creates a ScenarioMethodProxy" do
|
13
|
-
proxy = @space.scenario_method_proxy(@creator, @object)
|
14
|
-
proxy.should be_instance_of(ScenarioMethodProxy)
|
15
|
-
end
|
16
|
-
|
17
|
-
it "sets space to self" do
|
18
|
-
proxy = @space.scenario_method_proxy(@creator, @object)
|
19
|
-
class << proxy
|
20
|
-
attr_reader :space
|
21
|
-
end
|
22
|
-
proxy.space.should === @space
|
23
|
-
end
|
24
|
-
|
25
|
-
it "sets creator to passed in creator" do
|
26
|
-
proxy = @space.scenario_method_proxy(@creator, @object)
|
27
|
-
class << proxy
|
28
|
-
attr_reader :creator
|
29
|
-
end
|
30
|
-
proxy.creator.should === @creator
|
31
|
-
end
|
32
|
-
|
33
|
-
it "raises error if passed a method name and a block" do
|
34
|
-
proc do
|
35
|
-
@space.scenario_method_proxy(@creator, @object, :foobar) {}
|
36
|
-
end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
describe Space, "#scenario_method_proxy with a Mock strategy" do
|
41
|
-
it_should_behave_like "RR::Space#scenario_method_proxy"
|
42
|
-
|
43
|
-
before do
|
44
|
-
@creator = @space.scenario_creator
|
45
|
-
@creator.mock
|
46
|
-
end
|
47
|
-
|
48
|
-
it "creates a mock Scenario for method when passed a second argument" do
|
49
|
-
@space.scenario_method_proxy(@creator, @object, :foobar).with(1) {:baz}
|
50
|
-
@object.foobar(1).should == :baz
|
51
|
-
proc {@object.foobar(1)}.should raise_error(Errors::TimesCalledError)
|
52
|
-
end
|
53
|
-
|
54
|
-
it "uses block definition when passed a block" do
|
55
|
-
@space.scenario_method_proxy(@creator, @object) do |c|
|
56
|
-
c.foobar(1) {:baz}
|
57
|
-
end
|
58
|
-
@object.foobar(1).should == :baz
|
59
|
-
proc {@object.foobar(1)}.should raise_error(Errors::TimesCalledError)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
describe Space, "#scenario_method_proxy with a Stub strategy" do
|
64
|
-
it_should_behave_like "RR::Space#scenario_method_proxy"
|
65
|
-
|
66
|
-
before do
|
67
|
-
@creator = @space.scenario_creator
|
68
|
-
@creator.stub
|
69
|
-
end
|
70
|
-
|
71
|
-
it "creates a stub Scenario for method when passed a second argument" do
|
72
|
-
@space.scenario_method_proxy(@creator, @object, :foobar).with(1) {:baz}
|
73
|
-
@object.foobar(1).should == :baz
|
74
|
-
@object.foobar(1).should == :baz
|
75
|
-
end
|
76
|
-
|
77
|
-
it "uses block definition when passed a block" do
|
78
|
-
@space.scenario_method_proxy(@creator, @object) do |c|
|
79
|
-
c.foobar(1) {:return_value}
|
80
|
-
c.foobar.with_any_args {:default}
|
81
|
-
c.baz(1) {:baz_value}
|
82
|
-
end
|
83
|
-
@object.foobar(1).should == :return_value
|
84
|
-
@object.foobar.should == :default
|
85
|
-
proc {@object.baz.should == :return_value}.should raise_error
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
describe Space, "#scenario_method_proxy with a Mock Probe strategy" do
|
90
|
-
it_should_behave_like "RR::Space#scenario_method_proxy"
|
91
|
-
|
92
|
-
before do
|
93
|
-
@creator = @space.scenario_creator
|
94
|
-
@creator.mock.probe
|
95
|
-
def @object.foobar(*args)
|
96
|
-
:original_foobar
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
it "creates a mock probe Scenario for method when passed a second argument" do
|
101
|
-
@space.scenario_method_proxy(@creator, @object, :foobar).with(1)
|
102
|
-
@object.foobar(1).should == :original_foobar
|
103
|
-
proc {@object.foobar(1)}.should raise_error(Errors::TimesCalledError)
|
104
|
-
end
|
105
|
-
|
106
|
-
it "uses block definition when passed a block" do
|
107
|
-
@space.scenario_method_proxy(@creator, @object) do |c|
|
108
|
-
c.foobar(1)
|
109
|
-
end
|
110
|
-
@object.foobar(1).should == :original_foobar
|
111
|
-
proc {@object.foobar(1)}.should raise_error(Errors::TimesCalledError)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
describe Space, "#scenario_method_proxy with a Stub Probe strategy" do
|
116
|
-
it_should_behave_like "RR::Space#scenario_method_proxy"
|
117
|
-
|
118
|
-
before do
|
119
|
-
@creator = @space.scenario_creator
|
120
|
-
@creator.stub.probe
|
121
|
-
def @object.foobar(*args)
|
122
|
-
:original_foobar
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
it "creates a stub probe Scenario for method when passed a second argument" do
|
127
|
-
@space.scenario_method_proxy(@creator, @object, :foobar)
|
128
|
-
@object.foobar(1).should == :original_foobar
|
129
|
-
@object.foobar(1).should == :original_foobar
|
130
|
-
end
|
131
|
-
|
132
|
-
it "uses block definition when passed a block" do
|
133
|
-
@space.scenario_method_proxy(@creator, @object) do |c|
|
134
|
-
c.foobar(1)
|
135
|
-
end
|
136
|
-
@object.foobar(1).should == :original_foobar
|
137
|
-
@object.foobar(1).should == :original_foobar
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
describe Space, "#scenario_method_proxy with a Do Not Allow strategy" do
|
142
|
-
it_should_behave_like "RR::Space#scenario_method_proxy"
|
143
|
-
|
144
|
-
before do
|
145
|
-
@creator = @space.scenario_creator
|
146
|
-
@creator.do_not_call
|
147
|
-
end
|
148
|
-
|
149
|
-
it "creates a do not allow Scenario for method when passed a second argument" do
|
150
|
-
@space.scenario_method_proxy(@creator, @object, :foobar).with(1)
|
151
|
-
proc {@object.foobar(1)}.should raise_error(Errors::TimesCalledError)
|
152
|
-
end
|
153
|
-
|
154
|
-
it "uses block definition when passed a block" do
|
155
|
-
@space.scenario_method_proxy(@creator, @object) do |c|
|
156
|
-
c.foobar(1)
|
157
|
-
end
|
158
|
-
proc {@object.foobar(1)}.should raise_error(Errors::TimesCalledError)
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
describe Space, "#scenario_creator" do
|
163
|
-
it_should_behave_like "RR::Space"
|
164
|
-
|
165
|
-
before do
|
166
|
-
@space = Space.new
|
167
|
-
@object = Object.new
|
168
|
-
@creator = @space.scenario_creator
|
169
|
-
end
|
170
|
-
|
171
|
-
it "sets the space" do
|
172
|
-
@creator.space.should === @space
|
173
|
-
end
|
174
|
-
|
175
|
-
it "creates a ScenarioCreator" do
|
176
|
-
@creator.should be_instance_of(ScenarioCreator)
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
describe Space, "#scenario" do
|
181
|
-
it_should_behave_like "RR::Space"
|
182
|
-
|
183
|
-
before do
|
184
|
-
@space = Space.new
|
185
|
-
@object = Object.new
|
186
|
-
@method_name = :foobar
|
187
|
-
end
|
188
|
-
|
189
|
-
it "creates a Scenario and registers it to the double" do
|
190
|
-
double = @space.double(@object, @method_name)
|
191
|
-
def double.scenarios
|
192
|
-
@scenarios
|
193
|
-
end
|
194
|
-
|
195
|
-
scenario = @space.scenario(double)
|
196
|
-
double.scenarios.should include(scenario)
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
describe Space, "#double" do
|
201
|
-
it_should_behave_like "RR::Space"
|
202
|
-
|
203
|
-
before do
|
204
|
-
@space = Space.new
|
205
|
-
end
|
206
|
-
|
207
|
-
it "creates a new double when existing object == but not === with the same method name" do
|
208
|
-
object1 = []
|
209
|
-
object2 = []
|
210
|
-
(object1 === object2).should be_true
|
211
|
-
object1.__id__.should_not == object2.__id__
|
212
|
-
|
213
|
-
double1 = @space.double(object1, :foobar)
|
214
|
-
double2 = @space.double(object2, :foobar)
|
215
|
-
|
216
|
-
double1.should_not == double2
|
217
|
-
end
|
218
|
-
end
|
219
|
-
|
220
|
-
describe Space, "#double when double does not exist" do
|
221
|
-
it_should_behave_like "RR::Space"
|
222
|
-
|
223
|
-
before do
|
224
|
-
@space = Space.new
|
225
|
-
@object = Object.new
|
226
|
-
def @object.foobar(*args)
|
227
|
-
:original_foobar
|
228
|
-
end
|
229
|
-
@method_name = :foobar
|
230
|
-
end
|
231
|
-
|
232
|
-
it "returns double and adds double to double list when method_name is a symbol" do
|
233
|
-
double = @space.double(@object, @method_name)
|
234
|
-
@space.double(@object, @method_name).should === double
|
235
|
-
double.space.should === @space
|
236
|
-
double.object.should === @object
|
237
|
-
double.method_name.should === @method_name
|
238
|
-
end
|
239
|
-
|
240
|
-
it "returns double and adds double to double list when method_name is a string" do
|
241
|
-
double = @space.double(@object, 'foobar')
|
242
|
-
@space.double(@object, @method_name).should === double
|
243
|
-
double.space.should === @space
|
244
|
-
double.object.should === @object
|
245
|
-
double.method_name.should === @method_name
|
246
|
-
end
|
247
|
-
|
248
|
-
it "overrides the method when passing a block" do
|
249
|
-
double = @space.double(@object, @method_name)
|
250
|
-
@object.methods.should include("__rr__#{@method_name}")
|
251
|
-
end
|
252
|
-
end
|
253
|
-
|
254
|
-
describe Space, "#double when double exists" do
|
255
|
-
it_should_behave_like "RR::Space"
|
256
|
-
|
257
|
-
before do
|
258
|
-
@space = Space.new
|
259
|
-
@object = Object.new
|
260
|
-
def @object.foobar(*args)
|
261
|
-
:original_foobar
|
262
|
-
end
|
263
|
-
@method_name = :foobar
|
264
|
-
end
|
265
|
-
|
266
|
-
it "returns the existing double" do
|
267
|
-
original_foobar_method = @object.method(:foobar)
|
268
|
-
double = @space.double(@object, 'foobar')
|
269
|
-
|
270
|
-
double.object_has_original_method?.should be_true
|
271
|
-
|
272
|
-
@space.double(@object, 'foobar').should === double
|
273
|
-
|
274
|
-
double.reset
|
275
|
-
@object.foobar.should == :original_foobar
|
276
|
-
end
|
277
|
-
end
|
278
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
require "examples/example_helper"
|
2
|
-
|
3
|
-
module RR
|
4
|
-
describe Space, " class" do
|
5
|
-
it_should_behave_like "RR::Space"
|
6
|
-
|
7
|
-
before(:each) do
|
8
|
-
@original_space = Space.instance
|
9
|
-
@space = Space.new
|
10
|
-
Space.instance = @space
|
11
|
-
end
|
12
|
-
|
13
|
-
after(:each) do
|
14
|
-
Space.instance = @original_space
|
15
|
-
end
|
16
|
-
|
17
|
-
it "proxies to a singleton instance of Space" do
|
18
|
-
create_double_args = nil
|
19
|
-
(class << @space; self; end).class_eval do
|
20
|
-
define_method :double do |*args|
|
21
|
-
create_double_args = args
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
Space.double(:foo, :bar)
|
26
|
-
create_double_args.should == [:foo, :bar]
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|