rr 0.4.10 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. data/CHANGES +14 -0
  2. data/README.rdoc +67 -13
  3. data/Rakefile +1 -1
  4. data/lib/rr.rb +29 -9
  5. data/lib/rr/adapters/rr_methods.rb +38 -158
  6. data/lib/rr/double.rb +46 -41
  7. data/lib/rr/double_definitions/child_double_definition_creator.rb +23 -0
  8. data/lib/rr/double_definitions/double_definition.rb +212 -0
  9. data/lib/rr/double_definitions/double_definition_creator.rb +153 -0
  10. data/lib/rr/double_definitions/double_definition_creator_proxy.rb +25 -0
  11. data/lib/rr/double_definitions/strategies/implementation/implementation_strategy.rb +15 -0
  12. data/lib/rr/double_definitions/strategies/implementation/proxy.rb +62 -0
  13. data/lib/rr/double_definitions/strategies/implementation/reimplementation.rb +14 -0
  14. data/lib/rr/double_definitions/strategies/scope/instance.rb +15 -0
  15. data/lib/rr/double_definitions/strategies/scope/instance_of_class.rb +43 -0
  16. data/lib/rr/double_definitions/strategies/scope/scope_strategy.rb +15 -0
  17. data/lib/rr/double_definitions/strategies/strategy.rb +70 -0
  18. data/lib/rr/double_definitions/strategies/verification/dont_allow.rb +34 -0
  19. data/lib/rr/double_definitions/strategies/verification/mock.rb +44 -0
  20. data/lib/rr/double_definitions/strategies/verification/stub.rb +45 -0
  21. data/lib/rr/double_definitions/strategies/verification/verification_strategy.rb +15 -0
  22. data/lib/rr/double_injection.rb +21 -15
  23. data/lib/rr/expectations/argument_equality_expectation.rb +2 -1
  24. data/lib/rr/space.rb +23 -22
  25. data/lib/rr/wildcard_matchers/hash_including.rb +29 -0
  26. data/lib/rr/wildcard_matchers/satisfy.rb +26 -0
  27. data/spec/high_level_spec.rb +111 -64
  28. data/spec/rr/adapters/rr_methods_argument_matcher_spec.rb +1 -1
  29. data/spec/rr/adapters/rr_methods_creator_spec.rb +99 -315
  30. data/spec/rr/adapters/rr_methods_space_spec.rb +90 -109
  31. data/spec/rr/adapters/rr_methods_spec_helper.rb +1 -1
  32. data/spec/rr/adapters/rr_methods_times_matcher_spec.rb +1 -1
  33. data/spec/rr/double_definitions/child_double_definition_creator_spec.rb +103 -0
  34. data/spec/rr/double_definitions/double_definition_creator_proxy_spec.rb +83 -0
  35. data/spec/rr/double_definitions/double_definition_creator_spec.rb +495 -0
  36. data/spec/rr/double_definitions/double_definition_spec.rb +1116 -0
  37. data/spec/rr/double_injection/double_injection_bind_spec.rb +111 -0
  38. data/spec/rr/double_injection/double_injection_dispatching_spec.rb +245 -0
  39. data/spec/rr/{double → double_injection}/double_injection_has_original_method_spec.rb +9 -9
  40. data/spec/rr/double_injection/double_injection_reset_spec.rb +90 -0
  41. data/spec/rr/double_injection/double_injection_spec.rb +77 -0
  42. data/spec/rr/double_injection/double_injection_verify_spec.rb +29 -0
  43. data/spec/rr/double_spec.rb +156 -136
  44. data/spec/rr/errors/rr_error_spec.rb +1 -1
  45. data/spec/rr/expectations/any_argument_expectation_spec.rb +1 -1
  46. data/spec/rr/expectations/anything_argument_equality_expectation_spec.rb +6 -30
  47. data/spec/rr/expectations/argument_equality_expectation_spec.rb +35 -18
  48. data/spec/rr/expectations/boolean_argument_equality_expectation_spec.rb +22 -41
  49. data/spec/rr/expectations/hash_including_argument_equality_expectation_spec.rb +82 -0
  50. data/spec/rr/expectations/hash_including_spec.rb +17 -0
  51. data/spec/rr/expectations/satisfy_argument_equality_expectation_spec.rb +59 -0
  52. data/spec/rr/expectations/satisfy_spec.rb +14 -0
  53. data/spec/rr/expectations/times_called_expectation/times_called_expectation_any_times_spec.rb +30 -28
  54. data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_least_spec.rb +55 -54
  55. data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_most_spec.rb +49 -48
  56. data/spec/rr/expectations/times_called_expectation/times_called_expectation_helper.rb +9 -7
  57. data/spec/rr/expectations/times_called_expectation/times_called_expectation_integer_spec.rb +77 -76
  58. data/spec/rr/expectations/times_called_expectation/times_called_expectation_proc_spec.rb +58 -57
  59. data/spec/rr/expectations/times_called_expectation/times_called_expectation_range_spec.rb +59 -58
  60. data/spec/rr/expectations/times_called_expectation/times_called_expectation_spec.rb +25 -24
  61. data/spec/rr/rspec/rspec_adapter_spec.rb +12 -11
  62. data/spec/rr/rspec/rspec_backtrace_tweaking_spec.rb +10 -8
  63. data/spec/rr/rspec/rspec_usage_spec.rb +1 -1
  64. data/spec/rr/space/hash_with_object_id_key_spec.rb +1 -1
  65. data/spec/rr/space/space_spec.rb +330 -192
  66. data/spec/rr/test_unit/test_helper.rb +1 -2
  67. data/spec/rr/test_unit/test_unit_backtrace_test.rb +1 -2
  68. data/spec/rr/test_unit/test_unit_integration_test.rb +1 -2
  69. data/spec/rr/times_called_matchers/any_times_matcher_spec.rb +1 -1
  70. data/spec/rr/times_called_matchers/at_least_matcher_spec.rb +1 -1
  71. data/spec/rr/times_called_matchers/at_most_matcher_spec.rb +1 -1
  72. data/spec/rr/times_called_matchers/integer_matcher_spec.rb +1 -1
  73. data/spec/rr/times_called_matchers/proc_matcher_spec.rb +1 -1
  74. data/spec/rr/times_called_matchers/range_matcher_spec.rb +1 -1
  75. data/spec/rr/times_called_matchers/times_called_matcher_spec.rb +1 -1
  76. data/spec/rr/wildcard_matchers/anything_spec.rb +24 -0
  77. data/spec/rr/wildcard_matchers/boolean_spec.rb +36 -0
  78. data/spec/rr/wildcard_matchers/duck_type_spec.rb +52 -0
  79. data/spec/rr/wildcard_matchers/is_a_spec.rb +32 -0
  80. data/spec/rr/wildcard_matchers/numeric_spec.rb +32 -0
  81. data/spec/rr/wildcard_matchers/range_spec.rb +35 -0
  82. data/spec/rr/wildcard_matchers/regexp_spec.rb +43 -0
  83. data/spec/rr_spec.rb +28 -0
  84. data/spec/spec_helper.rb +84 -0
  85. metadata +43 -29
  86. data/lib/rr/double_creator.rb +0 -271
  87. data/lib/rr/double_definition.rb +0 -179
  88. data/lib/rr/double_definition_builder.rb +0 -44
  89. data/lib/rr/double_definition_creator.rb +0 -156
  90. data/lib/rr/double_definition_creator_proxy.rb +0 -20
  91. data/spec/rr/double/double_injection_bind_spec.rb +0 -105
  92. data/spec/rr/double/double_injection_dispatching_spec.rb +0 -228
  93. data/spec/rr/double/double_injection_reset_spec.rb +0 -86
  94. data/spec/rr/double/double_injection_spec.rb +0 -72
  95. data/spec/rr/double/double_injection_verify_spec.rb +0 -24
  96. data/spec/rr/double_definition_creator_proxy_spec.rb +0 -85
  97. data/spec/rr/double_definition_creator_spec.rb +0 -496
  98. data/spec/rr/double_definition_spec.rb +0 -815
  99. data/spec/rr/expectations/anything_spec.rb +0 -14
  100. data/spec/rr/expectations/boolean_spec.rb +0 -14
  101. data/spec/rr/expectations/duck_type_argument_equality_expectation_spec.rb +0 -71
  102. data/spec/rr/expectations/duck_type_spec.rb +0 -14
  103. data/spec/rr/expectations/is_a_argument_equality_expectation_spec.rb +0 -51
  104. data/spec/rr/expectations/is_a_spec.rb +0 -14
  105. data/spec/rr/expectations/numeric_argument_equality_expectation_spec.rb +0 -47
  106. data/spec/rr/expectations/numeric_spec.rb +0 -14
  107. data/spec/rr/expectations/range_argument_equality_expectation_spec.rb +0 -59
  108. data/spec/rr/expectations/range_spec.rb +0 -10
  109. data/spec/rr/expectations/regexp_argument_equality_expectation_spec.rb +0 -72
  110. data/spec/rr/expectations/regexp_spec.rb +0 -10
