rr 0.1.7 → 0.1.8

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.
Files changed (37) hide show
  1. data/CHANGES +5 -0
  2. data/Rakefile +1 -1
  3. data/examples/rr/double_dispatching_example.rb +4 -1
  4. data/examples/rr/double_register_scenario_example.rb +1 -1
  5. data/examples/rr/double_verify_example.rb +1 -1
  6. data/examples/rr/expectations/any_argument_expectation_example.rb +2 -2
  7. data/examples/rr/expectations/anything_argument_equality_expectation_example.rb +4 -4
  8. data/examples/rr/expectations/argument_equality_expectation_example.rb +12 -12
  9. data/examples/rr/expectations/boolean_argument_equality_expectation_example.rb +4 -4
  10. data/examples/rr/expectations/duck_type_argument_equality_expectation_example.rb +4 -4
  11. data/examples/rr/expectations/is_a_argument_equality_expectation_example.rb +4 -4
  12. data/examples/rr/expectations/numeric_argument_equality_expectation_example.rb +4 -4
  13. data/examples/rr/expectations/range_argument_equality_expectation_example.rb +4 -4
  14. data/examples/rr/expectations/regexp_argument_equality_expectation_example.rb +4 -4
  15. data/examples/rr/expectations/times_called_expectation/times_called_expectation_at_least_example.rb +1 -1
  16. data/examples/rr/expectations/times_called_expectation/times_called_expectation_at_most_example.rb +1 -1
  17. data/examples/rr/expectations/times_called_expectation/times_called_expectation_integer_example.rb +3 -3
  18. data/examples/rr/expectations/times_called_expectation/times_called_expectation_range_example.rb +1 -1
  19. data/examples/rr/extensions/double_methods_example.rb +4 -4
  20. data/examples/rr/scenario_example.rb +34 -5
  21. data/examples/rr/space_verify_example.rb +7 -1
  22. data/examples/rr/times_called_matchers/any_times_matcher_example.rb +61 -0
  23. data/examples/rr/times_called_matchers/at_least_matcher_example.rb +1 -1
  24. data/examples/rr/times_called_matchers/at_most_matcher_example.rb +1 -1
  25. data/examples/rr/times_called_matchers/integer_matcher_example.rb +1 -1
  26. data/examples/rr/times_called_matchers/proc_matcher_example.rb +1 -1
  27. data/examples/rr/times_called_matchers/range_matcher_example.rb +1 -1
  28. data/examples/rr/times_called_matchers/times_called_matcher_example.rb +1 -1
  29. data/lib/rr.rb +1 -0
  30. data/lib/rr/double.rb +9 -3
  31. data/lib/rr/expectations/argument_equality_expectation.rb +1 -1
  32. data/lib/rr/extensions/double_methods.rb +5 -5
  33. data/lib/rr/scenario.rb +38 -11
  34. data/lib/rr/space.rb +7 -2
  35. data/lib/rr/times_called_matchers/any_times_matcher.rb +22 -0
  36. data/lib/rr/times_called_matchers/times_called_matcher.rb +1 -1
  37. 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
@@ -21,7 +21,7 @@ def run_suite
21
21
  end
22
22
 
23
23
  PKG_NAME = "rr"
