rr 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. data/CHANGES +7 -0
  2. data/Rakefile +1 -1
  3. data/examples/environment_fixture_setup.rb +1 -1
  4. data/examples/example_helper.rb +1 -0
  5. data/examples/high_level_example.rb +1 -2
  6. data/examples/rr/do_not_allow_creator_example.rb +1 -2
  7. data/examples/rr/double_bind_example.rb +1 -2
  8. data/examples/rr/double_dispatching_example.rb +2 -3
  9. data/examples/rr/double_example.rb +1 -2
  10. data/examples/rr/double_register_scenario_example.rb +1 -2
  11. data/examples/rr/double_reset_example.rb +1 -2
  12. data/examples/rr/double_verify_example.rb +1 -2
  13. data/examples/rr/errors/rr_error_example.rb +1 -2
  14. data/examples/rr/expectations/any_argument_expectation_example.rb +1 -2
  15. data/examples/rr/expectations/anything_argument_equality_expectation_example.rb +1 -2
  16. data/examples/rr/expectations/argument_equality_expectation_example.rb +1 -2
  17. data/examples/rr/expectations/boolean_argument_equality_expectation_example.rb +1 -2
  18. data/examples/rr/expectations/duck_type_argument_equality_expectation_example.rb +1 -2
  19. data/examples/rr/expectations/is_a_argument_equality_expectation_example.rb +1 -2
  20. data/examples/rr/expectations/numeric_argument_equality_expectation_example.rb +1 -2
  21. data/examples/rr/expectations/range_argument_equality_expectation_example.rb +1 -2
  22. data/examples/rr/expectations/regexp_argument_equality_expectation_example.rb +1 -2
  23. data/examples/rr/expectations/times_called_expectation/times_called_expectation_at_least_example.rb +74 -0
  24. data/examples/rr/expectations/times_called_expectation/times_called_expectation_at_most_example.rb +69 -0
  25. data/examples/rr/expectations/times_called_expectation/times_called_expectation_helper.rb +18 -0
  26. data/examples/rr/expectations/times_called_expectation/times_called_expectation_integer_example.rb +102 -0
  27. data/examples/rr/expectations/times_called_expectation/times_called_expectation_proc_example.rb +80 -0
  28. data/examples/rr/expectations/times_called_expectation/times_called_expectation_range_example.rb +81 -0
  29. data/examples/rr/expectations/times_called_expectation_example.rb +1 -185
  30. data/examples/rr/extensions/double_methods_example.rb +3 -4
  31. data/examples/rr/mock_creator_example.rb +1 -2
  32. data/examples/rr/probe_creator_example.rb +1 -2
  33. data/examples/rr/rspec/rspec_adapter_example.rb +1 -2
  34. data/examples/rr/rspec/rspec_backtrace_tweaking_example.rb +1 -2
  35. data/examples/rr/rspec/rspec_usage_example.rb +1 -2
  36. data/examples/rr/scenario_example.rb +60 -15
  37. data/examples/rr/space_create_example.rb +1 -2
  38. data/examples/rr/space_example.rb +1 -2
  39. data/examples/rr/space_register_example.rb +1 -2
  40. data/examples/rr/space_reset_example.rb +51 -4
  41. data/examples/rr/space_verify_example.rb +4 -5
  42. data/examples/rr/stub_creator_example.rb +1 -2
  43. data/examples/rr/test_unit/test_helper.rb +1 -1
  44. data/examples/rr/times_called_matchers/at_least_matcher_example.rb +74 -0
  45. data/examples/rr/times_called_matchers/at_most_matcher_example.rb +82 -0
  46. data/examples/rr/times_called_matchers/integer_matcher_example.rb +88 -0
  47. data/examples/rr/times_called_matchers/proc_matcher_example.rb +74 -0
  48. data/examples/rr/times_called_matchers/range_matcher_example.rb +94 -0
  49. data/examples/rr/times_called_matchers/times_called_matcher_example.rb +53 -0
  50. data/lib/rr.rb +15 -7
  51. data/lib/rr/adapters/rspec.rb +2 -2
  52. data/lib/rr/adapters/test_unit.rb +1 -1
  53. data/lib/rr/double.rb +2 -2
  54. data/lib/rr/expectations/times_called_expectation.rb +14 -13
  55. data/lib/rr/extensions/double_methods.rb +5 -5
  56. data/lib/rr/scenario.rb +35 -7
  57. data/lib/rr/space.rb +20 -8
  58. data/lib/rr/times_called_matchers/at_least_matcher.rb +22 -0
  59. data/lib/rr/times_called_matchers/at_most_matcher.rb +22 -0
  60. data/lib/rr/times_called_matchers/integer_matcher.rb +17 -0
  61. data/lib/rr/times_called_matchers/proc_matcher.rb +17 -0
  62. data/lib/rr/times_called_matchers/range_matcher.rb +19 -0
  63. data/lib/rr/times_called_matchers/times_called_matcher.rb +44 -0
  64. data/lib/rr/wildcard_matchers/anything.rb +13 -0
  65. data/lib/rr/wildcard_matchers/boolean.rb +18 -0
  66. data/lib/rr/wildcard_matchers/duck_type.rb +24 -0
  67. data/lib/rr/wildcard_matchers/is_a.rb +20 -0
  68. data/lib/rr/wildcard_matchers/numeric.rb +9 -0
  69. data/lib/rr/{expectations/wildcard_matchers → wildcard_matchers}/range.rb +0 -0
  70. data/lib/rr/{expectations/wildcard_matchers → wildcard_matchers}/regexp.rb +0 -0
  71. metadata +27 -9
  72. data/lib/rr/expectations/wildcard_matchers/anything.rb +0 -15
  73. data/lib/rr/expectations/wildcard_matchers/boolean.rb +0 -20
  74. data/lib/rr/expectations/wildcard_matchers/duck_type.rb +0 -26
  75. data/lib/rr/expectations/wildcard_matchers/is_a.rb +0 -22
  76. data/lib/rr/expectations/wildcard_matchers/numeric.rb +0 -11