@@ -1,67 +1,68 @@
1
- require "spec/spec_helper"
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../../spec_helper")
2
2
 
3
3
  module RR
4
- module Expectations
5
- describe TimesCalledExpectation, ' with AtLeastMatcher' do
6
- it_should_behave_like "RR::Expectations::TimesCalledExpectation"
7
- attr_reader :times, :at_least
8
-
9
- before do
10
- @times = 3
11
- @at_least = TimesCalledMatchers::AtLeastMatcher.new(times)
12
- @expectation = TimesCalledExpectation.new(double, at_least)
13
- end
14
-
15
- describe "#verify!" do
16
- it "passes when times called > times" do
17
- 4.times {expectation.attempt}
18
- expectation.verify!
19
- end
4
+ module Expectations
5
+ describe TimesCalledExpectation do
6
+ context "when using an AtLeastMatcher" do
7
+ it_should_behave_like "RR::Expectations::TimesCalledExpectation"
8
+ attr_reader :times, :at_least, :expectation
20
9
 
21
- it "passes when times called == times" do
22
- 3.times {expectation.attempt}
23
- expectation.verify!
24
- end
10
+ before do
11
+ @times = 3
12
+ @at_least = TimesCalledMatchers::AtLeastMatcher.new(times)
13
+ @expectation = TimesCalledExpectation.new(double, at_least)
14
+ end
25
15
 
