rr 0.4.10 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +14 -0
- data/README.rdoc +67 -13
- data/Rakefile +1 -1
- data/lib/rr.rb +29 -9
- data/lib/rr/adapters/rr_methods.rb +38 -158
- data/lib/rr/double.rb +46 -41
- data/lib/rr/double_definitions/child_double_definition_creator.rb +23 -0
- data/lib/rr/double_definitions/double_definition.rb +212 -0
- data/lib/rr/double_definitions/double_definition_creator.rb +153 -0
- data/lib/rr/double_definitions/double_definition_creator_proxy.rb +25 -0
- data/lib/rr/double_definitions/strategies/implementation/implementation_strategy.rb +15 -0
- data/lib/rr/double_definitions/strategies/implementation/proxy.rb +62 -0
- data/lib/rr/double_definitions/strategies/implementation/reimplementation.rb +14 -0
- data/lib/rr/double_definitions/strategies/scope/instance.rb +15 -0
- data/lib/rr/double_definitions/strategies/scope/instance_of_class.rb +43 -0
- data/lib/rr/double_definitions/strategies/scope/scope_strategy.rb +15 -0
- data/lib/rr/double_definitions/strategies/strategy.rb +70 -0
- data/lib/rr/double_definitions/strategies/verification/dont_allow.rb +34 -0
- data/lib/rr/double_definitions/strategies/verification/mock.rb +44 -0
- data/lib/rr/double_definitions/strategies/verification/stub.rb +45 -0
- data/lib/rr/double_definitions/strategies/verification/verification_strategy.rb +15 -0
- data/lib/rr/double_injection.rb +21 -15
- data/lib/rr/expectations/argument_equality_expectation.rb +2 -1
- data/lib/rr/space.rb +23 -22
- data/lib/rr/wildcard_matchers/hash_including.rb +29 -0
- data/lib/rr/wildcard_matchers/satisfy.rb +26 -0
- data/spec/high_level_spec.rb +111 -64
- data/spec/rr/adapters/rr_methods_argument_matcher_spec.rb +1 -1
- data/spec/rr/adapters/rr_methods_creator_spec.rb +99 -315
- data/spec/rr/adapters/rr_methods_space_spec.rb +90 -109
- data/spec/rr/adapters/rr_methods_spec_helper.rb +1 -1
- data/spec/rr/adapters/rr_methods_times_matcher_spec.rb +1 -1
- data/spec/rr/double_definitions/child_double_definition_creator_spec.rb +103 -0
- data/spec/rr/double_definitions/double_definition_creator_proxy_spec.rb +83 -0
- data/spec/rr/double_definitions/double_definition_creator_spec.rb +495 -0
- data/spec/rr/double_definitions/double_definition_spec.rb +1116 -0
- data/spec/rr/double_injection/double_injection_bind_spec.rb +111 -0
- data/spec/rr/double_injection/double_injection_dispatching_spec.rb +245 -0
- data/spec/rr/{double → double_injection}/double_injection_has_original_method_spec.rb +9 -9
- data/spec/rr/double_injection/double_injection_reset_spec.rb +90 -0
- data/spec/rr/double_injection/double_injection_spec.rb +77 -0
- data/spec/rr/double_injection/double_injection_verify_spec.rb +29 -0
- data/spec/rr/double_spec.rb +156 -136
- data/spec/rr/errors/rr_error_spec.rb +1 -1
- data/spec/rr/expectations/any_argument_expectation_spec.rb +1 -1
- data/spec/rr/expectations/anything_argument_equality_expectation_spec.rb +6 -30
- data/spec/rr/expectations/argument_equality_expectation_spec.rb +35 -18
- data/spec/rr/expectations/boolean_argument_equality_expectation_spec.rb +22 -41
- data/spec/rr/expectations/hash_including_argument_equality_expectation_spec.rb +82 -0
- data/spec/rr/expectations/hash_including_spec.rb +17 -0
- data/spec/rr/expectations/satisfy_argument_equality_expectation_spec.rb +59 -0
- data/spec/rr/expectations/satisfy_spec.rb +14 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_any_times_spec.rb +30 -28
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_least_spec.rb +55 -54
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_most_spec.rb +49 -48
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_helper.rb +9 -7
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_integer_spec.rb +77 -76
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_proc_spec.rb +58 -57
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_range_spec.rb +59 -58
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_spec.rb +25 -24
- data/spec/rr/rspec/rspec_adapter_spec.rb +12 -11
- data/spec/rr/rspec/rspec_backtrace_tweaking_spec.rb +10 -8
- data/spec/rr/rspec/rspec_usage_spec.rb +1 -1
- data/spec/rr/space/hash_with_object_id_key_spec.rb +1 -1
- data/spec/rr/space/space_spec.rb +330 -192
- data/spec/rr/test_unit/test_helper.rb +1 -2
- data/spec/rr/test_unit/test_unit_backtrace_test.rb +1 -2
- data/spec/rr/test_unit/test_unit_integration_test.rb +1 -2
- data/spec/rr/times_called_matchers/any_times_matcher_spec.rb +1 -1
- data/spec/rr/times_called_matchers/at_least_matcher_spec.rb +1 -1
- data/spec/rr/times_called_matchers/at_most_matcher_spec.rb +1 -1
- data/spec/rr/times_called_matchers/integer_matcher_spec.rb +1 -1
- data/spec/rr/times_called_matchers/proc_matcher_spec.rb +1 -1
- data/spec/rr/times_called_matchers/range_matcher_spec.rb +1 -1
- data/spec/rr/times_called_matchers/times_called_matcher_spec.rb +1 -1
- data/spec/rr/wildcard_matchers/anything_spec.rb +24 -0
- data/spec/rr/wildcard_matchers/boolean_spec.rb +36 -0
- data/spec/rr/wildcard_matchers/duck_type_spec.rb +52 -0
- data/spec/rr/wildcard_matchers/is_a_spec.rb +32 -0
- data/spec/rr/wildcard_matchers/numeric_spec.rb +32 -0
- data/spec/rr/wildcard_matchers/range_spec.rb +35 -0
- data/spec/rr/wildcard_matchers/regexp_spec.rb +43 -0
- data/spec/rr_spec.rb +28 -0
- data/spec/spec_helper.rb +84 -0
- metadata +43 -29
- data/lib/rr/double_creator.rb +0 -271
- data/lib/rr/double_definition.rb +0 -179
- data/lib/rr/double_definition_builder.rb +0 -44
- data/lib/rr/double_definition_creator.rb +0 -156
- data/lib/rr/double_definition_creator_proxy.rb +0 -20
- data/spec/rr/double/double_injection_bind_spec.rb +0 -105
- data/spec/rr/double/double_injection_dispatching_spec.rb +0 -228
- data/spec/rr/double/double_injection_reset_spec.rb +0 -86
- data/spec/rr/double/double_injection_spec.rb +0 -72
- data/spec/rr/double/double_injection_verify_spec.rb +0 -24
- data/spec/rr/double_definition_creator_proxy_spec.rb +0 -85
- data/spec/rr/double_definition_creator_spec.rb +0 -496
- data/spec/rr/double_definition_spec.rb +0 -815
- data/spec/rr/expectations/anything_spec.rb +0 -14
- data/spec/rr/expectations/boolean_spec.rb +0 -14
- data/spec/rr/expectations/duck_type_argument_equality_expectation_spec.rb +0 -71
- data/spec/rr/expectations/duck_type_spec.rb +0 -14
- data/spec/rr/expectations/is_a_argument_equality_expectation_spec.rb +0 -51
- data/spec/rr/expectations/is_a_spec.rb +0 -14
- data/spec/rr/expectations/numeric_argument_equality_expectation_spec.rb +0 -47
- data/spec/rr/expectations/numeric_spec.rb +0 -14
- data/spec/rr/expectations/range_argument_equality_expectation_spec.rb +0 -59
- data/spec/rr/expectations/range_spec.rb +0 -10
- data/spec/rr/expectations/regexp_argument_equality_expectation_spec.rb +0 -72
- data/spec/rr/expectations/regexp_spec.rb +0 -10
@@ -1,81 +1,82 @@
|
|
1
|
-
require "
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../../spec_helper")
|
2
2
|
|
3
3
|
module RR
|
4
4
|
module Expectations
|
5
|
-
describe TimesCalledExpectation
|
6
|
-
|
7
|
-
|
5
|
+
describe TimesCalledExpectation do
|
6
|
+
context "when using a RangeMatcher" do
|
7
|
+
it_should_behave_like "RR::Expectations::TimesCalledExpectation"
|
8
|
+
attr_reader :matcher, :expectation
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
end
|
13
|
-
|
14
|
-
describe "#verify" do
|
15
|
-
it "returns true when times called falls within a range" do
|
16
|
-
expectation.verify.should == false
|
17
|
-
expectation.attempt
|
18
|
-
expectation.verify.should == true
|
19
|
-
expectation.attempt
|
20
|
-
expectation.verify.should == true
|
10
|
+
before do
|
11
|
+
@matcher = TimesCalledMatchers::RangeMatcher.new(1..2)
|
12
|
+
@expectation = TimesCalledExpectation.new(double, matcher)
|
21
13
|
end
|
22
|
-
end
|
23
14
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
15
|
+
describe "#verify" do
|
16
|
+
it "returns true when times called falls within a range" do
|
17
|
+
expectation.verify.should == false
|
18
|
+
expectation.attempt
|
19
|
+
expectation.verify.should == true
|
20
|
+
expectation.attempt
|
21
|
+
expectation.verify.should == true
|
22
|
+
end
|
28
23
|
end
|
29
24
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
25
|
+
describe "#verify! when passed a Range (1..2)" do
|
26
|
+
it "passes after attempt! called 1 time" do
|
27
|
+
expectation.attempt
|
28
|
+
expectation.verify!
|
29
|
+
end
|
35
30
|
|
36
|
-
|
37
|
-
expectation.attempt
|
38
|
-
expectation.attempt
|
39
|
-
lambda do
|
31
|
+
it "passes after attempt! called 2 times" do
|
40
32
|
expectation.attempt
|
41
|
-
|
42
|
-
|
43
|
-
|
33
|
+
expectation.attempt
|
34
|
+
expectation.verify!
|
35
|
+
end
|
44
36
|
|
45
|
-
|
46
|
-
|
47
|
-
|
37
|
+
it "can't be called when attempt! is called 3 times" do
|
38
|
+
expectation.attempt
|
39
|
+
expectation.attempt
|
40
|
+
lambda do
|
41
|
+
expectation.attempt
|
42
|
+
end.should raise_error(Errors::TimesCalledError, "foobar()\nCalled 3 times.\nExpected 1..2 times.")
|
43
|
+
end
|
48
44
|
end
|
49
45
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
46
|
+
describe "#attempt? with RangeMatcher" do
|
47
|
+
it "returns true when attempted less than low end of range" do
|
48
|
+
expectation.should be_attempt
|
49
|
+
end
|
50
|
+
|
51
|
+
it "returns false when attempted in range" do
|
52
|
+
expectation.attempt
|
53
|
+
expectation.should be_attempt
|
54
|
+
expectation.attempt
|
55
|
+
expectation.should be_attempt
|
56
|
+
end
|
56
57
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
58
|
+
it "raises error before attempted more than expected times" do
|
59
|
+
2.times {expectation.attempt}
|
60
|
+
lambda {expectation.attempt}.should raise_error(
|
61
|
+
Errors::TimesCalledError
|
62
|
+
)
|
63
|
+
end
|
62
64
|
end
|
63
|
-
end
|
64
65
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
66
|
+
describe "#attempt! for a range expectation" do
|
67
|
+
it "raises error when attempt! called more than range permits" do
|
68
|
+
expectation.attempt
|
69
|
+
expectation.attempt
|
70
|
+
raises_expectation_error {expectation.attempt}
|
71
|
+
end
|
70
72
|
end
|
71
|
-
end
|
72
73
|
|
73
|
-
|
74
|
-
|
75
|
-
|
74
|
+
describe "#terminal? with RangeMatcher" do
|
75
|
+
it "returns true" do
|
76
|
+
expectation.should be_terminal
|
77
|
+
end
|
76
78
|
end
|
77
79
|
end
|
78
80
|
end
|
79
|
-
|
80
81
|
end
|
81
82
|
end
|
@@ -1,36 +1,37 @@
|
|
1
|
-
require "
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../../spec_helper")
|
2
2
|
|
3
3
|
module RR
|
4
4
|
module Expectations
|
5
|
-
describe TimesCalledExpectation
|
6
|
-
|
7
|
-
|
5
|
+
describe TimesCalledExpectation do
|
6
|
+
context "with a failure" do
|
7
|
+
it_should_behave_like "RR::Expectations::TimesCalledExpectation"
|
8
|
+
attr_reader :times, :matcher, :expectation
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
before do
|
11
|
+
@times = 0
|
12
|
+
@matcher = TimesCalledMatchers::IntegerMatcher.new(times)
|
13
|
+
@expectation = TimesCalledExpectation.new(double, matcher)
|
14
|
+
end
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
describe "#attempt!" do
|
17
|
+
it "raises error that includes the double" do
|
18
|
+
lambda {expectation.attempt}.should raise_error(
|
19
|
+
Errors::TimesCalledError,
|
20
|
+
"#{double.formatted_name}\n#{matcher.error_message(1)}"
|
21
|
+
)
|
22
|
+
end
|
21
23
|
end
|
22
|
-
end
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
25
|
+
describe "#verify!" do
|
26
|
+
it "raises error with passed in message prepended" do
|
27
|
+
expectation.instance_variable_set(:@times_called, 1)
|
28
|
+
lambda {expectation.verify!}.should raise_error(
|
29
|
+
Errors::TimesCalledError,
|
30
|
+
"#{double.formatted_name}\n#{matcher.error_message(1)}"
|
31
|
+
)
|
32
|
+
end
|
31
33
|
end
|
32
34
|
end
|
33
35
|
end
|
34
|
-
|
35
36
|
end
|
36
37
|
end
|
@@ -1,22 +1,23 @@
|
|
1
|
-
require "
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
|
2
2
|
|
3
3
|
module RR
|
4
4
|
module Adapters
|
5
5
|
describe Rspec do
|
6
|
+
attr_reader :fixture, :subject, :method_name
|
6
7
|
describe "#setup_mocks_for_rspec" do
|
7
8
|
before do
|
8
9
|
@fixture = Object.new
|
9
|
-
|
10
|
+
fixture.extend Rspec
|
10
11
|
|
11
12
|
@subject = Object.new
|
12
13
|
@method_name = :foobar
|
13
14
|
end
|
14
15
|
|
15
16
|
it "resets the double_injections" do
|
16
|
-
RR.double_injection(
|
17
|
+
RR.double_injection(subject, method_name)
|
17
18
|
RR.double_injections.should_not be_empty
|
18
19
|
|
19
|
-
|
20
|
+
fixture.setup_mocks_for_rspec
|
20
21
|
RR.double_injections.should be_empty
|
21
22
|
end
|
22
23
|
end
|
@@ -24,20 +25,20 @@ module RR
|
|
24
25
|
describe "#verify_mocks_for_rspec" do
|
25
26
|
before do
|
26
27
|
@fixture = Object.new
|
27
|
-
|
28
|
+
fixture.extend Rspec
|
28
29
|
|
29
30
|
@subject = Object.new
|
30
31
|
@method_name = :foobar
|
31
32
|
end
|
32
33
|
|
33
34
|
it "verifies the double_injections" do
|
34
|
-
double_injection = RR.double_injection(
|
35
|
-
double =
|
35
|
+
double_injection = RR.double_injection(subject, method_name)
|
36
|
+
double = new_double(double_injection)
|
36
37
|
|
37
38
|
double.once
|
38
39
|
|
39
40
|
lambda do
|
40
|
-
|
41
|
+
fixture.verify_mocks_for_rspec
|
41
42
|
end.should raise_error(::RR::Errors::TimesCalledError)
|
42
43
|
RR.double_injections.should be_empty
|
43
44
|
end
|
@@ -46,17 +47,17 @@ module RR
|
|
46
47
|
describe "#teardown_mocks_for_rspec" do
|
47
48
|
before do
|
48
49
|
@fixture = Object.new
|
49
|
-
|
50
|
+
fixture.extend Rspec
|
50
51
|
|
51
52
|
@subject = Object.new
|
52
53
|
@method_name = :foobar
|
53
54
|
end
|
54
55
|
|
55
56
|
it "resets the double_injections" do
|
56
|
-
RR.double_injection(
|
57
|
+
RR.double_injection(subject, method_name)
|
57
58
|
RR.double_injections.should_not be_empty
|
58
59
|
|
59
|
-
|
60
|
+
fixture.teardown_mocks_for_rspec
|
60
61
|
RR.double_injections.should be_empty
|
61
62
|
end
|
62
63
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require "
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
|
2
2
|
|
3
3
|
module RR
|
4
4
|
module Adapters
|
@@ -20,30 +20,32 @@ module RR
|
|
20
20
|
end
|
21
21
|
|
22
22
|
describe " backtrace tweaking" do
|
23
|
-
attr_reader :original_rspec_options, :output
|
23
|
+
attr_reader :original_rspec_options, :error, :output
|
24
24
|
before do
|
25
|
-
@original_rspec_options =
|
25
|
+
@original_rspec_options = Spec::Runner.options
|
26
|
+
@error = StringIO.new("")
|
26
27
|
@output = StringIO.new("")
|
27
|
-
|
28
|
+
Spec::Runner.use(::Spec::Runner::Options.new(error, output))
|
28
29
|
end
|
29
30
|
|
30
31
|
after do
|
31
|
-
|
32
|
+
Spec::Runner.use(original_rspec_options)
|
32
33
|
end
|
33
34
|
|
34
35
|
it "hides rr library from the backtrace by default" do
|
35
36
|
subject = @subject
|
36
|
-
Class.new(::Spec::Example::ExampleGroup) do
|
37
|
+
example_group = Class.new(::Spec::Example::ExampleGroup) do
|
37
38
|
describe "Example"
|
38
39
|
|
39
40
|
it("hides RR framework in backtrace") do
|
40
41
|
mock(subject).foobar()
|
41
|
-
RR
|
42
|
+
RR.verify_double(subject, :foobar)
|
42
43
|
end
|
43
44
|
end
|
44
45
|
|
45
|
-
|
46
|
+
Spec::Runner.options.run_examples
|
46
47
|
|
48
|
+
output.string.should_not be_empty
|
47
49
|
output.string.should_not include("lib/rr")
|
48
50
|
end
|
49
51
|
end
|
data/spec/rr/space/space_spec.rb
CHANGED
@@ -1,371 +1,510 @@
|
|
1
|
-
require "
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
|
2
2
|
|
3
3
|
module RR
|
4
4
|
describe Space do
|
5
5
|
it_should_behave_like "Swapped Space"
|
6
|
+
attr_reader :space, :subject, :method_name, :double_injection
|
7
|
+
|
8
|
+
before do
|
9
|
+
@subject = Object.new
|
10
|
+
end
|
6
11
|
|
7
12
|
describe ".method_missing" do
|
8
13
|
it "proxies to a singleton instance of Space" do
|
9
14
|
create_double_args = nil
|
10
|
-
(class <<
|
15
|
+
(class << space; self; end).class_eval do
|
11
16
|
define_method :double_injection do |*args|
|
12
17
|
create_double_args = args
|
13
18
|
end
|
14
19
|
end
|
15
20
|
|
16
|
-
|
21
|
+
space.double_injection(:foo, :bar)
|
17
22
|
create_double_args.should == [:foo, :bar]
|
18
23
|
end
|
19
24
|
end
|
20
25
|
|
21
26
|
describe "#double_injection" do
|
22
|
-
|
23
|
-
|
24
|
-
|
27
|
+
context "when existing subject == but not === with the same method name" do
|
28
|
+
it "creates a new DoubleInjection" do
|
29
|
+
subject_1 = []
|
30
|
+
subject_2 = []
|
31
|
+
(subject_1 === subject_2).should be_true
|
32
|
+
subject_1.__id__.should_not == subject_2.__id__
|
25
33
|
|
26
|
-
|
27
|
-
|
28
|
-
object2 = []
|
29
|
-
(object1 === object2).should be_true
|
30
|
-
object1.__id__.should_not == object2.__id__
|
34
|
+
double_1 = space.double_injection(subject_1, :foobar)
|
35
|
+
double_2 = space.double_injection(subject_2, :foobar)
|
31
36
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
double1.should_not == double2
|
37
|
+
double_1.should_not == double_2
|
38
|
+
end
|
36
39
|
end
|
37
40
|
|
38
41
|
context "when double_injection does not exist" do
|
39
42
|
before do
|
40
|
-
|
41
|
-
def @object.foobar(*args)
|
43
|
+
def subject.foobar(*args)
|
42
44
|
:original_foobar
|
43
45
|
end
|
44
46
|
@method_name = :foobar
|
45
47
|
end
|
46
48
|
|
47
|
-
|
48
|
-
double_injection
|
49
|
-
|
50
|
-
|
51
|
-
|
49
|
+
context "when method_name is a symbol" do
|
50
|
+
it "returns double_injection and adds double_injection to double_injection list" do
|
51
|
+
@double_injection = space.double_injection(subject, method_name)
|
52
|
+
space.double_injection(subject, method_name).should === double_injection
|
53
|
+
double_injection.subject.should === subject
|
54
|
+
double_injection.method_name.should === method_name
|
55
|
+
end
|
52
56
|
end
|
53
57
|
|
54
|
-
|
55
|
-
double_injection
|
56
|
-
|
57
|
-
|
58
|
-
|
58
|
+
context "when method_name is a string" do
|
59
|
+
it "returns double_injection and adds double_injection to double_injection list" do
|
60
|
+
@double_injection = space.double_injection(subject, 'foobar')
|
61
|
+
space.double_injection(subject, method_name).should === double_injection
|
62
|
+
double_injection.subject.should === subject
|
63
|
+
double_injection.method_name.should === method_name
|
64
|
+
end
|
59
65
|
end
|
60
66
|
|
61
67
|
it "overrides the method when passing a block" do
|
62
|
-
double_injection =
|
63
|
-
|
68
|
+
@double_injection = space.double_injection(subject, method_name)
|
69
|
+
subject.methods.should include("__rr__#{method_name}")
|
64
70
|
end
|
65
71
|
end
|
66
72
|
|
67
73
|
context "when double_injection exists" do
|
68
74
|
before do
|
69
|
-
|
70
|
-
def @object.foobar(*args)
|
75
|
+
def subject.foobar(*args)
|
71
76
|
:original_foobar
|
72
77
|
end
|
73
78
|
@method_name = :foobar
|
74
79
|
end
|
75
80
|
|
76
81
|
it "returns the existing double_injection" do
|
77
|
-
original_foobar_method =
|
78
|
-
double_injection =
|
82
|
+
original_foobar_method = subject.method(:foobar)
|
83
|
+
@double_injection = space.double_injection(subject, 'foobar')
|
79
84
|
|
80
85
|
double_injection.object_has_original_method?.should be_true
|
81
86
|
|
82
|
-
|
87
|
+
space.double_injection(subject, 'foobar').should === double_injection
|
83
88
|
|
84
89
|
double_injection.reset
|
85
|
-
|
90
|
+
subject.foobar.should == :original_foobar
|
86
91
|
end
|
87
92
|
end
|
88
93
|
end
|
89
94
|
|
90
95
|
describe "#reset" do
|
96
|
+
attr_reader :subject_1, :subject_2
|
91
97
|
before do
|
92
|
-
@
|
93
|
-
@
|
94
|
-
@object2 = Object.new
|
98
|
+
@subject_1 = Object.new
|
99
|
+
@subject_2 = Object.new
|
95
100
|
@method_name = :foobar
|
96
101
|
end
|
97
102
|
|
98
103
|
it "removes the ordered doubles" do
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
104
|
+
double_1 = new_double(
|
105
|
+
space.double_injection(subject_1, :foobar1),
|
106
|
+
RR::DoubleDefinitions::DoubleDefinition.new(creator = Object.new, subject_1)
|
107
|
+
)
|
108
|
+
double_2 = new_double(
|
109
|
+
space.double_injection(subject_2, :foobar2),
|
110
|
+
RR::DoubleDefinitions::DoubleDefinition.new(creator = Object.new, subject_2)
|
111
|
+
)
|
112
|
+
double_1.ordered
|
113
|
+
double_2.ordered
|
114
|
+
|
115
|
+
space.ordered_doubles.should_not be_empty
|
116
|
+
|
117
|
+
space.reset
|
118
|
+
space.ordered_doubles.should be_empty
|
112
119
|
end
|
113
120
|
|
114
121
|
it "resets all double_injections" do
|
115
|
-
|
116
|
-
|
122
|
+
double_1 = space.double_injection(subject_1, method_name)
|
123
|
+
double_1_reset_call_count = 0
|
117
124
|
(
|
118
|
-
class <<
|
125
|
+
class << double_1;
|
119
126
|
self;
|
120
127
|
end).class_eval do
|
121
128
|
define_method(:reset) do ||
|
122
|
-
|
129
|
+
double_1_reset_call_count += 1
|
123
130
|
end
|
124
131
|
end
|
125
|
-
|
126
|
-
|
132
|
+
double_2 = space.double_injection(subject_2, method_name)
|
133
|
+
double_2_reset_call_count = 0
|
127
134
|
(
|
128
|
-
class <<
|
135
|
+
class << double_2;
|
129
136
|
self;
|
130
137
|
end).class_eval do
|
131
138
|
define_method(:reset) do ||
|
132
|
-
|
139
|
+
double_2_reset_call_count += 1
|
133
140
|
end
|
134
141
|
end
|
135
142
|
|
136
|
-
|
137
|
-
|
138
|
-
|
143
|
+
space.reset
|
144
|
+
double_1_reset_call_count.should == 1
|
145
|
+
double_2_reset_call_count.should == 1
|
139
146
|
end
|
140
147
|
end
|
141
148
|
|
142
149
|
describe "#reset_double" do
|
143
150
|
before do
|
144
|
-
@space = Space.new
|
145
|
-
@object = Object.new
|
146
151
|
@method_name = :foobar
|
147
152
|
end
|
148
153
|
|
149
154
|
it "resets the double_injections" do
|
150
|
-
double_injection =
|
151
|
-
|
152
|
-
|
155
|
+
@double_injection = space.double_injection(subject, method_name)
|
156
|
+
space.double_injections[subject][method_name].should === double_injection
|
157
|
+
subject.methods.should include("__rr__#{method_name}")
|
153
158
|
|
154
|
-
|
155
|
-
|
156
|
-
|
159
|
+
space.reset_double(subject, method_name)
|
160
|
+
space.double_injections[subject][method_name].should be_nil
|
161
|
+
subject.methods.should_not include("__rr__#{method_name}")
|
157
162
|
end
|
158
163
|
|
159
|
-
|
160
|
-
|
161
|
-
|
164
|
+
context "when it has no double_injections" do
|
165
|
+
it "removes the subject from the double_injections map" do
|
166
|
+
double_1 = space.double_injection(subject, :foobar1)
|
167
|
+
double_2 = space.double_injection(subject, :foobar2)
|
162
168
|
|
163
|
-
|
164
|
-
|
165
|
-
|
169
|
+
space.double_injections.include?(subject).should == true
|
170
|
+
space.double_injections[subject][:foobar1].should_not be_nil
|
171
|
+
space.double_injections[subject][:foobar2].should_not be_nil
|
166
172
|
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
173
|
+
space.reset_double(subject, :foobar1)
|
174
|
+
space.double_injections.include?(subject).should == true
|
175
|
+
space.double_injections[subject][:foobar1].should be_nil
|
176
|
+
space.double_injections[subject][:foobar2].should_not be_nil
|
171
177
|
|
172
|
-
|
173
|
-
|
178
|
+
space.reset_double(subject, :foobar2)
|
179
|
+
space.double_injections.include?(subject).should == false
|
180
|
+
end
|
174
181
|
end
|
175
182
|
end
|
176
183
|
|
177
184
|
describe "#reset_double_injections" do
|
185
|
+
attr_reader :subject_1, :subject_2
|
178
186
|
before do
|
179
|
-
@
|
180
|
-
@
|
187
|
+
@subject_1 = Object.new
|
188
|
+
@subject_2 = Object.new
|
181
189
|
@method_name = :foobar
|
182
190
|
end
|
183
191
|
|
184
192
|
it "resets the double_injection and removes it from the double_injections list" do
|
185
|
-
|
186
|
-
|
187
|
-
(class <<
|
188
|
-
define_method(:reset) do
|
189
|
-
|
193
|
+
double_injection_1 = space.double_injection(subject_1, method_name)
|
194
|
+
double_1_reset_call_count = 0
|
195
|
+
(class << double_injection_1; self; end).class_eval do
|
196
|
+
define_method(:reset) do
|
197
|
+
double_1_reset_call_count += 1
|
190
198
|
end
|
191
199
|
end
|
192
|
-
|
193
|
-
|
194
|
-
(class <<
|
195
|
-
define_method(:reset) do
|
196
|
-
|
200
|
+
double_injection_2 = space.double_injection(subject_2, method_name)
|
201
|
+
double_2_reset_call_count = 0
|
202
|
+
(class << double_injection_2; self; end).class_eval do
|
203
|
+
define_method(:reset) do
|
204
|
+
double_2_reset_call_count += 1
|
197
205
|
end
|
198
206
|
end
|
199
207
|
|
200
|
-
|
201
|
-
|
202
|
-
|
208
|
+
space.__send__(:reset_double_injections)
|
209
|
+
double_1_reset_call_count.should == 1
|
210
|
+
double_2_reset_call_count.should == 1
|
203
211
|
end
|
204
212
|
end
|
205
|
-
|
213
|
+
|
206
214
|
describe "#register_ordered_double" do
|
207
215
|
before(:each) do
|
208
|
-
@object = Object.new
|
209
216
|
@method_name = :foobar
|
210
|
-
@double_injection =
|
217
|
+
@double_injection = space.double_injection(subject, method_name)
|
211
218
|
end
|
212
219
|
|
213
220
|
it "adds the ordered double to the ordered_doubles collection" do
|
214
|
-
|
221
|
+
double_1 = new_double
|
215
222
|
|
216
|
-
|
217
|
-
|
218
|
-
|
223
|
+
space.ordered_doubles.should == []
|
224
|
+
space.register_ordered_double double_1
|
225
|
+
space.ordered_doubles.should == [double_1]
|
219
226
|
|
220
|
-
|
221
|
-
|
222
|
-
|
227
|
+
double_2 = new_double
|
228
|
+
space.register_ordered_double double_2
|
229
|
+
space.ordered_doubles.should == [double_1, double_2]
|
223
230
|
end
|
224
231
|
end
|
225
232
|
|
226
233
|
describe "#verify_doubles" do
|
234
|
+
attr_reader :subject_1, :subject_2, :subject3, :double_1, :double_2, :double3
|
227
235
|
before do
|
228
|
-
@
|
229
|
-
@
|
236
|
+
@subject_1 = Object.new
|
237
|
+
@subject_2 = Object.new
|
238
|
+
@subject3 = Object.new
|
230
239
|
@method_name = :foobar
|
240
|
+
@double_1 = space.double_injection(subject_1, method_name)
|
241
|
+
@double_2 = space.double_injection(subject_2, method_name)
|
242
|
+
@double3 = space.double_injection(subject3, method_name)
|
231
243
|
end
|
232
244
|
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
245
|
+
context "when passed no arguments" do
|
246
|
+
it "verifies and deletes the double_injections" do
|
247
|
+
double_1_verify_call_count = 0
|
248
|
+
double_1_reset_call_count = 0
|
249
|
+
(class << double_1; self; end).class_eval do
|
250
|
+
define_method(:verify) do
|
251
|
+
double_1_verify_call_count += 1
|
252
|
+
end
|
253
|
+
define_method(:reset) do
|
254
|
+
double_1_reset_call_count += 1
|
255
|
+
end
|
240
256
|
end
|
241
|
-
|
242
|
-
|
257
|
+
|
258
|
+
double_2_verify_call_count = 0
|
259
|
+
double_2_reset_call_count = 0
|
260
|
+
(class << double_2; self; end).class_eval do
|
261
|
+
define_method(:verify) do
|
262
|
+
double_2_verify_call_count += 1
|
263
|
+
end
|
264
|
+
define_method(:reset) do
|
265
|
+
double_2_reset_call_count += 1
|
266
|
+
end
|
243
267
|
end
|
268
|
+
|
269
|
+
space.verify_doubles
|
270
|
+
double_1_verify_call_count.should == 1
|
271
|
+
double_2_verify_call_count.should == 1
|
272
|
+
double_1_reset_call_count.should == 1
|
273
|
+
double_1_reset_call_count.should == 1
|
244
274
|
end
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
275
|
+
end
|
276
|
+
|
277
|
+
context "when passed an Object that has at least one DoubleInjection" do
|
278
|
+
it "verifies all Doubles injected into the Object" do
|
279
|
+
double_1_verify_call_count = 0
|
280
|
+
double_1_reset_call_count = 0
|
281
|
+
(class << double_1; self; end).class_eval do
|
282
|
+
define_method(:verify) do
|
283
|
+
double_1_verify_call_count += 1
|
284
|
+
end
|
285
|
+
define_method(:reset) do
|
286
|
+
double_1_reset_call_count += 1
|
287
|
+
end
|
251
288
|
end
|
252
|
-
|
253
|
-
|
289
|
+
|
290
|
+
double_2_verify_call_count = 0
|
291
|
+
double_2_reset_call_count = 0
|
292
|
+
(class << double_2; self; end).class_eval do
|
293
|
+
define_method(:verify) do
|
294
|
+
double_2_verify_call_count += 1
|
295
|
+
end
|
296
|
+
define_method(:reset) do
|
297
|
+
double_2_reset_call_count += 1
|
298
|
+
end
|
254
299
|
end
|
300
|
+
|
301
|
+
space.verify_doubles(subject_1)
|
302
|
+
|
303
|
+
double_1_verify_call_count.should == 1
|
304
|
+
double_1_reset_call_count.should == 1
|
305
|
+
double_2_verify_call_count.should == 0
|
306
|
+
double_2_reset_call_count.should == 0
|
255
307
|
end
|
308
|
+
end
|
309
|
+
|
310
|
+
context "when passed multiple Objects with at least one DoubleInjection" do
|
311
|
+
it "verifies the Doubles injected into all of the Objects" do
|
312
|
+
double_1_verify_call_count = 0
|
313
|
+
double_1_reset_call_count = 0
|
314
|
+
(class << double_1; self; end).class_eval do
|
315
|
+
define_method(:verify) do
|
316
|
+
double_1_verify_call_count += 1
|
317
|
+
end
|
318
|
+
define_method(:reset) do
|
319
|
+
double_1_reset_call_count += 1
|
320
|
+
end
|
321
|
+
end
|
256
322
|
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
323
|
+
double_2_verify_call_count = 0
|
324
|
+
double_2_reset_call_count = 0
|
325
|
+
(class << double_2; self; end).class_eval do
|
326
|
+
define_method(:verify) do
|
327
|
+
double_2_verify_call_count += 1
|
328
|
+
end
|
329
|
+
define_method(:reset) do
|
330
|
+
double_2_reset_call_count += 1
|
331
|
+
end
|
332
|
+
end
|
333
|
+
|
334
|
+
double3_verify_call_count = 0
|
335
|
+
double3_reset_call_count = 0
|
336
|
+
(class << double3; self; end).class_eval do
|
337
|
+
define_method(:verify) do
|
338
|
+
double3_verify_call_count += 1
|
339
|
+
end
|
340
|
+
define_method(:reset) do
|
341
|
+
double3_reset_call_count += 1
|
342
|
+
end
|
343
|
+
end
|
344
|
+
|
345
|
+
space.verify_doubles(subject_1, subject_2)
|
346
|
+
|
347
|
+
double_1_verify_call_count.should == 1
|
348
|
+
double_1_reset_call_count.should == 1
|
349
|
+
double_2_verify_call_count.should == 1
|
350
|
+
double_2_reset_call_count.should == 1
|
351
|
+
double3_verify_call_count.should == 0
|
352
|
+
double3_reset_call_count.should == 0
|
353
|
+
end
|
354
|
+
end
|
355
|
+
|
356
|
+
context "when passed an subject that does not have a DoubleInjection" do
|
357
|
+
it "does not raise an error" do
|
358
|
+
double_1_verify_call_count = 0
|
359
|
+
double_1_reset_call_count = 0
|
360
|
+
(class << double_1; self; end).class_eval do
|
361
|
+
define_method(:verify) do
|
362
|
+
double_1_verify_call_count += 1
|
363
|
+
end
|
364
|
+
define_method(:reset) do
|
365
|
+
double_1_reset_call_count += 1
|
366
|
+
end
|
367
|
+
end
|
368
|
+
|
369
|
+
double_2_verify_call_count = 0
|
370
|
+
double_2_reset_call_count = 0
|
371
|
+
(class << double_2; self; end).class_eval do
|
372
|
+
define_method(:verify) do
|
373
|
+
double_2_verify_call_count += 1
|
374
|
+
end
|
375
|
+
define_method(:reset) do
|
376
|
+
double_2_reset_call_count += 1
|
377
|
+
end
|
378
|
+
end
|
379
|
+
|
380
|
+
double3_verify_call_count = 0
|
381
|
+
double3_reset_call_count = 0
|
382
|
+
(class << double3; self; end).class_eval do
|
383
|
+
define_method(:verify) do
|
384
|
+
double3_verify_call_count += 1
|
385
|
+
end
|
386
|
+
define_method(:reset) do
|
387
|
+
double3_reset_call_count += 1
|
388
|
+
end
|
389
|
+
end
|
390
|
+
|
391
|
+
no_double_injection_object = Object.new
|
392
|
+
space.verify_doubles(no_double_injection_object)
|
393
|
+
|
394
|
+
double_1_verify_call_count.should == 0
|
395
|
+
double_1_reset_call_count.should == 0
|
396
|
+
double_2_verify_call_count.should == 0
|
397
|
+
double_2_reset_call_count.should == 0
|
398
|
+
double3_verify_call_count.should == 0
|
399
|
+
double3_reset_call_count.should == 0
|
400
|
+
end
|
262
401
|
end
|
263
402
|
end
|
264
403
|
|
265
404
|
describe "#verify_double" do
|
266
405
|
before do
|
267
|
-
@object = Object.new
|
268
406
|
@method_name = :foobar
|
269
407
|
end
|
270
408
|
|
271
409
|
it "verifies and deletes the double_injection" do
|
272
|
-
double_injection =
|
273
|
-
|
274
|
-
|
410
|
+
@double_injection = space.double_injection(subject, method_name)
|
411
|
+
space.double_injections[subject][method_name].should === double_injection
|
412
|
+
subject.methods.should include("__rr__#{method_name}")
|
275
413
|
|
276
|
-
|
414
|
+
verify_call_count = 0
|
277
415
|
(class << double_injection; self; end).class_eval do
|
278
|
-
define_method(:verify) do
|
279
|
-
|
416
|
+
define_method(:verify) do
|
417
|
+
verify_call_count += 1
|
280
418
|
end
|
281
419
|
end
|
282
|
-
|
283
|
-
|
420
|
+
space.verify_double(subject, method_name)
|
421
|
+
verify_call_count.should == 1
|
284
422
|
|
285
|
-
|
286
|
-
|
423
|
+
space.double_injections[subject][method_name].should be_nil
|
424
|
+
subject.methods.should_not include("__rr__#{method_name}")
|
287
425
|
end
|
288
426
|
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
427
|
+
context "when verifying the double_injection raises an error" do
|
428
|
+
it "deletes the double_injection" do
|
429
|
+
@double_injection = space.double_injection(subject, method_name)
|
430
|
+
space.double_injections[subject][method_name].should === double_injection
|
431
|
+
subject.methods.should include("__rr__#{method_name}")
|
432
|
+
|
433
|
+
verify_called = true
|
434
|
+
(class << double_injection; self; end).class_eval do
|
435
|
+
define_method(:verify) do
|
436
|
+
verify_called = true
|
437
|
+
raise "An Error"
|
438
|
+
end
|
299
439
|
end
|
300
|
-
|
301
|
-
|
302
|
-
verify_called.should be_true
|
440
|
+
lambda {space.verify_double(subject, method_name)}.should raise_error
|
441
|
+
verify_called.should be_true
|
303
442
|
|
304
|
-
|
305
|
-
|
443
|
+
space.double_injections[subject][method_name].should be_nil
|
444
|
+
subject.methods.should_not include("__rr__#{method_name}")
|
445
|
+
end
|
306
446
|
end
|
307
447
|
end
|
308
448
|
|
309
449
|
describe "#verify_ordered_double" do
|
310
450
|
before do
|
311
|
-
@object = Object.new
|
312
451
|
@method_name = :foobar
|
313
|
-
@double_injection =
|
452
|
+
@double_injection = space.double_injection(subject, method_name)
|
314
453
|
end
|
315
454
|
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
@space.register_ordered_double(double)
|
455
|
+
macro "#verify_ordered_double" do
|
456
|
+
it "raises an error when Double is NonTerminal" do
|
457
|
+
double = new_double
|
458
|
+
space.register_ordered_double(double)
|
321
459
|
|
322
|
-
|
323
|
-
|
460
|
+
double.any_number_of_times
|
461
|
+
double.should_not be_terminal
|
324
462
|
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
end
|
463
|
+
lambda do
|
464
|
+
space.verify_ordered_double(double)
|
465
|
+
end.should raise_error(
|
466
|
+
Errors::DoubleOrderError,
|
467
|
+
"Ordered Doubles cannot have a NonTerminal TimesCalledExpectation"
|
468
|
+
)
|
332
469
|
end
|
333
470
|
end
|
334
471
|
|
335
472
|
context "when the passed in double is at the front of the queue" do
|
336
473
|
send "#verify_ordered_double"
|
337
474
|
it "keeps the double when times called is not verified" do
|
338
|
-
double =
|
339
|
-
|
475
|
+
double = new_double
|
476
|
+
space.register_ordered_double(double)
|
340
477
|
|
341
478
|
double.twice
|
342
479
|
double.should be_attempt
|
343
480
|
|
344
|
-
|
345
|
-
|
481
|
+
space.verify_ordered_double(double)
|
482
|
+
space.ordered_doubles.should include(double)
|
346
483
|
end
|
347
484
|
|
348
|
-
|
349
|
-
double
|
350
|
-
|
485
|
+
context "when Double#attempt? is false" do
|
486
|
+
it "removes the double" do
|
487
|
+
double = new_double
|
488
|
+
space.register_ordered_double(double)
|
351
489
|
|
352
|
-
|
353
|
-
|
354
|
-
|
490
|
+
double.with(1).once
|
491
|
+
subject.foobar(1)
|
492
|
+
double.should_not be_attempt
|
355
493
|
|
356
|
-
|
357
|
-
|
494
|
+
space.verify_ordered_double(double)
|
495
|
+
space.ordered_doubles.should_not include(double)
|
496
|
+
end
|
358
497
|
end
|
359
498
|
end
|
360
499
|
|
361
500
|
context "when the passed in double is not at the front of the queue" do
|
362
501
|
send "#verify_ordered_double"
|
363
502
|
it "raises error" do
|
364
|
-
first_double =
|
365
|
-
second_double =
|
503
|
+
first_double = new_double
|
504
|
+
second_double = new_double
|
366
505
|
|
367
506
|
lambda do
|
368
|
-
|
507
|
+
space.verify_ordered_double(second_double)
|
369
508
|
end.should raise_error(
|
370
509
|
Errors::DoubleOrderError,
|
371
510
|
"foobar() called out of order in list\n" <<
|
@@ -374,13 +513,12 @@ module RR
|
|
374
513
|
)
|
375
514
|
end
|
376
515
|
|
377
|
-
def
|
378
|
-
double =
|
379
|
-
|
516
|
+
def new_double
|
517
|
+
double = super.once
|
518
|
+
space.register_ordered_double(double.double)
|
380
519
|
double.double
|
381
520
|
end
|
382
521
|
end
|
383
522
|
end
|
384
523
|
end
|
385
|
-
|
386
524
|
end
|