@@ -1,5 +1,4 @@
1
- dir = File.dirname(__FILE__)
2
- require "#{dir}/../example_helper"
1
+ require "examples/example_helper"
3
2
 
4
3
  module RR
5
4
  describe Space, "#create_mock_creator" do
@@ -1,5 +1,4 @@
1
- dir = File.dirname(__FILE__)
2
- require "#{dir}/../example_helper"
1
+ require "examples/example_helper"
3
2
 
4
3
  module RR
5
4
  describe Space, " class" do
@@ -1,5 +1,4 @@
1
- dir = File.dirname(__FILE__)
2
- require "#{dir}/../example_helper"
1
+ require "examples/example_helper"
3
2
 
4
3
  module RR
5
4
  describe Space, "#register_ordered_scenario" do
@@ -1,7 +1,54 @@
1
- dir = File.dirname(__FILE__)
2
- require "#{dir}/../example_helper"
1
+ require "examples/example_helper"
3
2
 
4
3
  module RR
4
+ describe Space, "#reset" do
5
+ it_should_behave_like "RR::Space"
6
+
7
+ before do
8
+ @space = Space.new
9
+ @object1 = Object.new
10
+ @object2 = Object.new
11
+ @method_name = :foobar
12
+ end
13
+
14
+ it "removes the ordered scenarios" do
15
+ double1 = @space.create_double(@object1, :foobar1)
16
+ double2 = @space.create_double(@object1, :foobar2)
17
+
18
+ scenario1 = @space.create_scenario(double1)
19
+ scenario2 = @space.create_scenario(double2)
20
+
21
+ scenario1.ordered
22
+ scenario2.ordered
23
+
24
+ @space.ordered_scenarios.should_not be_empty
25
+
26
+ @space.reset
27
+ @space.ordered_scenarios.should be_empty
28
+ end
29
+
30
+ it "resets all doubles" do
31
+ double1 = @space.create_double(@object1, @method_name)
32
+ double1_reset_calls = 0
33
+ (class << double1; self; end).class_eval do
34
+ define_method(:reset) do ||
35
+ double1_reset_calls += 1
36
+ end
37
+ end
38
+ double2 = @space.create_double(@object2, @method_name)
39
+ double2_reset_calls = 0
40
+ (class << double2; self; end).class_eval do
41
+ define_method(:reset) do ||
42
+ double2_reset_calls += 1
43
+ end
44
+ end
45
+
46
+ @space.reset
47
+ double1_reset_calls.should == 1
48
+ double2_reset_calls.should == 1
49
+ end
50
+ end
51
+
5
52
  describe Space, "#reset_double" do