26
- it "raises error when times called < times" do
27
- expectation.attempt
28
- lambda do
29
- expectation.verify!
30
- end.should raise_error(
31
- RR::Errors::TimesCalledError,
32
- "foobar()\nCalled 1 time.\nExpected at least 3 times."
33
- )
34
- end
35
- end
16
+ describe "#verify!" do
17
+ it "passes when times called > times" do
18
+ 4.times {expectation.attempt}
19
+ expectation.verify!
20
+ end
36
21
 
37
- describe "#attempt?" do
38
- it "always returns true" do
39
- expectation.should be_attempt
40
- 10.times {expectation.attempt}
41
- expectation.should be_attempt
42
- end
43
- end
22
+ it "passes when times called == times" do
23
+ 3.times {expectation.attempt}
24
+ expectation.verify!
25
+ end
44
26
 
45
- describe "#attempt!" do
46
- it "passes when times called more than times" do
47
- 4.times {expectation.attempt}
48
- end
27
+ it "raises error when times called < times" do
28
+ expectation.attempt
29
+ lambda do
30
+ expectation.verify!
31
+ end.should raise_error(
32
+ RR::Errors::TimesCalledError,
33
+ "foobar()\nCalled 1 time.\nExpected at least 3 times."
34
+ )
35
+ end
36
+ end
49
37
 
50
- it "passes when times called == times" do
51
- 3.times {expectation.attempt}
52
- end
38
+ describe "#attempt?" do
39
+ it "always returns true" do
40
+ expectation.should be_attempt
41
+ 10.times {expectation.attempt}
42
+ expectation.should be_attempt
43
+ end
44
+ end
53
45
 
54
- it "passes when times called < times" do
55
- expectation.attempt
56
- end
57
- end
46
+ describe "#attempt!" do
47
+ it "passes when times called more than times" do
48
+ 4.times {expectation.attempt}
49
+ end
58
50
 
59
- describe "#terminal?" do
60
- it "returns false" do
61
- expectation.should_not be_terminal
51
+ it "passes when times called == times" do
52
+ 3.times {expectation.attempt}
53
+ end
54
+
55
+ it "passes when times called < times" do
56
+ expectation.attempt
57
+ end
58
+ end
59
+
60
+ describe "#terminal?" do
61
+ it "returns false" do
62
+ expectation.should_not be_terminal
63
+ end
64
+ end
62
65
  end