24
- PKG_VERSION = "0.1.7"
24
+ PKG_VERSION = "0.1.8"
25
25
  PKG_FILES = FileList[
26
26
  '[A-Z]*',
27
27
  '*.rb',
@@ -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,7 +11,7 @@ describe Double, "#verify" do
11
11
  end
12
12
 
13
13
  it "verifies each scenario was met" do
14
- scenario = Scenario.new(@space)
14
+ scenario = Scenario.new(@space, @double)
15
15
  @double.register_scenario scenario
16
16
 
17
17
  scenario.with(1).once.returns {nil}
@@ -11,8 +11,8 @@ module Expectations
11
11
  @expectation.should == AnyArgumentExpectation.new
12
12
  end
13
13
 
14
- it "returns false when comparing with ArgumentEqualityError" do
15
- @expectation.should_not == ArgumentEqualityError.new(1)
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 ArgumentEqualityError, "#exact_match? with anything argument" do
5
+ describe ArgumentEqualityExpectation, "#exact_match? with anything argument" do
6
6
  before do
7
- @expectation = ArgumentEqualityError.new(anything)
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 ArgumentEqualityError, "#wildcard_match? with is_a String argument" do
23
+ describe ArgumentEqualityExpectation, "#wildcard_match? with is_a String argument" do
24
24
  before do
25
- @expectation = ArgumentEqualityError.new(anything)
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 ArgumentEqualityError, "==" do
5
+ describe ArgumentEqualityExpectation, "==" do
6
6
  before do
7
- @expectation = ArgumentEqualityError.new(1, 2, 3)
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 == ArgumentEqualityError.new(1, 2, 3)
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 == ArgumentEqualityError.new(1, 2)
16
- @expectation.should_not == ArgumentEqualityError.new(1)
17
- @expectation.should_not == ArgumentEqualityError.new(:something)
18
- @expectation.should_not == ArgumentEqualityError.new()
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 ArgumentEqualityError, "#exact_match?" do
22
+ describe ArgumentEqualityExpectation, "#exact_match?" do
23
23
  before do
24
- @expectation = ArgumentEqualityError.new(1, 2, 3)
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 ArgumentEqualityError, "#wildcard_match?" do
36
+ describe ArgumentEqualityExpectation, "#wildcard_match?" do
37
37
  it "returns false when not exact match" do
38
- @expectation = ArgumentEqualityError.new(1)
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 = ArgumentEqualityError.new(1, 2)
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 ArgumentEqualityError, "#exact_match? with is_a argument" do
5
+ describe ArgumentEqualityExpectation, "#exact_match? with is_a argument" do
6
6
  before do
7
- @expectation = ArgumentEqualityError.new(boolean)
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 ArgumentEqualityError, "#wildcard_match? with is_a Boolean argument" do
24
+ describe ArgumentEqualityExpectation, "#wildcard_match? with is_a Boolean argument" do
25
25
  before do
26
- @expectation = ArgumentEqualityError.new(boolean)
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 ArgumentEqualityError, "#exact_match? with duck_type argument" do
5
+ describe ArgumentEqualityExpectation, "#exact_match? with duck_type argument" do
6
6
  before do
7
- @expectation = ArgumentEqualityError.new(duck_type(:to_s))
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 ArgumentEqualityError, "#wildcard_match? with DuckType argument" do
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 = ArgumentEqualityError.new(duck_type(:quack, :waddle))
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 ArgumentEqualityError, "#exact_match? with is_a argument" do
5
+ describe ArgumentEqualityExpectation, "#exact_match? with is_a argument" do
6
6
  before do
7
- @expectation = ArgumentEqualityError.new(is_a(String))
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 ArgumentEqualityError, "#wildcard_match? with is_a String argument" do
27
+ describe ArgumentEqualityExpectation, "#wildcard_match? with is_a String argument" do
28
28
  before do
29
- @expectation = ArgumentEqualityError.new(is_a(String))
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 ArgumentEqualityError, "#exact_match? with is_a argument" do
5
+ describe ArgumentEqualityExpectation, "#exact_match? with is_a argument" do
6
6
  before do
7
- @expectation = ArgumentEqualityError.new(numeric)
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 ArgumentEqualityError, "#wildcard_match? with is_a Numeric argument" do
23
+ describe ArgumentEqualityExpectation, "#wildcard_match? with is_a Numeric argument" do
24
24
  before do
25
- @expectation = ArgumentEqualityError.new(numeric)
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 ArgumentEqualityError, "#exact_match? with range argument" do
5
+ describe ArgumentEqualityExpectation, "#exact_match? with range argument" do
6
6
  before do
7
- @expectation = ArgumentEqualityError.new(2..5)
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 ArgumentEqualityError, "#wildcard_match? with Range argument" do
28
+ describe ArgumentEqualityExpectation, "#wildcard_match? with Range argument" do
29
29
  before do
30
- @expectation = ArgumentEqualityError.new(2..6)
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 ArgumentEqualityError, "#exact_match? with regexp argument" do
5
+ describe ArgumentEqualityExpectation, "#exact_match? with regexp argument" do
6
6
  before do
7
- @expectation = ArgumentEqualityError.new(/abc/)
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 ArgumentEqualityError, "#wildcard_match? with Regexp argument" do
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 = ArgumentEqualityError.new(/abc/)
42
+ @expectation = ArgumentEqualityExpectation.new(/abc/)
43
43
  end
44
44
 
45
45
  it "returns true when string matches the regexp" do
@@ -31,7 +31,7 @@ module Expectations
31
31
  @expectation.verify!
32
32
  end.should raise_error(
33
33
  RR::Errors::TimesCalledError,
34
- "Called 1 time. Expected at least 3 times."
34
+ "Called 1 time.\nExpected at least 3 times."
35
35
  )
36
36
  end
37
37
  end
@@ -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. Expected at most 3 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
@@ -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. Expected 2 times."
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. Expected 2 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. Expected 2 times.")
65
+ end.should raise_error(Errors::TimesCalledError, "Called 0 times.\nExpected 2 times.")
66
66
  end
67
67
  end
68
68
 
@@ -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. Expected 1..2 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::ArgumentEqualityError
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::ArgumentEqualityError
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::ArgumentEqualityError
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::ArgumentEqualityError
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 ArgumentEqualityError" do
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 ArgumentEqualityError with no arguments" do
62
- @scenario.argument_expectation.should == Expectations::ArgumentEqualityError.new()
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. Expected at most 2 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(Errors::ScenarioOrderError)
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(Errors::ScenarioOrderError)
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
@@ -66,7 +66,7 @@ module TimesCalledMatchers
66
66
 
67
67
  it "has an error message" do
68
68
  @matcher.error_message(2).should == (
69
- "Called 2 times. Expected at least 3 times."
69
+ "Called 2 times.\nExpected at least 3 times."
70
70
  )
71
71
  end
72
72
  end
@@ -74,7 +74,7 @@ module TimesCalledMatchers
74
74
 
75
75
  it "has an error message" do
76
76
  @matcher.error_message(5).should == (
77
- "Called 5 times. Expected at most 3 times."
77
+ "Called 5 times.\nExpected at most 3 times."
78
78
  )
79
79
  end
80
80
  end
@@ -80,7 +80,7 @@ module TimesCalledMatchers
80
80
 
81
81
  it "has an error message" do
82
82
  @matcher.error_message(2).should == (
83
- "Called 2 times. Expected 3 times."
83
+ "Called 2 times.\nExpected 3 times."
84
84
  )
85
85
  end
86
86
  end
@@ -67,7 +67,7 @@ module TimesCalledMatchers
67
67
 
68
68
  it "has an error message" do
69
69
  @matcher.error_message(1).should =~
70
- /Called 1 time. Expected #<Proc.*> times./
70
+ /Called 1 time.\nExpected #<Proc.*> times./
71
71
  end
72
72
  end
73
73
  end
@@ -86,7 +86,7 @@ module TimesCalledMatchers
86
86
 
87
87
  it "has an error message" do
88
88
  @matcher.error_message(1).should == (
89
- "Called 1 time. Expected 2..4 times."
89
+ "Called 1 time.\nExpected 2..4 times."
90
90
  )
91
91
  end
92
92
  end
@@ -26,7 +26,7 @@ module TimesCalledMatchers
26
26
 
27
27
  it "has an error message" do
28
28
  @matcher.error_message(5).should == (
29
- "Called 5 times. Expected 3 times."
29
+ "Called 5 times.\nExpected 3 times."
30
30
  )
31
31
  end
32
32
  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
- formatted_errors = args.collect {|arg| arg.inspect}.join(', ')
82
- raise Errors::ScenarioNotFoundError, "No scenario for #{@method_name}(#{formatted_errors})"
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
@@ -1,6 +1,6 @@
1
1
  module RR
2
2
  module Expectations
3
- class ArgumentEqualityError
3
+ class ArgumentEqualityExpectation
4
4
  attr_reader :expected_arguments
5
5
 
6
6
  def initialize(*expected_arguments)
@@ -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 ArgumentEqualityError
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 ArgumentEqualityError
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 ArgumentEqualityError
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 ArgumentEqualityError
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 ArgumentEqualityError
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 ArgumentEqualityError, TimesCalledExpectation,
3
+ # It has the ArgumentEqualityExpectation, TimesCalledExpectation,
4
4
  # and the implementation.
5
5
  class Scenario
6
- attr_reader :times_called, :argument_expectation, :times_called_expectation
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 ArgumentEqualityError for the
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::ArgumentEqualityError.new(*args)
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 AnyArgumentEqualityError
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 ArgumentEqualityError with
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::ArgumentEqualityError.new()
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
- raise ArgumentError, "returns cannot accept both an argument and a block" if value && implementation
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 ArgumentEqualityError arguments.
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 ArgumentEqualityError arguments.
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
- raise Errors::ScenarioOrderError unless @ordered_scenarios.first == scenario
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)}. #{expected_message_part}"
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.7
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