6
53
  it_should_behave_like "RR::Space"
7
54
 
@@ -65,9 +112,9 @@ describe Space, "#reset_doubles" do
65
112
  end
66
113
  end
67
114
 
68
- @space.reset_doubles
69
- double1_reset_calls.should == 1
115
+ @space.send(:reset_doubles)
70
116
  double1_reset_calls.should == 1
117
+ double2_reset_calls.should == 1
71
118
  end
72
119
  end
73
120
  end
@@ -1,5 +1,4 @@
1
- dir = File.dirname(__FILE__)
2
- require "#{dir}/../example_helper"
1
+ require "examples/example_helper"
3
2
 
4
3
  module RR
5
4
  describe Space, "#verify_doubles" do
@@ -110,19 +109,19 @@ describe Space, "#verify_ordered_scenario where the passed in scenario is at the
110
109
  @space.register_ordered_scenario(scenario)
111
110
 
112
111
  scenario.twice
113
- scenario.should_not be_times_called_verified
112
+ scenario.should be_attempt
114
113
 
115
114
  @space.verify_ordered_scenario(scenario)
116
115
  @space.ordered_scenarios.should include(scenario)
117
116
  end
118
117
 
119
- it "removes the scenario when times called in verified" do
118
+ it "removes the scenario when times called expectation should no longer be attempted" do
120
119
  scenario = @space.create_scenario(@double)
121
120
  @space.register_ordered_scenario(scenario)
122
121
 
123
122
  scenario.with(1).once
124
123
  @object.foobar(1)
125
- scenario.should be_times_called_verified
124
+ scenario.should_not be_attempt
126
125
 
127
126
  @space.verify_ordered_scenario(scenario)
128
127
  @space.ordered_scenarios.should_not include(scenario)
@@ -1,5 +1,4 @@
1
- dir = File.dirname(__FILE__)
2
- require "#{dir}/../example_helper"
1
+ require "examples/example_helper"
3
2
 
4
3
  module RR
5
4
  describe StubCreator, :shared => true do
@@ -1,5 +1,5 @@
1
1
  dir = File.dirname(__FILE__)
2
- require "#{dir}/../../environment_fixture_setup"
2
+ require "examples/environment_fixture_setup"
3
3
  require "rr/adapters/test_unit"
4
4
 
5
5
  require "test/unit"