63
66
  end
64
67
  end
65
-
66
- end
67
68
  end
@@ -1,69 +1,70 @@
1
- require "spec/spec_helper"
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../../spec_helper")
2
2
 
3
3
  module RR
4
4
  module Expectations
5
- describe TimesCalledExpectation, ' with AtMostMatcher' do
6
- it_should_behave_like "RR::Expectations::TimesCalledExpectation"
7
- attr_reader :times, :at_most
5
+ describe TimesCalledExpectation do
6
+ context "when using an AtMostMatcher" do
7
+ it_should_behave_like "RR::Expectations::TimesCalledExpectation"
8
+ attr_reader :times, :at_most, :expectation
8
9
 
9
- before do
10
- @times = 3
11
- @at_most = TimesCalledMatchers::AtMostMatcher.new(times)
12
- @expectation = TimesCalledExpectation.new(double, at_most)
13
- end
14
-
15
- describe "#verify!" do
16
- it "returns true when times called == times" do
17
- 3.times {expectation.attempt}
18
- expectation.verify!
10
+ before do
11
+ @times = 3
12
+ @at_most = TimesCalledMatchers::AtMostMatcher.new(times)
13
+ @expectation = TimesCalledExpectation.new(double, at_most)
19
14
  end
20
15
 
21
- it "raises error when times called < times" do
22
- 2.times {expectation.attempt}
23
- expectation.verify!
24
- end
25
- end
16
+ describe "#verify!" do
17
+ it "returns true when times called == times" do
18
+ 3.times {expectation.attempt}
19
+ expectation.verify!
20
+ end
26
21
 
27
- describe "#attempt?" do
28
- it "returns true when attempted less than expected times" do
29
- 2.times {expectation.attempt}
30
- expectation.should be_attempt
22
+ it "raises error when times called < times" do
23
+ 2.times {expectation.attempt}
24
+ expectation.verify!
25
+ end
31
26
  end
32
27
 
33
- it "returns false when attempted expected times" do
34
- 3.times {expectation.attempt}
35
- expectation.should_not be_attempt
36
- end
28
+ describe "#attempt?" do
29
+ it "returns true when attempted less than expected times" do
30
+ 2.times {expectation.attempt}
31
+ expectation.should be_attempt
32
+ end
37
33
 
38
- it "raises error before attempted more than expected times" do
39
- 3.times {expectation.attempt}
40
- lambda {expectation.attempt}.should raise_error( Errors::TimesCalledError )
41
- end
42
- end
34
+ it "returns false when attempted expected times" do
35
+ 3.times {expectation.attempt}
36
+ expectation.should_not be_attempt
37
+ end
43
38
 
44
- describe "#attempt!" do
45
- it "fails when times called more than times" do
46
- 3.times {expectation.attempt}
47
- lambda do
48
- expectation.attempt
49
- end.should raise_error(Errors::TimesCalledError, "foobar()\nCalled 4 times.\nExpected at most 3 times.")
39
+ it "raises error before attempted more than expected times" do
40
+ 3.times {expectation.attempt}
41
+ lambda {expectation.attempt}.should raise_error( Errors::TimesCalledError )
42
+ end
50
43
  end
51
44
 
52
- it "passes when times called == times" do
53
- 3.times {expectation.attempt}
54
- end
45
+ describe "#attempt!" do
46
+ it "fails when times called more than times" do
47
+ 3.times {expectation.attempt}
48
+ lambda do
49
+ expectation.attempt
50
+ end.should raise_error(Errors::TimesCalledError, "foobar()\nCalled 4 times.\nExpected at most 3 times.")
51
+ end
52
+
53
+ it "passes when times called == times" do
54
+ 3.times {expectation.attempt}
55
+ end
55
56
 
56
- it "passes when times called < times" do
57
- expectation.attempt
57
+ it "passes when times called < times" do
58
+ expectation.attempt
59
+ end
58
60
  end
59
- end
60
61
 
61
- describe "#terminal?" do
62
- it "returns true" do
63
- expectation.should be_terminal
62
+ describe "#terminal?" do
63
+ it "returns true" do
64
+ expectation.should be_terminal
65
+ end
64
66
  end
