rr 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +5 -0
- data/Rakefile +1 -1
- data/examples/rr/double_dispatching_example.rb +4 -1
- data/examples/rr/double_register_scenario_example.rb +1 -1
- data/examples/rr/double_verify_example.rb +1 -1
- 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/times_called_expectation_at_least_example.rb +1 -1
- data/examples/rr/expectations/times_called_expectation/times_called_expectation_at_most_example.rb +1 -1
- data/examples/rr/expectations/times_called_expectation/times_called_expectation_integer_example.rb +3 -3
- data/examples/rr/expectations/times_called_expectation/times_called_expectation_range_example.rb +1 -1
- data/examples/rr/extensions/double_methods_example.rb +4 -4
- data/examples/rr/scenario_example.rb +34 -5
- data/examples/rr/space_verify_example.rb +7 -1
- data/examples/rr/times_called_matchers/any_times_matcher_example.rb +61 -0
- data/examples/rr/times_called_matchers/at_least_matcher_example.rb +1 -1
- data/examples/rr/times_called_matchers/at_most_matcher_example.rb +1 -1
- data/examples/rr/times_called_matchers/integer_matcher_example.rb +1 -1
- data/examples/rr/times_called_matchers/proc_matcher_example.rb +1 -1
- data/examples/rr/times_called_matchers/range_matcher_example.rb +1 -1
- data/examples/rr/times_called_matchers/times_called_matcher_example.rb +1 -1
- data/lib/rr.rb +1 -0
- data/lib/rr/double.rb +9 -3
- data/lib/rr/expectations/argument_equality_expectation.rb +1 -1
- data/lib/rr/extensions/double_methods.rb +5 -5
- data/lib/rr/scenario.rb +38 -11
- data/lib/rr/space.rb +7 -2
- data/lib/rr/times_called_matchers/any_times_matcher.rb +22 -0
- data/lib/rr/times_called_matchers/times_called_matcher.rb +1 -1
- metadata +3 -1
data/CHANGES
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
* 0.1.8
|
2
|
+
- TimesCalledError Message Formatted to be on multiple lines
|
3
|
+
- ScenarioNotFoundError Message includes all Scenarios for the Double
|
4
|
+
- ScenarioOrderError shows list of remaining ordered scenarios
|
5
|
+
|
1
6
|
* 0.1.7
|
2
7
|
- Fixed [#12194] Double#reset_doubles are not clearing Ordered Scenarios bug
|
3
8
|
- Added Space#reset
|
data/Rakefile
CHANGED
@@ -97,7 +97,10 @@ describe Double, " method dispatching where there are scenarios" do
|
|
97
97
|
|
98
98
|
proc {@object.foobar(:arg1, :arg2)}.should raise_error(
|
99
99
|
Errors::ScenarioNotFoundError,
|
100
|
-
"No scenario for foobar(:arg1, :arg2)"
|
100
|
+
"No scenario for foobar(:arg1, :arg2)\n" <<
|
101
|
+
"in\n" <<
|
102
|
+
"- foobar(1, 2)\n" <<
|
103
|
+
"- foobar(3)"
|
101
104
|
)
|
102
105
|
end
|
103
106
|
end
|
@@ -14,7 +14,7 @@ describe Double, "#register_scenario" do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
it "adds the scenario to the scenarios list" do
|
17
|
-
scenario = Scenario.new(@space)
|
17
|
+
scenario = Scenario.new(@space, @double)
|
18
18
|
|
19
19
|
@double.scenarios.should_not include(scenario)
|
20
20
|
@double.register_scenario scenario
|
@@ -11,8 +11,8 @@ module Expectations
|
|
11
11
|
@expectation.should == AnyArgumentExpectation.new
|
12
12
|
end
|
13
13
|
|
14
|
-
it "returns false when comparing with
|
15
|
-
@expectation.should_not ==
|
14
|
+
it "returns false when comparing with ArgumentEqualityExpectation" do
|
15
|
+
@expectation.should_not == ArgumentEqualityExpectation.new(1)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -2,9 +2,9 @@ require "examples/example_helper"
|
|
2
2
|
|
3
3
|
module RR
|
4
4
|
module Expectations
|
5
|
-
describe
|
5
|
+
describe ArgumentEqualityExpectation, "#exact_match? with anything argument" do
|
6
6
|
before do
|
7
|
-
@expectation =
|
7
|
+
@expectation = ArgumentEqualityExpectation.new(anything)
|
8
8
|
end
|
9
9
|
|
10
10
|
it "returns true when passed in an Anything module" do
|
@@ -20,9 +20,9 @@ module Expectations
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
describe
|
23
|
+
describe ArgumentEqualityExpectation, "#wildcard_match? with is_a String argument" do
|
24
24
|
before do
|
25
|
-
@expectation =
|
25
|
+
@expectation = ArgumentEqualityExpectation.new(anything)
|
26
26
|
end
|
27
27
|
|
28
28
|
it "returns true when passed correct number of arguments" do
|
@@ -2,26 +2,26 @@ require "examples/example_helper"
|
|
2
2
|
|
3
3
|
module RR
|
4
4
|
module Expectations
|
5
|
-
describe
|
5
|
+
describe ArgumentEqualityExpectation, "==" do
|
6
6
|
before do
|
7
|
-
@expectation =
|
7
|
+
@expectation = ArgumentEqualityExpectation.new(1, 2, 3)
|
8
8
|
end
|
9
9
|
|
10
10
|
it "returns true when passed in expected_arguments are equal" do
|
11
|
-
@expectation.should ==
|
11
|
+
@expectation.should == ArgumentEqualityExpectation.new(1, 2, 3)
|
12
12
|
end
|
13
13
|
|
14
14
|
it "returns false when passed in expected_arguments are not equal" do
|
15
|
-
@expectation.should_not ==
|
16
|
-
@expectation.should_not ==
|
17
|
-
@expectation.should_not ==
|
18
|
-
@expectation.should_not ==
|
15
|
+
@expectation.should_not == ArgumentEqualityExpectation.new(1, 2)
|
16
|
+
@expectation.should_not == ArgumentEqualityExpectation.new(1)
|
17
|
+
@expectation.should_not == ArgumentEqualityExpectation.new(:something)
|
18
|
+
@expectation.should_not == ArgumentEqualityExpectation.new()
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
describe
|
22
|
+
describe ArgumentEqualityExpectation, "#exact_match?" do
|
23
23
|
before do
|
24
|
-
@expectation =
|
24
|
+
@expectation = ArgumentEqualityExpectation.new(1, 2, 3)
|
25
25
|
end
|
26
26
|
|
27
27
|
it "returns true when all arguments exactly match" do
|
@@ -33,16 +33,16 @@ module Expectations
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
describe
|
36
|
+
describe ArgumentEqualityExpectation, "#wildcard_match?" do
|
37
37
|
it "returns false when not exact match" do
|
38
|
-
@expectation =
|
38
|
+
@expectation = ArgumentEqualityExpectation.new(1)
|
39
39
|
@expectation.should_not be_wildcard_match(1, 2, 3)
|
40
40
|
@expectation.should_not be_wildcard_match("whatever")
|
41
41
|
@expectation.should_not be_wildcard_match("whatever", "else")
|
42
42
|
end
|
43
43
|
|
44
44
|
it "returns true when exact match" do
|
45
|
-
@expectation =
|
45
|
+
@expectation = ArgumentEqualityExpectation.new(1, 2)
|
46
46
|
@expectation.should be_wildcard_match(1, 2)
|
47
47
|
@expectation.should_not be_wildcard_match(1)
|
48
48
|
@expectation.should_not be_wildcard_match("whatever", "else")
|
@@ -2,9 +2,9 @@ require "examples/example_helper"
|
|
2
2
|
|
3
3
|
module RR
|
4
4
|
module Expectations
|
5
|
-
describe
|
5
|
+
describe ArgumentEqualityExpectation, "#exact_match? with is_a argument" do
|
6
6
|
before do
|
7
|
-
@expectation =
|
7
|
+
@expectation = ArgumentEqualityExpectation.new(boolean)
|
8
8
|
end
|
9
9
|
|
10
10
|
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 ArgumentEqualityExpectation, "#wildcard_match? with is_a Boolean argument" do
|
25
25
|
before do
|
26
|
-
@expectation =
|
26
|
+
@expectation = ArgumentEqualityExpectation.new(boolean)
|
27
27
|
end
|
28
28
|
|
29
29
|
it "returns true when passed a Boolean" do
|
@@ -2,9 +2,9 @@ require "examples/example_helper"
|
|
2
2
|
|
3
3
|
module RR
|
4
4
|
module Expectations
|
5
|
-
describe
|
5
|
+
describe ArgumentEqualityExpectation, "#exact_match? with duck_type argument" do
|
6
6
|
before do
|
7
|
-
@expectation =
|
7
|
+
@expectation = ArgumentEqualityExpectation.new(duck_type(:to_s))
|
8
8
|
end
|
9
9
|
|
10
10
|
it "returns true when passed in an DuckType matcher with the same argument list" do
|
@@ -25,7 +25,7 @@ module Expectations
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
describe
|
28
|
+
describe ArgumentEqualityExpectation, "#wildcard_match? with DuckType argument" do
|
29
29
|
before do
|
30
30
|
@matching_object = Object.new
|
31
31
|
def @matching_object.quack
|
@@ -39,7 +39,7 @@ module Expectations
|
|
39
39
|
|
40
40
|
@not_match_object = Object.new
|
41
41
|
|
42
|
-
@expectation =
|
42
|
+
@expectation = ArgumentEqualityExpectation.new(duck_type(:quack, :waddle))
|
43
43
|
end
|
44
44
|
|
45
45
|
it "returns true when object matches all required methods" do
|
@@ -2,9 +2,9 @@ require "examples/example_helper"
|
|
2
2
|
|
3
3
|
module RR
|
4
4
|
module Expectations
|
5
|
-
describe
|
5
|
+
describe ArgumentEqualityExpectation, "#exact_match? with is_a argument" do
|
6
6
|
before do
|
7
|
-
@expectation =
|
7
|
+
@expectation = ArgumentEqualityExpectation.new(is_a(String))
|
8
8
|
end
|
9
9
|
|
10
10
|
it "returns true when passed in an IsA module" do
|
@@ -24,9 +24,9 @@ module Expectations
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
describe
|
27
|
+
describe ArgumentEqualityExpectation, "#wildcard_match? with is_a String argument" do
|
28
28
|
before do
|
29
|
-
@expectation =
|
29
|
+
@expectation = ArgumentEqualityExpectation.new(is_a(String))
|
30
30
|
end
|
31
31
|
|
32
32
|
it "returns true when passed a String" do
|
@@ -2,9 +2,9 @@ require "examples/example_helper"
|
|
2
2
|
|
3
3
|
module RR
|
4
4
|
module Expectations
|
5
|
-
describe
|
5
|
+
describe ArgumentEqualityExpectation, "#exact_match? with is_a argument" do
|
6
6
|
before do
|
7
|
-
@expectation =
|
7
|
+
@expectation = ArgumentEqualityExpectation.new(numeric)
|
8
8
|
end
|
9
9
|
|
10
10
|
it "returns true when passed in an IsA module" do
|
@@ -20,9 +20,9 @@ module Expectations
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
describe
|
23
|
+
describe ArgumentEqualityExpectation, "#wildcard_match? with is_a Numeric argument" do
|
24
24
|
before do
|
25
|
-
@expectation =
|
25
|
+
@expectation = ArgumentEqualityExpectation.new(numeric)
|
26
26
|
end
|
27
27
|
|
28
28
|
it "returns true when passed a Numeric" do
|
@@ -2,9 +2,9 @@ require "examples/example_helper"
|
|
2
2
|
|
3
3
|
module RR
|
4
4
|
module Expectations
|
5
|
-
describe
|
5
|
+
describe ArgumentEqualityExpectation, "#exact_match? with range argument" do
|
6
6
|
before do
|
7
|
-
@expectation =
|
7
|
+
@expectation = ArgumentEqualityExpectation.new(2..5)
|
8
8
|
end
|
9
9
|
|
10
10
|
it "returns true when passed in an Range matcher with the same argument list" do
|
@@ -25,9 +25,9 @@ module Expectations
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
describe
|
28
|
+
describe ArgumentEqualityExpectation, "#wildcard_match? with Range argument" do
|
29
29
|
before do
|
30
|
-
@expectation =
|
30
|
+
@expectation = ArgumentEqualityExpectation.new(2..6)
|
31
31
|
end
|
32
32
|
|
33
33
|
it "returns true when string matches the range" do
|
@@ -2,9 +2,9 @@ require "examples/example_helper"
|
|
2
2
|
|
3
3
|
module RR
|
4
4
|
module Expectations
|
5
|
-
describe
|
5
|
+
describe ArgumentEqualityExpectation, "#exact_match? with regexp argument" do
|
6
6
|
before do
|
7
|
-
@expectation =
|
7
|
+
@expectation = ArgumentEqualityExpectation.new(/abc/)
|
8
8
|
end
|
9
9
|
|
10
10
|
it "returns true when passed in an Regexp matcher with the same argument list" do
|
@@ -25,7 +25,7 @@ module Expectations
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
describe
|
28
|
+
describe ArgumentEqualityExpectation, "#wildcard_match? with Regexp argument" do
|
29
29
|
before do
|
30
30
|
@matching_object = Object.new
|
31
31
|
def @matching_object.quack
|
@@ -39,7 +39,7 @@ module Expectations
|
|
39
39
|
|
40
40
|
@not_match_object = Object.new
|
41
41
|
|
42
|
-
@expectation =
|
42
|
+
@expectation = ArgumentEqualityExpectation.new(/abc/)
|
43
43
|
end
|
44
44
|
|
45
45
|
it "returns true when string matches the regexp" do
|
data/examples/rr/expectations/times_called_expectation/times_called_expectation_at_most_example.rb
CHANGED
@@ -54,7 +54,7 @@ module Expectations
|
|
54
54
|
3.times {@expectation.attempt!}
|
55
55
|
proc do
|
56
56
|
@expectation.attempt!
|
57
|
-
end.should raise_error(Errors::TimesCalledError, "Called 4 times
|
57
|
+
end.should raise_error(Errors::TimesCalledError, "Called 4 times.\nExpected at most 3 times.")
|
58
58
|
end
|
59
59
|
|
60
60
|
it "passes when times called == times" do
|
data/examples/rr/expectations/times_called_expectation/times_called_expectation_integer_example.rb
CHANGED
@@ -36,7 +36,7 @@ module Expectations
|
|
36
36
|
@expectation.attempt!
|
37
37
|
proc {@expectation.verify!}.should raise_error(
|
38
38
|
Errors::TimesCalledError,
|
39
|
-
"Called 1 time
|
39
|
+
"Called 1 time.\nExpected 2 times."
|
40
40
|
)
|
41
41
|
end
|
42
42
|
|
@@ -45,7 +45,7 @@ module Expectations
|
|
45
45
|
@expectation.attempt!
|
46
46
|
proc do
|
47
47
|
@expectation.attempt!
|
48
|
-
end.should raise_error(Errors::TimesCalledError, "Called 3 times
|
48
|
+
end.should raise_error(Errors::TimesCalledError, "Called 3 times.\nExpected 2 times.")
|
49
49
|
end
|
50
50
|
|
51
51
|
it "has a backtrace to where the TimesCalledExpectation was instantiated on failure" do
|
@@ -62,7 +62,7 @@ module Expectations
|
|
62
62
|
it "has an error message that includes the number of times called and expected number of times" do
|
63
63
|
proc do
|
64
64
|
@expectation.verify!
|
65
|
-
end.should raise_error(Errors::TimesCalledError, "Called 0 times
|
65
|
+
end.should raise_error(Errors::TimesCalledError, "Called 0 times.\nExpected 2 times.")
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
data/examples/rr/expectations/times_called_expectation/times_called_expectation_range_example.rb
CHANGED
@@ -42,7 +42,7 @@ module Expectations
|
|
42
42
|
@expectation.attempt!
|
43
43
|
proc do
|
44
44
|
@expectation.attempt!
|
45
|
-
end.should raise_error(Errors::TimesCalledError, "Called 3 times
|
45
|
+
end.should raise_error(Errors::TimesCalledError, "Called 3 times.\nExpected 1..2 times.")
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
@@ -25,7 +25,7 @@ module Extensions
|
|
25
25
|
|
26
26
|
scenario = creator.foobar(1, 2) {:baz}
|
27
27
|
scenario.times_called_expectation.matcher.should == TimesCalledMatchers::IntegerMatcher.new(1)
|
28
|
-
scenario.argument_expectation.class.should == RR::Expectations::
|
28
|
+
scenario.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
|
29
29
|
scenario.argument_expectation.expected_arguments.should == [1, 2]
|
30
30
|
|
31
31
|
@subject.foobar(1, 2).should == :baz
|
@@ -55,7 +55,7 @@ module Extensions
|
|
55
55
|
|
56
56
|
scenario = creator.foobar(1, 2) {:baz}
|
57
57
|
scenario.times_called_expectation.should == nil
|
58
|
-
scenario.argument_expectation.class.should == RR::Expectations::
|
58
|
+
scenario.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
|
59
59
|
@subject.foobar(1, 2).should == :baz
|
60
60
|
end
|
61
61
|
end
|
@@ -83,7 +83,7 @@ module Extensions
|
|
83
83
|
|
84
84
|
scenario = creator.foobar(1, 2)
|
85
85
|
scenario.times_called_expectation.times.should == 1
|
86
|
-
scenario.argument_expectation.class.should == RR::Expectations::
|
86
|
+
scenario.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
|
87
87
|
scenario.argument_expectation.expected_arguments.should == [1, 2]
|
88
88
|
|
89
89
|
@subject.foobar(1, 2).should == :original_value
|
@@ -121,7 +121,7 @@ module Extensions
|
|
121
121
|
|
122
122
|
scenario = creator.foobar(1, 2)
|
123
123
|
scenario.times_called_expectation.matcher.should == TimesCalledMatchers::IntegerMatcher.new(0)
|
124
|
-
scenario.argument_expectation.class.should == RR::Expectations::
|
124
|
+
scenario.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
|
125
125
|
scenario.argument_expectation.expected_arguments.should == [1, 2]
|
126
126
|
end
|
127
127
|
end
|
@@ -14,7 +14,7 @@ end
|
|
14
14
|
describe Scenario, "#with" do
|
15
15
|
it_should_behave_like "RR::Scenario"
|
16
16
|
|
17
|
-
it "sets an
|
17
|
+
it "sets an ArgumentEqualityExpectation" do
|
18
18
|
@scenario.with(1).should === @scenario
|
19
19
|
@scenario.should be_exact_match(1)
|
20
20
|
@scenario.should_not be_exact_match(2)
|
@@ -58,8 +58,8 @@ describe Scenario, "#with_no_args" do
|
|
58
58
|
@scenario.with_no_args.should === @scenario
|
59
59
|
end
|
60
60
|
|
61
|
-
it "sets an
|
62
|
-
@scenario.argument_expectation.should == Expectations::
|
61
|
+
it "sets an ArgumentEqualityExpectation with no arguments" do
|
62
|
+
@scenario.argument_expectation.should == Expectations::ArgumentEqualityExpectation.new()
|
63
63
|
end
|
64
64
|
|
65
65
|
it "sets return value when block passed in" do
|
@@ -153,7 +153,7 @@ describe Scenario, "#at_most" do
|
|
153
153
|
@scenario.call
|
154
154
|
end.should raise_error(
|
155
155
|
Errors::TimesCalledError,
|
156
|
-
"Called 3 times
|
156
|
+
"Called 3 times.\nExpected at most 2 times."
|
157
157
|
)
|
158
158
|
end
|
159
159
|
|
@@ -355,7 +355,13 @@ describe Scenario, "#call implemented by a proc" do
|
|
355
355
|
|
356
356
|
proc do
|
357
357
|
@object.foobar(2)
|
358
|
-
end.should raise_error(
|
358
|
+
end.should raise_error(
|
359
|
+
Errors::ScenarioOrderError,
|
360
|
+
"foobar(2)\n" <<
|
361
|
+
"called out of order in list\n" <<
|
362
|
+
"- foobar(1)\n" <<
|
363
|
+
"- foobar(2)"
|
364
|
+
)
|
359
365
|
end
|
360
366
|
|
361
367
|
it "dispatches to Space#verify_ordered_scenario when ordered" do
|
@@ -527,4 +533,27 @@ describe Scenario, "#verify" do
|
|
527
533
|
proc {@scenario.verify}.should_not raise_error
|
528
534
|
end
|
529
535
|
end
|
536
|
+
|
537
|
+
describe Scenario, "#method_name" do
|
538
|
+
it_should_behave_like "RR::Scenario"
|
539
|
+
|
540
|
+
it "returns the Double's method_name" do
|
541
|
+
@double.method_name.should == :foobar
|
542
|
+
@scenario.method_name.should == :foobar
|
543
|
+
end
|
544
|
+
end
|
545
|
+
|
546
|
+
describe Scenario, "#expected_arguments" do
|
547
|
+
it_should_behave_like "RR::Scenario"
|
548
|
+
|
549
|
+
it "returns argument expectation's expected_arguments when there is a argument expectation" do
|
550
|
+
@scenario.with(1, 2)
|
551
|
+
@scenario.expected_arguments.should == [1, 2]
|
552
|
+
end
|
553
|
+
|
554
|
+
it "returns an empty array when there is no argument expectation" do
|
555
|
+
@scenario.argument_expectation.should be_nil
|
556
|
+
@scenario.expected_arguments.should == []
|
557
|
+
end
|
558
|
+
end
|
530
559
|
end
|
@@ -139,7 +139,13 @@ describe Space, "#verify_ordered_scenario where the passed in scenario is not at
|
|
139
139
|
|
140
140
|
proc do
|
141
141
|
@space.verify_ordered_scenario(second_scenario)
|
142
|
-
end.should raise_error(
|
142
|
+
end.should raise_error(
|
143
|
+
Errors::ScenarioOrderError,
|
144
|
+
"foobar()\n" <<
|
145
|
+
"called out of order in list\n" <<
|
146
|
+
"- foobar()\n" <<
|
147
|
+
"- foobar()"
|
148
|
+
)
|
143
149
|
end
|
144
150
|
end
|
145
151
|
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require "examples/example_helper"
|
2
|
+
|
3
|
+
module RR
|
4
|
+
module TimesCalledMatchers
|
5
|
+
describe TimesCalledMatcher, ".create when passed a AnyTimesMatcher" do
|
6
|
+
it "returns the passed in argument" do
|
7
|
+
matcher = AnyTimesMatcher.new(5)
|
8
|
+
TimesCalledMatcher.create(matcher).should === matcher
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe AnyTimesMatcher, "#possible_match?" do
|
13
|
+
before do
|
14
|
+
@times = 3
|
15
|
+
@matcher = AnyTimesMatcher.new(@times)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "always returns true" do
|
19
|
+
@matcher.should be_possible_match(0)
|
20
|
+
@matcher.should be_possible_match(99999)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe AnyTimesMatcher, "#matches?" do
|
25
|
+
before do
|
26
|
+
@times = 3
|
27
|
+
@matcher = AnyTimesMatcher.new(@times)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "always returns true" do
|
31
|
+
@matcher.should be_matches(0)
|
32
|
+
@matcher.should be_matches(99999)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe AnyTimesMatcher, "#attempt?" do
|
37
|
+
before do
|
38
|
+
@times = 3
|
39
|
+
@matcher = AnyTimesMatcher.new(@times)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "always returns true" do
|
43
|
+
@matcher.should be_attempt(0)
|
44
|
+
@matcher.should be_attempt(99999)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe AnyTimesMatcher, "#error_message" do
|
49
|
+
before do
|
50
|
+
@times = 3
|
51
|
+
@matcher = AnyTimesMatcher.new(@times)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "has an error message" do
|
55
|
+
@matcher.error_message(2).should == (
|
56
|
+
"Called 2 times.\nExpected any number of times."
|
57
|
+
)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/lib/rr.rb
CHANGED
@@ -29,6 +29,7 @@ require "rr/wildcard_matchers/regexp"
|
|
29
29
|
require "rr/wildcard_matchers/range"
|
30
30
|
|
31
31
|
require "rr/times_called_matchers/times_called_matcher"
|
32
|
+
require "rr/times_called_matchers/any_times_matcher"
|
32
33
|
require "rr/times_called_matchers/integer_matcher"
|
33
34
|
require "rr/times_called_matchers/range_matcher"
|
34
35
|
require "rr/times_called_matchers/proc_matcher"
|
data/lib/rr/double.rb
CHANGED
@@ -77,11 +77,17 @@ module RR
|
|
77
77
|
end
|
78
78
|
end
|
79
79
|
matching_scenarios.first.call(*args) unless matching_scenarios.empty?
|
80
|
+
scenario_not_found_error(*args)
|
81
|
+
end
|
80
82
|
|
81
|
-
|
82
|
-
|
83
|
+
protected
|
84
|
+
def scenario_not_found_error(*args)
|
85
|
+
message = "No scenario for #{Scenario.formatted_name(@method_name, args)}\n"
|
86
|
+
message << "in\n"
|
87
|
+
message << Scenario.list_message_part(@scenarios)
|
88
|
+
raise Errors::ScenarioNotFoundError, message
|
83
89
|
end
|
84
|
-
|
90
|
+
|
85
91
|
def placeholder_name
|
86
92
|
"__rr__#{@method_name}"
|
87
93
|
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 ArgumentEqualityExpectation
|
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::WildcardMatchers::Anything.new
|
39
39
|
end
|
40
40
|
|
41
|
-
# Sets up an IsA wildcard
|
41
|
+
# Sets up an IsA wildcard ArgumentEqualityExpectation
|
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::WildcardMatchers::IsA.new(klass)
|
47
47
|
end
|
48
48
|
|
49
|
-
# Sets up an Numeric wildcard
|
49
|
+
# Sets up an Numeric wildcard ArgumentEqualityExpectation
|
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::WildcardMatchers::Numeric.new
|
55
55
|
end
|
56
56
|
|
57
|
-
# Sets up an Boolean wildcard
|
57
|
+
# Sets up an Boolean wildcard ArgumentEqualityExpectation
|
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::WildcardMatchers::Boolean.new
|
63
63
|
end
|
64
64
|
|
65
|
-
# Sets up a DuckType wildcard
|
65
|
+
# Sets up a DuckType wildcard ArgumentEqualityExpectation
|
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,33 +1,47 @@
|
|
1
1
|
module RR
|
2
2
|
# RR::Scenario is the use case for a method call.
|
3
|
-
# It has the
|
3
|
+
# It has the ArgumentEqualityExpectation, TimesCalledExpectation,
|
4
4
|
# and the implementation.
|
5
5
|
class Scenario
|
6
|
-
|
6
|
+
class << self
|
7
|
+
def formatted_name(method_name, args)
|
8
|
+
formatted_errors = args.collect {|arg| arg.inspect}.join(', ')
|
9
|
+
"#{method_name}(#{formatted_errors})"
|
10
|
+
end
|
11
|
+
|
12
|
+
def list_message_part(scenarios)
|
13
|
+
scenarios.collect do |scenario|
|
14
|
+
"- #{formatted_name(scenario.method_name, scenario.expected_arguments)}"
|
15
|
+
end.join("\n")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
attr_reader :times_called, :argument_expectation, :times_called_expectation, :double
|
7
20
|
|
8
|
-
def initialize(space)
|
21
|
+
def initialize(space, double)
|
9
22
|
@space = space
|
10
23
|
@implementation = nil
|
11
24
|
@argument_expectation = nil
|
12
25
|
@times_called_expectation = nil
|
13
26
|
@times_called = 0
|
14
27
|
@after_call = nil
|
28
|
+
@double = double
|
15
29
|
@yields = nil
|
16
30
|
end
|
17
31
|
|
18
|
-
# Scenario#with creates an
|
32
|
+
# Scenario#with creates an ArgumentEqualityExpectation for the
|
19
33
|
# Scenario. it takes a list of expected arguments.
|
20
34
|
#
|
21
35
|
# Passing in a block sets the return value.
|
22
36
|
#
|
23
37
|
# mock(subject).method_name.with(1, 2) {:return_value}
|
24
38
|
def with(*args, &returns)
|
25
|
-
@argument_expectation = Expectations::
|
39
|
+
@argument_expectation = Expectations::ArgumentEqualityExpectation.new(*args)
|
26
40
|
returns(&returns) if returns
|
27
41
|
self
|
28
42
|
end
|
29
43
|
|
30
|
-
# Scenario#with_any_args creates an
|
44
|
+
# Scenario#with_any_args creates an AnyArgumentEqualityExpectation
|
31
45
|
# for the Scenario.
|
32
46
|
#
|
33
47
|
# Passing in a block sets the return value.
|
@@ -39,14 +53,14 @@ module RR
|
|
39
53
|
self
|
40
54
|
end
|
41
55
|
|
42
|
-
# Scenario#with_no_args creates an
|
56
|
+
# Scenario#with_no_args creates an ArgumentEqualityExpectation with
|
43
57
|
# no arguments for the Scenario.
|
44
58
|
#
|
45
59
|
# Passing in a block sets the return value.
|
46
60
|
#
|
47
61
|
# mock(subject).method_name.with_no_args {:return_value}
|
48
62
|
def with_no_args(&returns)
|
49
|
-
@argument_expectation = Expectations::
|
63
|
+
@argument_expectation = Expectations::ArgumentEqualityExpectation.new()
|
50
64
|
returns(&returns) if returns
|
51
65
|
self
|
52
66
|
end
|
@@ -182,7 +196,9 @@ module RR
|
|
182
196
|
#
|
183
197
|
# Passing in an argument causes Scenario to return the argument.
|
184
198
|
def returns(value=nil, &implementation)
|
185
|
-
|
199
|
+
if value && implementation
|
200
|
+
raise ArgumentError, "returns cannot accept both an argument and a block"
|
201
|
+
end
|
186
202
|
if value
|
187
203
|
implemented_by proc {value}
|
188
204
|
else
|
@@ -236,14 +252,14 @@ module RR
|
|
236
252
|
protected :call_implementation
|
237
253
|
|
238
254
|
# Scenario#exact_match? returns true when the passed in arguments
|
239
|
-
# exactly match the
|
255
|
+
# exactly match the ArgumentEqualityExpectation arguments.
|
240
256
|
def exact_match?(*arguments)
|
241
257
|
return false unless @argument_expectation
|
242
258
|
@argument_expectation.exact_match?(*arguments)
|
243
259
|
end
|
244
260
|
|
245
261
|
# Scenario#wildcard_match? returns true when the passed in arguments
|
246
|
-
# wildcard match the
|
262
|
+
# wildcard match the ArgumentEqualityExpectation arguments.
|
247
263
|
def wildcard_match?(*arguments)
|
248
264
|
return false unless @argument_expectation
|
249
265
|
@argument_expectation.wildcard_match?(*arguments)
|
@@ -264,5 +280,16 @@ module RR
|
|
264
280
|
@times_called_expectation.verify!
|
265
281
|
true
|
266
282
|
end
|
283
|
+
|
284
|
+
# The method name that this Scenario is attatched to
|
285
|
+
def method_name
|
286
|
+
double.method_name
|
287
|
+
end
|
288
|
+
|
289
|
+
# The Argumentns that this Scenario expects
|
290
|
+
def expected_arguments
|
291
|
+
return [] unless argument_expectation
|
292
|
+
argument_expectation.expected_arguments
|
293
|
+
end
|
267
294
|
end
|
268
295
|
end
|
data/lib/rr/space.rb
CHANGED
@@ -45,7 +45,7 @@ module RR
|
|
45
45
|
|
46
46
|
# Creates and registers a Scenario to be verified.
|
47
47
|
def create_scenario(double)
|
48
|
-
scenario = Scenario.new(self)
|
48
|
+
scenario = Scenario.new(self, double)
|
49
49
|
double.register_scenario scenario
|
50
50
|
scenario
|
51
51
|
end
|
@@ -72,7 +72,12 @@ module RR
|
|
72
72
|
# Verifies that the passed in ordered Scenario is being called
|
73
73
|
# in the correct position.
|
74
74
|
def verify_ordered_scenario(scenario)
|
75
|
-
|
75
|
+
unless @ordered_scenarios.first == scenario
|
76
|
+
message = Scenario.formatted_name(scenario.method_name, scenario.expected_arguments)
|
77
|
+
message << "\ncalled out of order in list\n"
|
78
|
+
message << Scenario.list_message_part(@ordered_scenarios)
|
79
|
+
raise Errors::ScenarioOrderError, message
|
80
|
+
end
|
76
81
|
@ordered_scenarios.shift unless scenario.attempt?
|
77
82
|
scenario
|
78
83
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module RR
|
2
|
+
module TimesCalledMatchers
|
3
|
+
class AnyTimesMatcher < TimesCalledMatcher
|
4
|
+
def possible_match?(times_called)
|
5
|
+
true
|
6
|
+
end
|
7
|
+
|
8
|
+
def matches?(times_called)
|
9
|
+
true
|
10
|
+
end
|
11
|
+
|
12
|
+
def attempt?(times_called)
|
13
|
+
true
|
14
|
+
end
|
15
|
+
|
16
|
+
protected
|
17
|
+
def expected_message_part
|
18
|
+
"Expected any number of times."
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -24,7 +24,7 @@ module TimesCalledMatchers
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def error_message(times_called)
|
27
|
-
"Called #{times_called.inspect} #{pluralized_time(times_called)}
|
27
|
+
"Called #{times_called.inspect} #{pluralized_time(times_called)}.\n#{expected_message_part}"
|
28
28
|
end
|
29
29
|
|
30
30
|
def ==(other)
|
metadata
CHANGED
@@ -3,7 +3,7 @@ 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.
|
6
|
+
version: 0.1.8
|
7
7
|
date: 2007-07-14 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:
|
@@ -40,6 +40,7 @@ files:
|
|
40
40
|
- lib/rr/do_not_allow_creator.rb
|
41
41
|
- lib/rr/mock_creator.rb
|
42
42
|
- lib/rr/probe_creator.rb
|
43
|
+
- lib/rr/times_called_matchers/any_times_matcher.rb
|
43
44
|
- lib/rr/times_called_matchers/at_most_matcher.rb
|
44
45
|
- lib/rr/times_called_matchers/times_called_matcher.rb
|
45
46
|
- lib/rr/times_called_matchers/at_least_matcher.rb
|
@@ -95,6 +96,7 @@ files:
|
|
95
96
|
- examples/rr/times_called_matchers/times_called_matcher_example.rb
|
96
97
|
- examples/rr/times_called_matchers/range_matcher_example.rb
|
97
98
|
- examples/rr/times_called_matchers/proc_matcher_example.rb
|
99
|
+
- examples/rr/times_called_matchers/any_times_matcher_example.rb
|
98
100
|
- examples/rr/times_called_matchers/integer_matcher_example.rb
|
99
101
|
- examples/rr/expectations/is_a_argument_equality_expectation_example.rb
|
100
102
|
- examples/rr/expectations/any_argument_expectation_example.rb
|