@@ -0,0 +1,74 @@
1
+ require "examples/example_helper"
2
+
3
+ module RR
4
+ module TimesCalledMatchers
5
+ describe TimesCalledMatcher, ".create when passed a AtLeastMatcher" do
6
+ it "returns the passed in argument" do
7
+ matcher = AtLeastMatcher.new(5)
8
+ TimesCalledMatcher.create(matcher).should === matcher
9
+ end
10
+ end
11
+
12
+ describe AtLeastMatcher, "#possible_match?" do
13
+ before do
14
+ @times = 3
15
+ @matcher = AtLeastMatcher.new(@times)
16
+ end
17
+
18
+ it "always returns true" do
19
+ @matcher.should be_possible_match(99999)
20
+ end
21
+ end
22
+
23
+ describe AtLeastMatcher, "#matches?" do
24
+ before do
25
+ @times = 3
26
+ @matcher = AtLeastMatcher.new(@times)
27
+ end
28
+
29
+ it "returns false when times_called less than times" do
30
+ @matcher.should_not be_matches(2)
31
+ end
32
+
33
+ it "returns true when times_called == times" do
34
+ @matcher.should be_matches(3)
35
+ end
36
+
37
+ it "returns true when times_called > times" do
38
+ @matcher.should be_matches(4)
39
+ end
40
+ end
41
+
42
+ describe AtLeastMatcher, "#attempt?" do
43
+ before do
44
+ @times = 3
45
+ @matcher = AtLeastMatcher.new(@times)
46
+ end
47
+
48
+ it "returns true when less than expected times" do
49
+ @matcher.should be_attempt(2)
50
+ end
51
+
52
+ it "returns false when == expected times" do
53
+ @matcher.should_not be_attempt(3)
54
+ end
55
+
56
+ it "returns false when > expected times" do
57
+ @matcher.should_not be_attempt(4)
58
+ end
59
+ end
60
+
61
+ describe AtLeastMatcher, "#error_message" do
62
+ before do
63
+ @times = 3
64
+ @matcher = AtLeastMatcher.new(@times)
65
+ end
66
+
67
+ it "has an error message" do
68
+ @matcher.error_message(2).should == (
69
+ "Called 2 times. Expected at least 3 times."
70
+ )
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,82 @@
1
+ require "examples/example_helper"
2
+
3
+ module RR
4
+ module TimesCalledMatchers
5
+ describe TimesCalledMatcher, ".create when passed a AtMostMatcher" do
6
+ it "returns the passed in argument" do
7
+ matcher = AtMostMatcher.new(5)
8
+ TimesCalledMatcher.create(matcher).should === matcher
9
+ end
10
+ end
11
+
12
+ describe AtMostMatcher, "#possible_match?" do
13
+ before do
14
+ @times = 3
15
+ @matcher = AtMostMatcher.new(@times)
16
+ end
17
+
18
+ it "returns true when times called < times" do
19
+ @matcher.should be_possible_match(2)
20
+ end
21
+
22
+ it "returns true when times called == times" do
23
+ @matcher.should be_possible_match(3)
24
+ end
25
+
26
+ it "returns false when times called > times" do
27
+ @matcher.should_not be_possible_match(4)
28
+ end
29
+ end
30
+
31
+ describe AtMostMatcher, "#matches?" do
32
+ before do
33
+ @times = 3
34
+ @matcher = AtMostMatcher.new(@times)
35
+ end
36
+
37
+ it "returns true when times_called less than times" do
38
+ @matcher.should be_matches(2)
39
+ end
40
+
41
+ it "returns true when times_called == times" do
42
+ @matcher.should be_matches(3)
43
+ end
44
+
45
+ it "returns false when times_called > times" do
46
+ @matcher.should_not be_matches(4)
47
+ end
48
+ end
49
+
50
+ describe AtMostMatcher, "#attempt?" do
51
+ before do
52
+ @times = 3
53
+ @matcher = AtMostMatcher.new(@times)
54
+ end
55
+
56
+ it "returns true when less than expected times" do
57
+ @matcher.should be_attempt(2)
58
+ end
59
+
60
+ it "returns false when == expected times" do
61
+ @matcher.should_not be_attempt(3)
62
+ end
63
+
64
+ it "returns false when > expected times" do
65
+ @matcher.should_not be_attempt(4)
66
+ end
67
+ end
68
+
69
+ describe AtMostMatcher, "#error_message" do
70
+ before do
71
+ @times = 3
72
+ @matcher = AtMostMatcher.new(@times)
73
+ end
74
+
75
+ it "has an error message" do
76
+ @matcher.error_message(5).should == (
77
+ "Called 5 times. Expected at most 3 times."
78
+ )
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,88 @@
1
+ require "examples/example_helper"
2
+
3
+ module RR
4
+ module TimesCalledMatchers
5
+ describe TimesCalledMatcher, ".create when passed a IntegerMatcher" do
6
+ it "returns the passed in argument" do
7
+ matcher = IntegerMatcher.new(5)
8
+ TimesCalledMatcher.create(matcher).should === matcher
9
+ end
10
+ end
11
+
12
+ describe TimesCalledMatcher, ".create when passed a Integer" do
13
+ it "returns IntegerMatcher" do
14
+ TimesCalledMatcher.create(5).should == IntegerMatcher.new(5)
15
+ end
16
+ end
17
+
18
+ describe IntegerMatcher, "#possible_match?" do
19
+ before do
20
+ @times = 3
21
+ @matcher = IntegerMatcher.new(@times)
22
+ end
23
+
24
+ it "returns true when times called < times" do
25
+ @matcher.should be_possible_match(2)
26
+ end
27
+
28
+ it "returns true when times called == times" do
29
+ @matcher.should be_possible_match(3)
30
+ end
31
+
32
+ it "returns false when times called > times" do
33
+ @matcher.should_not be_possible_match(4)
34
+ end
35
+ end
36
+
37
+ describe IntegerMatcher, "#matches?" do
38
+ before do
39
+ @times = 3
40
+ @matcher = IntegerMatcher.new(@times)
41
+ end
42
+
43
+ it "returns false when times_called less than times" do
44
+ @matcher.should_not be_matches(2)
45
+ end
46
+
47
+ it "returns true when times_called == times" do
48
+ @matcher.should be_matches(3)
49
+ end
50
+
51
+ it "returns false when times_called > times" do
52
+ @matcher.should_not be_matches(4)
53
+ end
54
+ end
55
+
56
+ describe IntegerMatcher, "#attempt?" do
57
+ before do
58
+ @times = 3
59
+ @matcher = IntegerMatcher.new(@times)
60
+ end
61
+
62
+ it "returns true when less than expected times" do
63
+ @matcher.should be_attempt(2)
64
+ end
65
+
66
+ it "returns false when == expected times" do
67
+ @matcher.should_not be_attempt(3)
68
+ end
69
+
70
+ it "returns false when > expected times" do
71
+ @matcher.should_not be_attempt(4)
72
+ end
73
+ end
74
+
75
+ describe IntegerMatcher, "#error_message" do
76
+ before do
77
+ @times = 3
78
+ @matcher = IntegerMatcher.new(@times)
79
+ end
80
+
81
+ it "has an error message" do
82
+ @matcher.error_message(2).should == (
83
+ "Called 2 times. Expected 3 times."
84
+ )
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,74 @@
1
+ require "examples/example_helper"
2
+
3
+ module RR
4
+ module TimesCalledMatchers
5
+ describe TimesCalledMatcher, ".create when passed a ProcMatcher" do
6
+ it "returns the passed in argument" do
7
+ matcher = ProcMatcher.new(proc {|other| other == 5})
8
+ TimesCalledMatcher.create(matcher).should === matcher
9
+ end
10
+ end
11
+
12
+ describe TimesCalledMatcher, ".create when passed a Integer" do
13
+ it "returns ProcMatcher" do
14
+ value = proc {|other| other == 5}
15
+ TimesCalledMatcher.create(value).should == ProcMatcher.new(value)
16
+ end
17
+ end
18
+
19
+ describe ProcMatcher, "#possible_match?" do
20
+ before do
21
+ @times = proc {|other| other == 3}
22
+ @matcher = ProcMatcher.new(@times)
23
+ end
24
+
25
+ it "always returns true" do
26
+ @matcher.should be_possible_match(2)
27
+ @matcher.should be_possible_match(3)
28
+ @matcher.should be_possible_match(10)
29
+ end
30
+ end
31
+
32
+ describe ProcMatcher, "#matches?" do
33
+ before do
34
+ @times = proc {|other| other == 3}
35
+ @matcher = ProcMatcher.new(@times)
36
+ end
37
+
38
+ it "returns false when proc returns false" do
39
+ @times.call(2).should be_false
40
+ @matcher.should_not be_matches(2)
41
+ end
42
+
43
+ it "returns true when proc returns true" do
44
+ @times.call(3).should be_true
45
+ @matcher.should be_matches(3)
46
+ end
47
+ end
48
+
49
+ describe ProcMatcher, "#attempt?" do
50
+ before do
51
+ @times = proc {|other| other == 3}
52
+ @matcher = ProcMatcher.new(@times)
53
+ end
54
+
55
+ it "always returns true" do
56
+ @matcher.should be_attempt(2)
57
+ @matcher.should be_attempt(3)
58
+ @matcher.should be_attempt(10)
59
+ end
60
+ end
61
+
62
+ describe ProcMatcher, "#error_message" do
63
+ before do
64
+ @times = proc {|other| other == 3}
65
+ @matcher = ProcMatcher.new(@times)
66
+ end
67
+
68
+ it "has an error message" do
69
+ @matcher.error_message(1).should =~
70
+ /Called 1 time. Expected #<Proc.*> times./
71
+ end
72
+ end
73
+ end
74
+ end