65
67
  end
66
68
  end
67
-
68
69
  end
69
70
  end
@@ -1,15 +1,17 @@
1
- require "spec/spec_helper"
2
-
3
1
  module RR
4
2
  module Expectations
5
3
  describe TimesCalledExpectation, :shared => true do
6
- attr_reader :space, :object, :method_name, :double_injection, :double, :expectation
4
+ attr_reader :space, :subject, :method_name, :double_injection, :double, :double_definition
5
+ it_should_behave_like "Swapped Space"
7
6
  before do
8
- @space = Space.new
9
- @object = Object.new
7
+ @subject = Object.new
10
8
  @method_name = :foobar
11
- @double_injection = space.double_injection(object, method_name)
12
- @double = Double.new(double_injection)
9
+ @double_injection = space.double_injection(subject, method_name)
10
+ @double_definition = DoubleDefinitions::DoubleDefinition.new(
11
+ DoubleDefinitions::DoubleDefinitionCreator.new,
12
+ subject
13
+ )
14
+ @double = new_double(double_injection)
13
15
  double.with_any_args
14
16
  end
15
17
 
@@ -1,103 +1,104 @@
1
- require "spec/spec_helper"
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../../spec_helper")
2
2
 
3
3
  module RR
4
4
  module Expectations
5
- describe TimesCalledExpectation, " with IntegerMatcher" do
6
- it_should_behave_like "RR::Expectations::TimesCalledExpectation"
7
- attr_reader :matcher, :expected_line
5
+ describe TimesCalledExpectation do
6
+ context "when using an IntegerMatcher" do
7
+ it_should_behave_like "RR::Expectations::TimesCalledExpectation"
8
+ attr_reader :matcher, :expected_line, :expectation
8
9
 
9
- before do
10
- @matcher = TimesCalledMatchers::IntegerMatcher.new(2)
11
- @expectation = TimesCalledExpectation.new(double, matcher)
12
- @expected_line = __LINE__ - 1
13
- end
14
-
15
- describe "#verify" do
16
- it "returns true when times called exactly matches an integer" do
17
- expectation.verify.should == false
18
- expectation.attempt
19
- expectation.verify.should == false
20
- expectation.attempt
21
- expectation.verify.should == true
10
+ before do
11
+ @matcher = TimesCalledMatchers::IntegerMatcher.new(2)
12
+ @expectation = TimesCalledExpectation.new(double, matcher)
13
+ @expected_line = __LINE__ - 1
22
14
  end
23
- end
24
15
 
25
- describe "#verify! when passed an Integer (2)" do
26
- it "passes after attempt! called 2 times" do
27
- expectation.attempt
28
- expectation.attempt
29
- expectation.verify!
16
+ describe "#verify" do
17
+ it "returns true when times called exactly matches an integer" do
18
+ expectation.verify.should == false
19
+ expectation.attempt
20
+ expectation.verify.should == false
21
+ expectation.attempt
22
+ expectation.verify.should == true
23
+ end
30
24
  end
31
25
 
32
- it "fails after attempt! called 1 time" do
33
- expectation.attempt
34
- lambda {expectation.verify!}.should raise_error(
35
- Errors::TimesCalledError,
36
- "foobar()\nCalled 1 time.\nExpected 2 times."
37
- )
38
- end
26
+ describe "#verify! when passed an Integer (2)" do
27
+ it "passes after attempt! called 2 times" do
28
+ expectation.attempt
29
+ expectation.attempt
30
+ expectation.verify!
31
+ end
39
32
 
40
- it "can't be called when attempt! is called 3 times" do
41
- expectation.attempt
42
- expectation.attempt
43
- lambda do
33
+ it "fails after attempt! called 1 time" do
44
34
  expectation.attempt
45
- end.should raise_error(Errors::TimesCalledError, "foobar()\nCalled 3 times.\nExpected 2 times.")
46
- end
35
+ lambda {expectation.verify!}.should raise_error(
36
+ Errors::TimesCalledError,
37
+ "foobar()\nCalled 1 time.\nExpected 2 times."
38
+ )
39
+ end
47
40
 
