rr 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES +5 -0
- data/Rakefile +1 -1
- data/examples/high_level_example.rb +6 -4
- data/examples/rr/do_not_allow_creator_example.rb +18 -18
- data/examples/rr/double_dispatching_example.rb +5 -5
- data/examples/rr/double_verify_example.rb +1 -1
- data/examples/rr/errors/rr_error_example.rb +47 -0
- data/examples/rr/expectations/any_argument_expectation_example.rb +2 -2
- data/examples/rr/expectations/anything_argument_equality_expectation_example.rb +4 -4
- data/examples/rr/expectations/argument_equality_expectation_example.rb +12 -12
- data/examples/rr/expectations/boolean_argument_equality_expectation_example.rb +4 -4
- data/examples/rr/expectations/duck_type_argument_equality_expectation_example.rb +4 -4
- data/examples/rr/expectations/is_a_argument_equality_expectation_example.rb +4 -4
- data/examples/rr/expectations/numeric_argument_equality_expectation_example.rb +4 -4
- data/examples/rr/expectations/range_argument_equality_expectation_example.rb +4 -4
- data/examples/rr/expectations/regexp_argument_equality_expectation_example.rb +4 -4
- data/examples/rr/expectations/times_called_expectation_example.rb +6 -6
- data/examples/rr/extensions/double_methods_example.rb +4 -4
- data/examples/rr/mock_creator_example.rb +1 -1
- data/examples/rr/probe_creator_example.rb +1 -1
- data/examples/rr/rspec/rspec_adapter_example.rb +1 -1
- data/examples/rr/rspec/rspec_backtrace_tweaking_example.rb +25 -0
- data/examples/rr/scenario_example.rb +12 -12
- data/examples/rr/space_create_example.rb +6 -6
- data/examples/rr/space_verify_example.rb +1 -1
- data/examples/rr/test_unit/test_unit_backtrace_test.rb +32 -0
- data/examples/rr/test_unit/test_unit_integration_test.rb +1 -1
- data/lib/rr/adapters/rspec.rb +2 -2
- data/lib/rr/adapters/test_unit.rb +1 -2
- data/lib/rr/double.rb +1 -1
- data/lib/rr/errors/argument_equality_error.rb +6 -0
- data/lib/rr/errors/rr_error.rb +19 -0
- data/lib/rr/errors/scenario_not_found_error.rb +6 -0
- data/lib/rr/errors/scenario_order_error.rb +6 -0
- data/lib/rr/errors/times_called_error.rb +6 -0
- data/lib/rr/expectations/argument_equality_expectation.rb +1 -4
- data/lib/rr/expectations/times_called_expectation.rb +2 -5
- data/lib/rr/extensions/double_methods.rb +5 -5
- data/lib/rr/scenario.rb +10 -10
- data/lib/rr/space.rb +3 -1
- data/lib/rr.rb +5 -2
- metadata +10 -4
- data/lib/rr/scenario_not_found_error.rb +0 -4
- data/lib/rr/scenario_order_error.rb +0 -4
data/CHANGES
CHANGED
data/Rakefile
CHANGED
@@ -18,7 +18,7 @@ describe "RR mock:" do
|
|
18
18
|
it "mocks via inline call" do
|
19
19
|
mock(@obj).to_s {"a value"}
|
20
20
|
@obj.to_s.should == "a value"
|
21
|
-
proc {@obj.to_s}.should raise_error(RR::
|
21
|
+
proc {@obj.to_s}.should raise_error(RR::Errors::TimesCalledError)
|
22
22
|
end
|
23
23
|
|
24
24
|
it "allows ordering" do
|
@@ -27,7 +27,7 @@ describe "RR mock:" do
|
|
27
27
|
@obj.to_s.should == "value 1"
|
28
28
|
@obj.to_s.should == "value 2"
|
29
29
|
@obj.to_s.should == "value 2"
|
30
|
-
proc {@obj.to_s}.should raise_error(RR::
|
30
|
+
proc {@obj.to_s}.should raise_error(RR::Errors::TimesCalledError)
|
31
31
|
end
|
32
32
|
|
33
33
|
it "mocks via block" do
|
@@ -56,7 +56,9 @@ describe "RR mock:" do
|
|
56
56
|
"My String",
|
57
57
|
"Tabcola"
|
58
58
|
).should == "value 1"
|
59
|
-
proc
|
59
|
+
proc do
|
60
|
+
@obj.foobar(:failure)
|
61
|
+
end.should raise_error( RR::Errors::ScenarioNotFoundError )
|
60
62
|
end
|
61
63
|
end
|
62
64
|
|
@@ -80,7 +82,7 @@ describe "RR probe:" do
|
|
80
82
|
@obj.to_s(:foo).should == "Original to_s with arg foo"
|
81
83
|
@obj.to_s(:bar).should == "Original to_s with arg bar"
|
82
84
|
@obj.to_s(:bar).should == "Original to_s with arg bar"
|
83
|
-
proc {@obj.to_s(:bar)}.should raise_error(RR::
|
85
|
+
proc {@obj.to_s(:bar)}.should raise_error(RR::Errors::TimesCalledError)
|
84
86
|
end
|
85
87
|
|
86
88
|
it "probes via block" do
|
@@ -35,28 +35,28 @@ describe DoNotAllowCreator, ".new with block" do
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
it "raises
|
39
|
-
proc {@subject.any_args}.should raise_error(
|
38
|
+
it "raises TimesCalledError when any_args is called with no arguments" do
|
39
|
+
proc {@subject.any_args}.should raise_error(Errors::TimesCalledError)
|
40
40
|
end
|
41
41
|
|
42
|
-
it "raises
|
43
|
-
proc {@subject.any_args(1, 2)}.should raise_error(
|
42
|
+
it "raises TimesCalledError when any_args is called with arguments" do
|
43
|
+
proc {@subject.any_args(1, 2)}.should raise_error(Errors::TimesCalledError)
|
44
44
|
end
|
45
45
|
|
46
|
-
it "raises
|
47
|
-
proc {@subject.no_args}.should raise_error(
|
46
|
+
it "raises TimesCalledError when no_args is called with no arguments" do
|
47
|
+
proc {@subject.no_args}.should raise_error(Errors::TimesCalledError)
|
48
48
|
end
|
49
49
|
|
50
|
-
it "does not raise
|
51
|
-
proc {@subject.no_args(1, 2)}.should raise_error(ScenarioNotFoundError)
|
50
|
+
it "does not raise TimesCalledError when no_args is called with arguments" do
|
51
|
+
proc {@subject.no_args(1, 2)}.should raise_error(Errors::ScenarioNotFoundError)
|
52
52
|
end
|
53
53
|
|
54
|
-
it "raises
|
55
|
-
proc {@subject.with_args}.should raise_error(ScenarioNotFoundError)
|
54
|
+
it "raises TimesCalledError when any_args is called with no arguments" do
|
55
|
+
proc {@subject.with_args}.should raise_error(Errors::ScenarioNotFoundError)
|
56
56
|
end
|
57
57
|
|
58
|
-
it "raises
|
59
|
-
proc {@subject.any_args(1, 2)}.should raise_error(
|
58
|
+
it "raises TimesCalledError when any_args is called with arguments" do
|
59
|
+
proc {@subject.any_args(1, 2)}.should raise_error(Errors::TimesCalledError)
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
@@ -70,20 +70,20 @@ describe DoNotAllowCreator, "#method_missing" do
|
|
70
70
|
|
71
71
|
it "sets expectation for method to never be called with any arguments when on arguments passed in" do
|
72
72
|
@creator.foobar
|
73
|
-
proc {@subject.foobar}.should raise_error(
|
74
|
-
proc {@subject.foobar(1, 2)}.should raise_error(
|
73
|
+
proc {@subject.foobar}.should raise_error(Errors::TimesCalledError)
|
74
|
+
proc {@subject.foobar(1, 2)}.should raise_error(Errors::TimesCalledError)
|
75
75
|
end
|
76
76
|
|
77
77
|
it "sets expectation for method to never be called with passed in arguments" do
|
78
78
|
@creator.foobar(1, 2)
|
79
|
-
proc {@subject.foobar}.should raise_error(ScenarioNotFoundError)
|
80
|
-
proc {@subject.foobar(1, 2)}.should raise_error(
|
79
|
+
proc {@subject.foobar}.should raise_error(Errors::ScenarioNotFoundError)
|
80
|
+
proc {@subject.foobar(1, 2)}.should raise_error(Errors::TimesCalledError)
|
81
81
|
end
|
82
82
|
|
83
83
|
it "sets expectation for method to never be called with no arguments when with_no_args is set" do
|
84
84
|
@creator.foobar.with_no_args
|
85
|
-
proc {@subject.foobar}.should raise_error(
|
86
|
-
proc {@subject.foobar(1, 2)}.should raise_error(ScenarioNotFoundError)
|
85
|
+
proc {@subject.foobar}.should raise_error(Errors::TimesCalledError)
|
86
|
+
proc {@subject.foobar(1, 2)}.should raise_error(Errors::ScenarioNotFoundError)
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
@@ -65,7 +65,7 @@ describe Double, " method dispatching where there are scenarios" do
|
|
65
65
|
scenario_2.with(3)
|
66
66
|
|
67
67
|
proc {@object.foobar(:no_matching_args)}.should raise_error(
|
68
|
-
ScenarioNotFoundError,
|
68
|
+
Errors::ScenarioNotFoundError,
|
69
69
|
"No scenario for arguments [:no_matching_args]"
|
70
70
|
)
|
71
71
|
end
|
@@ -103,7 +103,7 @@ describe Double, " method dispatching where there are scenarios with duplicate E
|
|
103
103
|
@object.foobar(:exact_match).should == :return_2
|
104
104
|
end
|
105
105
|
|
106
|
-
it "raises
|
106
|
+
it "raises TimesCalledError when all of the scenarios Times Called expectation is satisfied" do
|
107
107
|
scenario1_with_exact_match = @space.create_scenario(@double)
|
108
108
|
scenario1_with_exact_match.with(:exact_match).returns {:return_1}.once
|
109
109
|
|
@@ -114,7 +114,7 @@ describe Double, " method dispatching where there are scenarios with duplicate E
|
|
114
114
|
@object.foobar(:exact_match)
|
115
115
|
proc do
|
116
116
|
@object.foobar(:exact_match)
|
117
|
-
end.should raise_error(
|
117
|
+
end.should raise_error(Errors::TimesCalledError)
|
118
118
|
end
|
119
119
|
end
|
120
120
|
|
@@ -150,7 +150,7 @@ describe Double, " method dispatching where there are scenarios with duplicate W
|
|
150
150
|
@object.foobar(:anything).should == :return_2
|
151
151
|
end
|
152
152
|
|
153
|
-
it "raises
|
153
|
+
it "raises TimesCalledError when all of the scenarios Times Called expectation is satisfied" do
|
154
154
|
scenario_1 = @space.create_scenario(@double)
|
155
155
|
scenario_1.with_any_args.returns {:return_1}.once
|
156
156
|
|
@@ -161,7 +161,7 @@ describe Double, " method dispatching where there are scenarios with duplicate W
|
|
161
161
|
@object.foobar(:anything)
|
162
162
|
proc do
|
163
163
|
@object.foobar(:anything)
|
164
|
-
end.should raise_error(
|
164
|
+
end.should raise_error(Errors::TimesCalledError)
|
165
165
|
end
|
166
166
|
end
|
167
167
|
end
|
@@ -16,7 +16,7 @@ describe Double, "#verify" do
|
|
16
16
|
@double.register_scenario scenario
|
17
17
|
|
18
18
|
scenario.with(1).once.returns {nil}
|
19
|
-
proc {@double.verify}.should raise_error(
|
19
|
+
proc {@double.verify}.should raise_error(Errors::TimesCalledError)
|
20
20
|
@object.foobar(1)
|
21
21
|
proc {@double.verify}.should_not raise_error
|
22
22
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
dir = File.dirname(__FILE__)
|
2
|
+
require "#{dir}/../../example_helper"
|
3
|
+
|
4
|
+
module RR
|
5
|
+
module Errors
|
6
|
+
describe RRError, "#backtrace" do
|
7
|
+
before do
|
8
|
+
@original_trim_backtrace = RR::Space.trim_backtrace
|
9
|
+
end
|
10
|
+
after do
|
11
|
+
RR::Space.trim_backtrace = @original_trim_backtrace
|
12
|
+
end
|
13
|
+
|
14
|
+
it "does not include the rr library files when trim_backtrace is true" do
|
15
|
+
RR::Space.trim_backtrace = true
|
16
|
+
|
17
|
+
error = nil
|
18
|
+
begin
|
19
|
+
obj = Object.new
|
20
|
+
mock(obj).foobar
|
21
|
+
RR::Space.verify_double(obj, :foobar)
|
22
|
+
rescue RRError=> e
|
23
|
+
error = e
|
24
|
+
end
|
25
|
+
backtrace = error.backtrace.join("\n")
|
26
|
+
|
27
|
+
backtrace.should_not include("lib/rr")
|
28
|
+
end
|
29
|
+
|
30
|
+
it "includes the rr library files when trim_backtrace is false" do
|
31
|
+
RR::Space.trim_backtrace = false
|
32
|
+
|
33
|
+
error = nil
|
34
|
+
begin
|
35
|
+
obj = Object.new
|
36
|
+
mock(obj).foobar
|
37
|
+
RR::Space.verify_double(obj, :foobar)
|
38
|
+
rescue RRError=> e
|
39
|
+
error = e
|
40
|
+
end
|
41
|
+
backtrace = error.backtrace.join("\n")
|
42
|
+
|
43
|
+
backtrace.should include("lib/rr")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -12,8 +12,8 @@ module Expectations
|
|
12
12
|
@expectation.should == AnyArgumentExpectation.new
|
13
13
|
end
|
14
14
|
|
15
|
-
it "returns false when comparing with
|
16
|
-
@expectation.should_not ==
|
15
|
+
it "returns false when comparing with ArgumentEqualityError" do
|
16
|
+
@expectation.should_not == ArgumentEqualityError.new(1)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -3,9 +3,9 @@ require "#{dir}/../../example_helper"
|
|
3
3
|
|
4
4
|
module RR
|
5
5
|
module Expectations
|
6
|
-
describe
|
6
|
+
describe ArgumentEqualityError, "#exact_match? with anything argument" do
|
7
7
|
before do
|
8
|
-
@expectation =
|
8
|
+
@expectation = ArgumentEqualityError.new(anything)
|
9
9
|
end
|
10
10
|
|
11
11
|
it "returns true when passed in an Anything module" do
|
@@ -21,9 +21,9 @@ module Expectations
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
describe
|
24
|
+
describe ArgumentEqualityError, "#wildcard_match? with is_a String argument" do
|
25
25
|
before do
|
26
|
-
@expectation =
|
26
|
+
@expectation = ArgumentEqualityError.new(anything)
|
27
27
|
end
|
28
28
|
|
29
29
|
it "returns true when passed correct number of arguments" do
|
@@ -3,26 +3,26 @@ require "#{dir}/../../example_helper"
|
|
3
3
|
|
4
4
|
module RR
|
5
5
|
module Expectations
|
6
|
-
describe
|
6
|
+
describe ArgumentEqualityError, "==" do
|
7
7
|
before do
|
8
|
-
@expectation =
|
8
|
+
@expectation = ArgumentEqualityError.new(1, 2, 3)
|
9
9
|
end
|
10
10
|
|
11
11
|
it "returns true when passed in expected_arguments are equal" do
|
12
|
-
@expectation.should ==
|
12
|
+
@expectation.should == ArgumentEqualityError.new(1, 2, 3)
|
13
13
|
end
|
14
14
|
|
15
15
|
it "returns false when passed in expected_arguments are not equal" do
|
16
|
-
@expectation.should_not ==
|
17
|
-
@expectation.should_not ==
|
18
|
-
@expectation.should_not ==
|
19
|
-
@expectation.should_not ==
|
16
|
+
@expectation.should_not == ArgumentEqualityError.new(1, 2)
|
17
|
+
@expectation.should_not == ArgumentEqualityError.new(1)
|
18
|
+
@expectation.should_not == ArgumentEqualityError.new(:something)
|
19
|
+
@expectation.should_not == ArgumentEqualityError.new()
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
describe
|
23
|
+
describe ArgumentEqualityError, "#exact_match?" do
|
24
24
|
before do
|
25
|
-
@expectation =
|
25
|
+
@expectation = ArgumentEqualityError.new(1, 2, 3)
|
26
26
|
end
|
27
27
|
|
28
28
|
it "returns true when all arguments exactly match" do
|
@@ -34,16 +34,16 @@ module Expectations
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
describe
|
37
|
+
describe ArgumentEqualityError, "#wildcard_match?" do
|
38
38
|
it "returns false when not exact match" do
|
39
|
-
@expectation =
|
39
|
+
@expectation = ArgumentEqualityError.new(1)
|
40
40
|
@expectation.should_not be_wildcard_match(1, 2, 3)
|
41
41
|
@expectation.should_not be_wildcard_match("whatever")
|
42
42
|
@expectation.should_not be_wildcard_match("whatever", "else")
|
43
43
|
end
|
44
44
|
|
45
45
|
it "returns true when exact match" do
|
46
|
-
@expectation =
|
46
|
+
@expectation = ArgumentEqualityError.new(1, 2)
|
47
47
|
@expectation.should be_wildcard_match(1, 2)
|
48
48
|
@expectation.should_not be_wildcard_match(1)
|
49
49
|
@expectation.should_not be_wildcard_match("whatever", "else")
|
@@ -3,9 +3,9 @@ require "#{dir}/../../example_helper"
|
|
3
3
|
|
4
4
|
module RR
|
5
5
|
module Expectations
|
6
|
-
describe
|
6
|
+
describe ArgumentEqualityError, "#exact_match? with is_a argument" do
|
7
7
|
before do
|
8
|
-
@expectation =
|
8
|
+
@expectation = ArgumentEqualityError.new(boolean)
|
9
9
|
end
|
10
10
|
|
11
11
|
it "returns true when passed in an IsA module" do
|
@@ -22,9 +22,9 @@ module Expectations
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
describe
|
25
|
+
describe ArgumentEqualityError, "#wildcard_match? with is_a Boolean argument" do
|
26
26
|
before do
|
27
|
-
@expectation =
|
27
|
+
@expectation = ArgumentEqualityError.new(boolean)
|
28
28
|
end
|
29
29
|
|
30
30
|
it "returns true when passed a Boolean" do
|
@@ -3,9 +3,9 @@ require "#{dir}/../../example_helper"
|
|
3
3
|
|
4
4
|
module RR
|
5
5
|
module Expectations
|
6
|
-
describe
|
6
|
+
describe ArgumentEqualityError, "#exact_match? with duck_type argument" do
|
7
7
|
before do
|
8
|
-
@expectation =
|
8
|
+
@expectation = ArgumentEqualityError.new(duck_type(:to_s))
|
9
9
|
end
|
10
10
|
|
11
11
|
it "returns true when passed in an DuckType matcher with the same argument list" do
|
@@ -26,7 +26,7 @@ module Expectations
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
describe
|
29
|
+
describe ArgumentEqualityError, "#wildcard_match? with DuckType argument" do
|
30
30
|
before do
|
31
31
|
@matching_object = Object.new
|
32
32
|
def @matching_object.quack
|
@@ -40,7 +40,7 @@ module Expectations
|
|
40
40
|
|
41
41
|
@not_match_object = Object.new
|
42
42
|
|
43
|
-
@expectation =
|
43
|
+
@expectation = ArgumentEqualityError.new(duck_type(:quack, :waddle))
|
44
44
|
end
|
45
45
|
|
46
46
|
it "returns true when object matches all required methods" do
|
@@ -3,9 +3,9 @@ require "#{dir}/../../example_helper"
|
|
3
3
|
|
4
4
|
module RR
|
5
5
|
module Expectations
|
6
|
-
describe
|
6
|
+
describe ArgumentEqualityError, "#exact_match? with is_a argument" do
|
7
7
|
before do
|
8
|
-
@expectation =
|
8
|
+
@expectation = ArgumentEqualityError.new(is_a(String))
|
9
9
|
end
|
10
10
|
|
11
11
|
it "returns true when passed in an IsA module" do
|
@@ -25,9 +25,9 @@ module Expectations
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
describe
|
28
|
+
describe ArgumentEqualityError, "#wildcard_match? with is_a String argument" do
|
29
29
|
before do
|
30
|
-
@expectation =
|
30
|
+
@expectation = ArgumentEqualityError.new(is_a(String))
|
31
31
|
end
|
32
32
|
|
33
33
|
it "returns true when passed a String" do
|
@@ -3,9 +3,9 @@ require "#{dir}/../../example_helper"
|
|
3
3
|
|
4
4
|
module RR
|
5
5
|
module Expectations
|
6
|
-
describe
|
6
|
+
describe ArgumentEqualityError, "#exact_match? with is_a argument" do
|
7
7
|
before do
|
8
|
-
@expectation =
|
8
|
+
@expectation = ArgumentEqualityError.new(numeric)
|
9
9
|
end
|
10
10
|
|
11
11
|
it "returns true when passed in an IsA module" do
|
@@ -21,9 +21,9 @@ module Expectations
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
describe
|
24
|
+
describe ArgumentEqualityError, "#wildcard_match? with is_a Numeric argument" do
|
25
25
|
before do
|
26
|
-
@expectation =
|
26
|
+
@expectation = ArgumentEqualityError.new(numeric)
|
27
27
|
end
|
28
28
|
|
29
29
|
it "returns true when passed a Numeric" do
|
@@ -3,9 +3,9 @@ require "#{dir}/../../example_helper"
|
|
3
3
|
|
4
4
|
module RR
|
5
5
|
module Expectations
|
6
|
-
describe
|
6
|
+
describe ArgumentEqualityError, "#exact_match? with range argument" do
|
7
7
|
before do
|
8
|
-
@expectation =
|
8
|
+
@expectation = ArgumentEqualityError.new(2..5)
|
9
9
|
end
|
10
10
|
|
11
11
|
it "returns true when passed in an Range matcher with the same argument list" do
|
@@ -26,9 +26,9 @@ module Expectations
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
describe
|
29
|
+
describe ArgumentEqualityError, "#wildcard_match? with Range argument" do
|
30
30
|
before do
|
31
|
-
@expectation =
|
31
|
+
@expectation = ArgumentEqualityError.new(2..6)
|
32
32
|
end
|
33
33
|
|
34
34
|
it "returns true when string matches the range" do
|
@@ -3,9 +3,9 @@ require "#{dir}/../../example_helper"
|
|
3
3
|
|
4
4
|
module RR
|
5
5
|
module Expectations
|
6
|
-
describe
|
6
|
+
describe ArgumentEqualityError, "#exact_match? with regexp argument" do
|
7
7
|
before do
|
8
|
-
@expectation =
|
8
|
+
@expectation = ArgumentEqualityError.new(/abc/)
|
9
9
|
end
|
10
10
|
|
11
11
|
it "returns true when passed in an Regexp matcher with the same argument list" do
|
@@ -26,7 +26,7 @@ module Expectations
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
describe
|
29
|
+
describe ArgumentEqualityError, "#wildcard_match? with Regexp argument" do
|
30
30
|
before do
|
31
31
|
@matching_object = Object.new
|
32
32
|
def @matching_object.quack
|
@@ -40,7 +40,7 @@ module Expectations
|
|
40
40
|
|
41
41
|
@not_match_object = Object.new
|
42
42
|
|
43
|
-
@expectation =
|
43
|
+
@expectation = ArgumentEqualityError.new(/abc/)
|
44
44
|
end
|
45
45
|
|
46
46
|
it "returns true when string matches the regexp" do
|
@@ -14,7 +14,7 @@ describe TimesCalledExpectation, :shared => true do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def raises_expectation_error(&block)
|
17
|
-
proc {block.call}.should raise_error(
|
17
|
+
proc {block.call}.should raise_error(Errors::TimesCalledError)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -76,7 +76,7 @@ describe TimesCalledExpectation, "#verify! when passed an Integer (2)" do
|
|
76
76
|
|
77
77
|
it "fails after verify_input called 1 time" do
|
78
78
|
@expectation.verify_input
|
79
|
-
proc {@expectation.verify!}.should raise_error(
|
79
|
+
proc {@expectation.verify!}.should raise_error(Errors::TimesCalledError)
|
80
80
|
end
|
81
81
|
|
82
82
|
it "can't be called when verify_input is called 3 times" do
|
@@ -84,7 +84,7 @@ describe TimesCalledExpectation, "#verify! when passed an Integer (2)" do
|
|
84
84
|
@expectation.verify_input
|
85
85
|
proc do
|
86
86
|
@expectation.verify_input
|
87
|
-
end.should raise_error(
|
87
|
+
end.should raise_error(Errors::TimesCalledError)
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
@@ -111,7 +111,7 @@ describe TimesCalledExpectation, "#verify! when passed a Range (1..2)" do
|
|
111
111
|
@expectation.verify_input
|
112
112
|
proc do
|
113
113
|
@expectation.verify_input
|
114
|
-
end.should raise_error(
|
114
|
+
end.should raise_error(Errors::TimesCalledError)
|
115
115
|
end
|
116
116
|
end
|
117
117
|
|
@@ -130,14 +130,14 @@ describe TimesCalledExpectation, "#verify! when passed a block (== 2 times)" do
|
|
130
130
|
|
131
131
|
it "fails after verify_input called 1 time" do
|
132
132
|
@expectation.verify_input
|
133
|
-
proc {@expectation.verify!}.should raise_error(
|
133
|
+
proc {@expectation.verify!}.should raise_error(Errors::TimesCalledError)
|
134
134
|
end
|
135
135
|
|
136
136
|
it "fails after verify_input called 3 times" do
|
137
137
|
@expectation.verify_input
|
138
138
|
@expectation.verify_input
|
139
139
|
@expectation.verify_input
|
140
|
-
proc {@expectation.verify!}.should raise_error(
|
140
|
+
proc {@expectation.verify!}.should raise_error(Errors::TimesCalledError)
|
141
141
|
end
|
142
142
|
end
|
143
143
|
|
@@ -26,7 +26,7 @@ module Extensions
|
|
26
26
|
|
27
27
|
scenario = creator.foobar(1, 2) {:baz}
|
28
28
|
scenario.times_called_expectation.times.should == 1
|
29
|
-
scenario.argument_expectation.class.should == RR::Expectations::
|
29
|
+
scenario.argument_expectation.class.should == RR::Expectations::ArgumentEqualityError
|
30
30
|
scenario.argument_expectation.expected_arguments.should == [1, 2]
|
31
31
|
|
32
32
|
@subject.foobar(1, 2).should == :baz
|
@@ -56,7 +56,7 @@ module Extensions
|
|
56
56
|
|
57
57
|
scenario = creator.foobar(1, 2) {:baz}
|
58
58
|
scenario.times_called_expectation.should == nil
|
59
|
-
scenario.argument_expectation.class.should == RR::Expectations::
|
59
|
+
scenario.argument_expectation.class.should == RR::Expectations::ArgumentEqualityError
|
60
60
|
@subject.foobar(1, 2).should == :baz
|
61
61
|
end
|
62
62
|
end
|
@@ -84,7 +84,7 @@ module Extensions
|
|
84
84
|
|
85
85
|
scenario = creator.foobar(1, 2)
|
86
86
|
scenario.times_called_expectation.times.should == 1
|
87
|
-
scenario.argument_expectation.class.should == RR::Expectations::
|
87
|
+
scenario.argument_expectation.class.should == RR::Expectations::ArgumentEqualityError
|
88
88
|
scenario.argument_expectation.expected_arguments.should == [1, 2]
|
89
89
|
|
90
90
|
@subject.foobar(1, 2).should == :original_value
|
@@ -122,7 +122,7 @@ module Extensions
|
|
122
122
|
|
123
123
|
scenario = creator.foobar(1, 2)
|
124
124
|
scenario.times_called_expectation.times.should == 0
|
125
|
-
scenario.argument_expectation.class.should == RR::Expectations::
|
125
|
+
scenario.argument_expectation.class.should == RR::Expectations::ArgumentEqualityError
|
126
126
|
scenario.argument_expectation.expected_arguments.should == [1, 2]
|
127
127
|
end
|
128
128
|
end
|
@@ -58,7 +58,7 @@ describe MockCreator, "#method_missing" do
|
|
58
58
|
|
59
59
|
@subject.foobar(1, 2).should == :baz
|
60
60
|
@subject.foobar(1, 2).should == :baz
|
61
|
-
proc {@subject.foobar(1, 2)}.should raise_error(
|
61
|
+
proc {@subject.foobar(1, 2)}.should raise_error(Errors::TimesCalledError)
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
@@ -76,7 +76,7 @@ describe ProbeCreator, "#method_missing" do
|
|
76
76
|
@creator.foobar(1, 2).twice
|
77
77
|
@subject.foobar(1, 2).should == :baz
|
78
78
|
@subject.foobar(1, 2).should == :baz
|
79
|
-
proc {@subject.foobar(1, 2)}.should raise_error(
|
79
|
+
proc {@subject.foobar(1, 2)}.should raise_error(Errors::TimesCalledError)
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
@@ -0,0 +1,25 @@
|
|
1
|
+
dir = File.dirname(__FILE__)
|
2
|
+
require "#{dir}/../../example_helper"
|
3
|
+
|
4
|
+
describe RR, " backtrace tweaking" do
|
5
|
+
it "hides rr library from the backtrace by default" do
|
6
|
+
output = StringIO.new("")
|
7
|
+
backtrace_tweaker = ::Spec::Runner::QuietBacktraceTweaker.new
|
8
|
+
formatter = ::Spec::Runner::Formatter::BaseTextFormatter.new(output)
|
9
|
+
reporter = ::Spec::Runner::Reporter.new([formatter], backtrace_tweaker)
|
10
|
+
|
11
|
+
behaviour = ::Spec::DSL::Behaviour.new("example") {}
|
12
|
+
subject = @subject
|
13
|
+
behaviour.it("hides RR framework in backtrace") do
|
14
|
+
mock(subject).foobar()
|
15
|
+
RR::Space::instance.verify_double(subject, :foobar)
|
16
|
+
end
|
17
|
+
|
18
|
+
reporter.add_behaviour(behaviour)
|
19
|
+
|
20
|
+
behaviour.run(reporter)
|
21
|
+
reporter.dump
|
22
|
+
|
23
|
+
output.string.should_not include("lib/rr")
|
24
|
+
end
|
25
|
+
end
|
@@ -15,7 +15,7 @@ end
|
|
15
15
|
describe Scenario, "#with" do
|
16
16
|
it_should_behave_like "RR::Scenario"
|
17
17
|
|
18
|
-
it "sets an
|
18
|
+
it "sets an ArgumentEqualityError" do
|
19
19
|
@scenario.with(1).should === @scenario
|
20
20
|
@scenario.should be_exact_match(1)
|
21
21
|
@scenario.should_not be_exact_match(2)
|
@@ -59,8 +59,8 @@ describe Scenario, "#with_no_args" do
|
|
59
59
|
@scenario.with_no_args.should === @scenario
|
60
60
|
end
|
61
61
|
|
62
|
-
it "sets an
|
63
|
-
@scenario.argument_expectation.should == Expectations::
|
62
|
+
it "sets an ArgumentEqualityError with no arguments" do
|
63
|
+
@scenario.argument_expectation.should == Expectations::ArgumentEqualityError.new()
|
64
64
|
end
|
65
65
|
|
66
66
|
it "sets return value when block passed in" do
|
@@ -77,12 +77,12 @@ describe Scenario, "#never" do
|
|
77
77
|
|
78
78
|
it "sets up a Times Called Expectation with 0" do
|
79
79
|
@scenario.never
|
80
|
-
proc {@scenario.call}.should raise_error(
|
80
|
+
proc {@scenario.call}.should raise_error(Errors::TimesCalledError)
|
81
81
|
end
|
82
82
|
|
83
83
|
it "sets return value when block passed in" do
|
84
84
|
@scenario.with_any_args.never
|
85
|
-
proc {@scenario.call}.should raise_error(
|
85
|
+
proc {@scenario.call}.should raise_error(Errors::TimesCalledError)
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
@@ -92,7 +92,7 @@ describe Scenario, "#once" do
|
|
92
92
|
it "sets up a Times Called Expectation with 1" do
|
93
93
|
@scenario.once.should === @scenario
|
94
94
|
@scenario.call
|
95
|
-
proc {@scenario.call}.should raise_error(
|
95
|
+
proc {@scenario.call}.should raise_error(Errors::TimesCalledError)
|
96
96
|
end
|
97
97
|
|
98
98
|
it "sets return value when block passed in" do
|
@@ -108,7 +108,7 @@ describe Scenario, "#twice" do
|
|
108
108
|
@scenario.twice.should === @scenario
|
109
109
|
@scenario.call
|
110
110
|
@scenario.call
|
111
|
-
proc {@scenario.call}.should raise_error(
|
111
|
+
proc {@scenario.call}.should raise_error(Errors::TimesCalledError)
|
112
112
|
end
|
113
113
|
|
114
114
|
it "sets return value when block passed in" do
|
@@ -125,7 +125,7 @@ describe Scenario, "#times" do
|
|
125
125
|
@scenario.call
|
126
126
|
@scenario.call
|
127
127
|
@scenario.call
|
128
|
-
proc {@scenario.call}.should raise_error(
|
128
|
+
proc {@scenario.call}.should raise_error(Errors::TimesCalledError)
|
129
129
|
end
|
130
130
|
|
131
131
|
it "sets return value when block passed in" do
|
@@ -219,7 +219,7 @@ describe Scenario, "#call implemented by a proc" do
|
|
219
219
|
|
220
220
|
@scenario.call(:foobar)
|
221
221
|
@scenario.call(:foobar)
|
222
|
-
proc {@scenario.call(:foobar)}.should raise_error(
|
222
|
+
proc {@scenario.call(:foobar)}.should raise_error(Errors::TimesCalledError)
|
223
223
|
end
|
224
224
|
|
225
225
|
it "raises ScenarioOrderError when ordered and called out of order" do
|
@@ -231,7 +231,7 @@ describe Scenario, "#call implemented by a proc" do
|
|
231
231
|
|
232
232
|
proc do
|
233
233
|
@object.foobar(2)
|
234
|
-
end.should raise_error(::
|
234
|
+
end.should raise_error(Errors::ScenarioOrderError)
|
235
235
|
end
|
236
236
|
|
237
237
|
it "dispatches to Space#verify_ordered_scenario when ordered" do
|
@@ -380,9 +380,9 @@ describe Scenario, "#verify" do
|
|
380
380
|
it "verifies that times called expectation was met" do
|
381
381
|
@scenario.twice.returns {:return_value}
|
382
382
|
|
383
|
-
proc {@scenario.verify}.should raise_error(
|
383
|
+
proc {@scenario.verify}.should raise_error(Errors::TimesCalledError)
|
384
384
|
@scenario.call
|
385
|
-
proc {@scenario.verify}.should raise_error(
|
385
|
+
proc {@scenario.verify}.should raise_error(Errors::TimesCalledError)
|
386
386
|
@scenario.call
|
387
387
|
|
388
388
|
proc {@scenario.verify}.should_not raise_error
|
@@ -14,7 +14,7 @@ describe Space, "#create_mock_creator" do
|
|
14
14
|
creator = @space.create_mock_creator(@object)
|
15
15
|
creator.foobar(1) {:baz}
|
16
16
|
@object.foobar(1).should == :baz
|
17
|
-
proc {@object.foobar(1)}.should raise_error(
|
17
|
+
proc {@object.foobar(1)}.should raise_error(Errors::TimesCalledError)
|
18
18
|
end
|
19
19
|
|
20
20
|
it "uses block definition when passed a block" do
|
@@ -22,7 +22,7 @@ describe Space, "#create_mock_creator" do
|
|
22
22
|
c.foobar(1) {:baz}
|
23
23
|
end
|
24
24
|
@object.foobar(1).should == :baz
|
25
|
-
proc {@object.foobar(1)}.should raise_error(
|
25
|
+
proc {@object.foobar(1)}.should raise_error(Errors::TimesCalledError)
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
@@ -70,7 +70,7 @@ describe Space, "#create_probe_creator" do
|
|
70
70
|
creator = @space.create_probe_creator(@object)
|
71
71
|
creator.foobar(1)
|
72
72
|
@object.foobar(1).should == :original_foobar
|
73
|
-
proc {@object.foobar(1)}.should raise_error(
|
73
|
+
proc {@object.foobar(1)}.should raise_error(Errors::TimesCalledError)
|
74
74
|
end
|
75
75
|
|
76
76
|
it "uses block definition when passed a block" do
|
@@ -78,7 +78,7 @@ describe Space, "#create_probe_creator" do
|
|
78
78
|
c.foobar(1)
|
79
79
|
end
|
80
80
|
@object.foobar(1).should == :original_foobar
|
81
|
-
proc {@object.foobar(1)}.should raise_error(
|
81
|
+
proc {@object.foobar(1)}.should raise_error(Errors::TimesCalledError)
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
@@ -93,14 +93,14 @@ describe Space, "#create_do_not_allow_creator" do
|
|
93
93
|
it "creates a MockCreator" do
|
94
94
|
creator = @space.create_do_not_allow_creator(@object)
|
95
95
|
creator.foobar(1)
|
96
|
-
proc {@object.foobar(1)}.should raise_error(
|
96
|
+
proc {@object.foobar(1)}.should raise_error(Errors::TimesCalledError)
|
97
97
|
end
|
98
98
|
|
99
99
|
it "uses block definition when passed a block" do
|
100
100
|
creator = @space.create_do_not_allow_creator(@object) do |c|
|
101
101
|
c.foobar(1)
|
102
102
|
end
|
103
|
-
proc {@object.foobar(1)}.should raise_error(
|
103
|
+
proc {@object.foobar(1)}.should raise_error(Errors::TimesCalledError)
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
@@ -140,7 +140,7 @@ describe Space, "#verify_ordered_scenario where the passed in scenario is not at
|
|
140
140
|
|
141
141
|
proc do
|
142
142
|
@space.verify_ordered_scenario(second_scenario)
|
143
|
-
end.should raise_error(
|
143
|
+
end.should raise_error(Errors::ScenarioOrderError)
|
144
144
|
end
|
145
145
|
end
|
146
146
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
dir = File.dirname(__FILE__)
|
2
|
+
require "#{dir}/test_helper"
|
3
|
+
|
4
|
+
class TestUnitBacktraceTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
super
|
7
|
+
@subject = Object.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def teardown
|
11
|
+
super
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_backtrace_tweaking
|
15
|
+
old_result = @_result
|
16
|
+
result = Test::Unit::TestResult.new
|
17
|
+
|
18
|
+
error_display = nil
|
19
|
+
result.add_listener(Test::Unit::TestResult::FAULT) do |f|
|
20
|
+
error_display = f.long_display
|
21
|
+
end
|
22
|
+
test_case = self.class.new(:backtrace_tweaking)
|
23
|
+
test_case.run(result) {}
|
24
|
+
|
25
|
+
assert !error_display.include?("lib/rr")
|
26
|
+
end
|
27
|
+
|
28
|
+
def backtrace_tweaking
|
29
|
+
mock(@subject).foobar
|
30
|
+
RR::Space::instance.verify_double(@subject, :foobar)
|
31
|
+
end
|
32
|
+
end
|
@@ -32,7 +32,7 @@ class TestUnitIntegrationTest < Test::Unit::TestCase
|
|
32
32
|
|
33
33
|
def test_times_called_verification
|
34
34
|
mock(@subject).foobar(1, 2) {:baz}
|
35
|
-
assert_raise RR::
|
35
|
+
assert_raise RR::Errors::TimesCalledError do
|
36
36
|
teardown
|
37
37
|
end
|
38
38
|
end
|
data/lib/rr/adapters/rspec.rb
CHANGED
data/lib/rr/double.rb
CHANGED
@@ -77,7 +77,7 @@ module RR
|
|
77
77
|
end
|
78
78
|
end
|
79
79
|
matching_scenarios.first.call(*args) unless matching_scenarios.empty?
|
80
|
-
raise ScenarioNotFoundError, "No scenario for arguments #{args.inspect}"
|
80
|
+
raise Errors::ScenarioNotFoundError, "No scenario for arguments #{args.inspect}"
|
81
81
|
end
|
82
82
|
|
83
83
|
def placeholder_name
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module RR
|
2
|
+
module Errors
|
3
|
+
BACKTRACE_IDENTIFIER = /lib\/rr/
|
4
|
+
|
5
|
+
class RRError < RuntimeError
|
6
|
+
def backtrace
|
7
|
+
original_backtrace = super
|
8
|
+
return original_backtrace unless RR::Space.trim_backtrace
|
9
|
+
|
10
|
+
return original_backtrace unless original_backtrace.respond_to?(:each)
|
11
|
+
new_backtrace = []
|
12
|
+
original_backtrace.each do |line|
|
13
|
+
new_backtrace << line unless line =~ BACKTRACE_IDENTIFIER
|
14
|
+
end
|
15
|
+
new_backtrace
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,8 +1,5 @@
|
|
1
1
|
module RR
|
2
2
|
module Expectations
|
3
|
-
class TimesCalledExpectationError < RuntimeError
|
4
|
-
end
|
5
|
-
|
6
3
|
class TimesCalledExpectation
|
7
4
|
attr_reader :times, :times_called
|
8
5
|
|
@@ -27,12 +24,12 @@ module RR
|
|
27
24
|
end
|
28
25
|
|
29
26
|
def verify!
|
30
|
-
raise
|
27
|
+
raise Errors::TimesCalledError unless verify
|
31
28
|
end
|
32
29
|
|
33
30
|
protected
|
34
31
|
def verify_input_error
|
35
|
-
raise
|
32
|
+
raise Errors::TimesCalledError, "Called #{@times_called.inspect} times. Expected #{@times.inspect}"
|
36
33
|
end
|
37
34
|
end
|
38
35
|
end
|
@@ -30,7 +30,7 @@ module Extensions
|
|
30
30
|
end
|
31
31
|
alias_method :dont_allow, :do_not_allow
|
32
32
|
|
33
|
-
# Sets up an Anything wildcard
|
33
|
+
# Sets up an Anything wildcard ArgumentEqualityError
|
34
34
|
# that succeeds when passed any argument.
|
35
35
|
# mock(object).method_name(anything) {return_value}
|
36
36
|
# object.method_name("an arbitrary value") # passes
|
@@ -38,7 +38,7 @@ module Extensions
|
|
38
38
|
RR::Expectations::WildcardMatchers::Anything.new
|
39
39
|
end
|
40
40
|
|
41
|
-
# Sets up an IsA wildcard
|
41
|
+
# Sets up an IsA wildcard ArgumentEqualityError
|
42
42
|
# that succeeds when passed an argument of a certain type.
|
43
43
|
# mock(object).method_name(is_a(String)) {return_value}
|
44
44
|
# object.method_name("A String") # passes
|
@@ -46,7 +46,7 @@ module Extensions
|
|
46
46
|
RR::Expectations::WildcardMatchers::IsA.new(klass)
|
47
47
|
end
|
48
48
|
|
49
|
-
# Sets up an Numeric wildcard
|
49
|
+
# Sets up an Numeric wildcard ArgumentEqualityError
|
50
50
|
# that succeeds when passed an argument that is ::Numeric.
|
51
51
|
# mock(object).method_name(numeric) {return_value}
|
52
52
|
# object.method_name(99) # passes
|
@@ -54,7 +54,7 @@ module Extensions
|
|
54
54
|
RR::Expectations::WildcardMatchers::Numeric.new
|
55
55
|
end
|
56
56
|
|
57
|
-
# Sets up an Boolean wildcard
|
57
|
+
# Sets up an Boolean wildcard ArgumentEqualityError
|
58
58
|
# that succeeds when passed an argument that is a ::Boolean.
|
59
59
|
# mock(object).method_name(boolean) {return_value}
|
60
60
|
# object.method_name(false) # passes
|
@@ -62,7 +62,7 @@ module Extensions
|
|
62
62
|
RR::Expectations::WildcardMatchers::Boolean.new
|
63
63
|
end
|
64
64
|
|
65
|
-
# Sets up a DuckType wildcard
|
65
|
+
# Sets up a DuckType wildcard ArgumentEqualityError
|
66
66
|
# that succeeds when passed the argument implements the methods.
|
67
67
|
# arg = Object.new
|
68
68
|
# def arg.foo; end
|
data/lib/rr/scenario.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module RR
|
2
2
|
# RR::Scenario is the use case for a method call.
|
3
|
-
# It has the
|
3
|
+
# It has the ArgumentEqualityError, TimesCalledExpectation,
|
4
4
|
# and the implementation.
|
5
5
|
class Scenario
|
6
6
|
attr_reader :times_called, :argument_expectation, :times_called_expectation
|
@@ -13,19 +13,19 @@ module RR
|
|
13
13
|
@times_called = 0
|
14
14
|
end
|
15
15
|
|
16
|
-
# Scenario#with creates an
|
16
|
+
# Scenario#with creates an ArgumentEqualityError for the
|
17
17
|
# Scenario. it takes a list of expected arguments.
|
18
18
|
#
|
19
19
|
# Passing in a block sets the return value.
|
20
20
|
#
|
21
21
|
# mock(subject).method_name.with(1, 2) {:return_value}
|
22
22
|
def with(*args, &returns)
|
23
|
-
@argument_expectation = Expectations::
|
23
|
+
@argument_expectation = Expectations::ArgumentEqualityError.new(*args)
|
24
24
|
returns(&returns) if returns
|
25
25
|
self
|
26
26
|
end
|
27
27
|
|
28
|
-
# Scenario#with_any_args creates an
|
28
|
+
# Scenario#with_any_args creates an AnyArgumentEqualityError
|
29
29
|
# for the Scenario.
|
30
30
|
#
|
31
31
|
# Passing in a block sets the return value.
|
@@ -37,14 +37,14 @@ module RR
|
|
37
37
|
self
|
38
38
|
end
|
39
39
|
|
40
|
-
# Scenario#with_no_args creates an
|
40
|
+
# Scenario#with_no_args creates an ArgumentEqualityError with
|
41
41
|
# no arguments for the Scenario.
|
42
42
|
#
|
43
43
|
# Passing in a block sets the return value.
|
44
44
|
#
|
45
45
|
# mock(subject).method_name.with_no_args {:return_value}
|
46
46
|
def with_no_args(&returns)
|
47
|
-
@argument_expectation = Expectations::
|
47
|
+
@argument_expectation = Expectations::ArgumentEqualityError.new()
|
48
48
|
returns(&returns) if returns
|
49
49
|
self
|
50
50
|
end
|
@@ -136,7 +136,7 @@ module RR
|
|
136
136
|
# Scenario#call calls the Scenario's implementation. The return
|
137
137
|
# value of the implementation is returned.
|
138
138
|
#
|
139
|
-
# A
|
139
|
+
# A TimesCalledError is raised when the times called
|
140
140
|
# exceeds the expected TimesCalledExpectation.
|
141
141
|
def call(*args, &block)
|
142
142
|
@times_called_expectation.verify_input if @times_called_expectation
|
@@ -152,14 +152,14 @@ module RR
|
|
152
152
|
end
|
153
153
|
|
154
154
|
# Scenario#exact_match? returns true when the passed in arguments
|
155
|
-
# exactly match the
|
155
|
+
# exactly match the ArgumentEqualityError arguments.
|
156
156
|
def exact_match?(*arguments)
|
157
157
|
return false unless @argument_expectation
|
158
158
|
@argument_expectation.exact_match?(*arguments)
|
159
159
|
end
|
160
160
|
|
161
161
|
# Scenario#wildcard_match? returns true when the passed in arguments
|
162
|
-
# wildcard match the
|
162
|
+
# wildcard match the ArgumentEqualityError arguments.
|
163
163
|
def wildcard_match?(*arguments)
|
164
164
|
return false unless @argument_expectation
|
165
165
|
@argument_expectation.wildcard_match?(*arguments)
|
@@ -173,7 +173,7 @@ module RR
|
|
173
173
|
end
|
174
174
|
|
175
175
|
# Scenario#verify verifies the the TimesCalledExpectation
|
176
|
-
# is satisfied for this scenario. A
|
176
|
+
# is satisfied for this scenario. A TimesCalledError
|
177
177
|
# is raised if the TimesCalledExpectation is not met.
|
178
178
|
def verify
|
179
179
|
return true unless @times_called_expectation
|
data/lib/rr/space.rb
CHANGED
@@ -16,9 +16,11 @@ module RR
|
|
16
16
|
end
|
17
17
|
|
18
18
|
attr_reader :doubles, :ordered_scenarios
|
19
|
+
attr_accessor :trim_backtrace
|
19
20
|
def initialize
|
20
21
|
@doubles = Hash.new {|hash, subject_object| hash[subject_object] = Hash.new}
|
21
22
|
@ordered_scenarios = []
|
23
|
+
@trim_backtrace = false
|
22
24
|
end
|
23
25
|
|
24
26
|
# Creates a MockCreator.
|
@@ -70,7 +72,7 @@ module RR
|
|
70
72
|
# Verifies that the passed in ordered Scenario is being called
|
71
73
|
# in the correct position.
|
72
74
|
def verify_ordered_scenario(scenario)
|
73
|
-
raise ::
|
75
|
+
raise Errors::ScenarioOrderError unless @ordered_scenarios.first == scenario
|
74
76
|
@ordered_scenarios.shift if scenario.times_called_verified?
|
75
77
|
scenario
|
76
78
|
end
|
data/lib/rr.rb
CHANGED
@@ -10,8 +10,11 @@ require "rr/do_not_allow_creator"
|
|
10
10
|
require "rr/scenario"
|
11
11
|
require "rr/space"
|
12
12
|
|
13
|
-
require "rr/
|
14
|
-
require "rr/
|
13
|
+
require "rr/errors/rr_error"
|
14
|
+
require "rr/errors/scenario_not_found_error"
|
15
|
+
require "rr/errors/scenario_order_error"
|
16
|
+
require "rr/errors/argument_equality_error"
|
17
|
+
require "rr/errors/times_called_error"
|
15
18
|
|
16
19
|
require "rr/expectations/argument_equality_expectation"
|
17
20
|
require "rr/expectations/any_argument_expectation"
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.3
|
|
3
3
|
specification_version: 1
|
4
4
|
name: rr
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.1.
|
7
|
-
date: 2007-07-
|
6
|
+
version: 0.1.1
|
7
|
+
date: 2007-07-08 00:00:00 -07:00
|
8
8
|
summary: RR (Double Ruby) is a double framework that features a rich selection of double techniques and a terse syntax. http://xunitpatterns.com/Test%20Double.html
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -34,8 +34,6 @@ files:
|
|
34
34
|
- README
|
35
35
|
- lib/rr.rb
|
36
36
|
- lib/rr/scenario.rb
|
37
|
-
- lib/rr/scenario_not_found_error.rb
|
38
|
-
- lib/rr/scenario_order_error.rb
|
39
37
|
- lib/rr/stub_creator.rb
|
40
38
|
- lib/rr/space.rb
|
41
39
|
- lib/rr/double.rb
|
@@ -52,6 +50,11 @@ files:
|
|
52
50
|
- lib/rr/expectations/wildcard_matchers/numeric.rb
|
53
51
|
- lib/rr/expectations/wildcard_matchers/is_a.rb
|
54
52
|
- lib/rr/expectations/wildcard_matchers/anything.rb
|
53
|
+
- lib/rr/errors/scenario_not_found_error.rb
|
54
|
+
- lib/rr/errors/argument_equality_error.rb
|
55
|
+
- lib/rr/errors/scenario_order_error.rb
|
56
|
+
- lib/rr/errors/rr_error.rb
|
57
|
+
- lib/rr/errors/times_called_error.rb
|
55
58
|
- lib/rr/adapters/test_unit.rb
|
56
59
|
- lib/rr/adapters/rspec.rb
|
57
60
|
- lib/rr/extensions/double_methods.rb
|
@@ -78,6 +81,7 @@ files:
|
|
78
81
|
- examples/rr/double_dispatching_example.rb
|
79
82
|
- examples/rr/space_register_example.rb
|
80
83
|
- examples/rr/double_verify_example.rb
|
84
|
+
- examples/rr/rspec/rspec_backtrace_tweaking_example.rb
|
81
85
|
- examples/rr/rspec/rspec_adapter_example.rb
|
82
86
|
- examples/rr/rspec/rspec_usage_example.rb
|
83
87
|
- examples/rr/expectations/is_a_argument_equality_expectation_example.rb
|
@@ -90,6 +94,8 @@ files:
|
|
90
94
|
- examples/rr/expectations/range_argument_equality_expectation_example.rb
|
91
95
|
- examples/rr/expectations/argument_equality_expectation_example.rb
|
92
96
|
- examples/rr/expectations/anything_argument_equality_expectation_example.rb
|
97
|
+
- examples/rr/errors/rr_error_example.rb
|
98
|
+
- examples/rr/test_unit/test_unit_backtrace_test.rb
|
93
99
|
- examples/rr/test_unit/test_helper.rb
|
94
100
|
- examples/rr/test_unit/test_unit_integration_test.rb
|
95
101
|
- examples/rr/extensions/double_methods_example.rb
|