48
- it "has a backtrace to where the TimesCalledExpectation was instantiated on failure" do
49
- error = nil
50
- begin
51
- expectation.verify!
52
- rescue Errors::TimesCalledError => e
53
- error = e
41
+ it "can't be called when attempt! is called 3 times" do
42
+ expectation.attempt
43
+ expectation.attempt
44
+ lambda do
45
+ expectation.attempt
46
+ end.should raise_error(Errors::TimesCalledError, "foobar()\nCalled 3 times.\nExpected 2 times.")
54
47
  end
55
- e.backtrace.first.should include(__FILE__)
56
- e.backtrace.first.should include(":#{expected_line}")
57
- end
58
48
 
59
- it "has an error message that includes the number of times called and expected number of times" do
60
- lambda do
61
- expectation.verify!
62
- end.should raise_error(Errors::TimesCalledError, "foobar()\nCalled 0 times.\nExpected 2 times.")
63
- end
64
- end
49
+ it "has a backtrace to where the TimesCalledExpectation was instantiated on failure" do
50
+ error = nil
51
+ begin
52
+ expectation.verify!
53
+ rescue Errors::TimesCalledError => e
54
+ error = e
55
+ end
56
+ e.backtrace.first.should include(__FILE__)
57
+ e.backtrace.first.should include(":#{expected_line}")
58
+ end
65
59
 
66
- describe "#attempt?" do
67
- it "returns true when attempted less than expected times" do
68
- 1.times {expectation.attempt}
69
- expectation.should be_attempt
60
+ it "has an error message that includes the number of times called and expected number of times" do
61
+ lambda do
62
+ expectation.verify!
63
+ end.should raise_error(Errors::TimesCalledError, "foobar()\nCalled 0 times.\nExpected 2 times.")
64
+ end
70
65
  end
71
66
 
72
- it "returns false when attempted expected times" do
73
- 2.times {expectation.attempt}
74
- expectation.should_not be_attempt
75
- end
67
+ describe "#attempt?" do
68
+ it "returns true when attempted less than expected times" do
69
+ 1.times {expectation.attempt}
70
+ expectation.should be_attempt
71
+ end
72
+
73
+ it "returns false when attempted expected times" do
74
+ 2.times {expectation.attempt}
75
+ expectation.should_not be_attempt
76
+ end
76
77
 
77
- it "raises error before attempted more than expected times" do
78
- 2.times {expectation.attempt}
79
- lambda {expectation.attempt}.should raise_error(
80
- Errors::TimesCalledError
81
- )
78
+ it "raises error before attempted more than expected times" do
79
+ 2.times {expectation.attempt}
80
+ lambda {expectation.attempt}.should raise_error(
81
+ Errors::TimesCalledError
82
+ )
83
+ end
82
84
  end
83
- end
84
85
 
85
- describe "#attempt! for an IntegerMatcher" do
86
- it "raises error when attempt! called more than the expected number of times" do
87
- expectation.attempt
88
- expectation.attempt
89
- lambda do
86
+ describe "#attempt! for an IntegerMatcher" do
87
+ it "raises error when attempt! called more than the expected number of times" do
88
+ expectation.attempt
90
89
  expectation.attempt
91
- end.should raise_error(Errors::TimesCalledError)
90
+ lambda do
91
+ expectation.attempt
92
+ end.should raise_error(Errors::TimesCalledError)
93
+ end
92
94
  end
93
- end
94
95
 
95
- describe "#terminal?" do
96
- it "returns true" do
97
- expectation.should be_terminal
96
+ describe "#terminal?" do
97
+ it "returns true" do
98
+ expectation.should be_terminal
99
+ end
98
100
  end
99
101
  end
100
102
  end
101
-
102
103
  end
103
104
  end
@@ -1,79 +1,80 @@
1
- require "spec/spec_helper"
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../../spec_helper")
2
2
 
3
3
  module RR
4
4
  module Expectations
5
- describe TimesCalledExpectation, " with ProcMatcher" do
6
- it_should_behave_like "RR::Expectations::TimesCalledExpectation"
7
- attr_reader :matcher
5
+ describe TimesCalledExpectation do
6
+ context "when using a ProcMatcher" do
7
+ it_should_behave_like "RR::Expectations::TimesCalledExpectation"
8
+ attr_reader :matcher, :expectation
8
9
 
9
- before do
10
- @matcher = TimesCalledMatchers::ProcMatcher.new(lambda {|value| value == 2})
11
- @expectation = TimesCalledExpectation.new(double, matcher)
12
- end
13
-
14
- describe "#verify" do
15
- it "matches a block" do
16
- expectation.verify.should == false
17
- expectation.attempt
18
- expectation.verify.should == false
19
- expectation.attempt
20
- expectation.verify.should == true
21
- expectation.attempt
22
- expectation.verify.should == false
10
+ before do
11
+ @matcher = TimesCalledMatchers::ProcMatcher.new(lambda {|value| value == 2})
12
+ @expectation = TimesCalledExpectation.new(double, matcher)
23
13
  end
24
- end
25
14
 
26
- describe "#verify! when passed a block (== 2 times)" do
27
- it "passes after attempt! called 2 times" do
28
- expectation.attempt
29
- expectation.attempt
30
- expectation.verify!
15
+ describe "#verify" do
16
+ it "matches a block" do
17
+ expectation.verify.should == false
18
+ expectation.attempt
19
+ expectation.verify.should == false
20
+ expectation.attempt
21
+ expectation.verify.should == true
22
+ expectation.attempt
23
+ expectation.verify.should == false
24
+ end
31
25
  end
32
26
 
33
- it "fails after attempt! called 1 time" do
34
- expectation.attempt
35
- lambda {expectation.verify!}.should raise_error(Errors::TimesCalledError)
36
- end
27
+ describe "#verify! when passed a block (== 2 times)" do
28
+ it "passes after attempt! called 2 times" do
29
+ expectation.attempt
30
+ expectation.attempt
31
+ expectation.verify!
32
+ end
37
33
 
38
- it "fails after attempt! called 3 times" do
39
- expectation.attempt
40
- expectation.attempt
41
- expectation.attempt
42
- lambda {expectation.verify!}.should raise_error(Errors::TimesCalledError)
43
- end
44
- end
34
+ it "fails after attempt! called 1 time" do
35
+ expectation.attempt
36
+ lambda {expectation.verify!}.should raise_error(Errors::TimesCalledError)
37
+ end
45
38
 
46
- describe "#attempt? with IntegerMatcher" do
47
- it "returns true when attempted less than expected times" do
48
- 1.times {expectation.attempt}
49
- expectation.should be_attempt
39
+ it "fails after attempt! called 3 times" do
40
+ expectation.attempt
41
+ expectation.attempt
42
+ expectation.attempt
43
+ lambda {expectation.verify!}.should raise_error(Errors::TimesCalledError)
44
+ end
50
45
  end
51
46
 
52
- it "returns true when attempted expected times" do
53
- 2.times {expectation.attempt}
54
- expectation.should be_attempt
55
- end
47
+ describe "#attempt? with IntegerMatcher" do
48
+ it "returns true when attempted less than expected times" do
49
+ 1.times {expectation.attempt}
50
+ expectation.should be_attempt
51
+ end
52
+
53
+ it "returns true when attempted expected times" do
54
+ 2.times {expectation.attempt}
55
+ expectation.should be_attempt
56
+ end
56
57
 
57
- it "returns true when attempted more than expected times" do
58
- 3.times {expectation.attempt}
59
- expectation.should be_attempt
58
+ it "returns true when attempted more than expected times" do
59
+ 3.times {expectation.attempt}
60
+ expectation.should be_attempt
61
+ end
60
62
  end
61
- end
62
63
 
63
- describe "#attempt! for a lambda expectation" do
64
- it "lets everything pass" do
65
- @object.foobar
66
- @object.foobar
67
- @object.foobar
64
+ describe "#attempt! for a lambda expectation" do
65
+ it "lets everything pass" do
66
+ @subject.foobar
67
+ @subject.foobar
68
+ @subject.foobar
69
+ end
68
70
  end
69
- end
70
71
 
71
- describe "#terminal? with ProcMatcher" do
72
- it "returns false" do
73
- expectation.should_not be_terminal
72
+ describe "#terminal? with ProcMatcher" do
73
+ it "returns false" do
74
+ expectation.should_not be_terminal
75
+ end
74
76
  end
75
77
  end
76
78
  end
77
-
78
79
  end
79
80
  end