rr 0.3.11 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (150) hide show
  1. data/CHANGES +8 -3
  2. data/README +130 -39
  3. data/Rakefile +6 -5
  4. data/lib/rr.rb +8 -8
  5. data/lib/rr/adapters/rr_methods.rb +228 -0
  6. data/lib/rr/adapters/rspec.rb +1 -1
  7. data/lib/rr/adapters/test_unit.rb +1 -1
  8. data/lib/rr/double.rb +294 -89
  9. data/lib/rr/{scenario_creator.rb → double_creator.rb} +65 -66
  10. data/lib/rr/{scenario_definition.rb → double_definition.rb} +36 -36
  11. data/lib/rr/{scenario_definition_builder.rb → double_definition_builder.rb} +3 -3
  12. data/lib/rr/double_insertion.rb +132 -0
  13. data/lib/rr/{scenario_matches.rb → double_matches.rb} +2 -2
  14. data/lib/rr/{scenario_method_proxy.rb → double_method_proxy.rb} +2 -2
  15. data/lib/rr/errors/argument_equality_error.rb +3 -3
  16. data/lib/rr/errors/rr_error.rb +13 -13
  17. data/lib/rr/errors/scenario_definition_error.rb +3 -3
  18. data/lib/rr/errors/scenario_not_found_error.rb +3 -3
  19. data/lib/rr/errors/scenario_order_error.rb +3 -3
  20. data/lib/rr/errors/times_called_error.rb +3 -3
  21. data/lib/rr/expectations/any_argument_expectation.rb +1 -1
  22. data/lib/rr/expectations/argument_equality_expectation.rb +1 -1
  23. data/lib/rr/expectations/times_called_expectation.rb +1 -1
  24. data/lib/rr/hash_with_object_id_key.rb +1 -1
  25. data/lib/rr/space.rb +40 -40
  26. data/lib/rr/times_called_matchers/any_times_matcher.rb +13 -13
  27. data/lib/rr/times_called_matchers/at_least_matcher.rb +11 -11
  28. data/lib/rr/times_called_matchers/at_most_matcher.rb +16 -16
  29. data/lib/rr/times_called_matchers/integer_matcher.rb +13 -13
  30. data/lib/rr/times_called_matchers/non_terminal.rb +21 -21
  31. data/lib/rr/times_called_matchers/proc_matcher.rb +7 -7
  32. data/lib/rr/times_called_matchers/range_matcher.rb +14 -14
  33. data/lib/rr/times_called_matchers/terminal.rb +16 -16
  34. data/lib/rr/times_called_matchers/times_called_matcher.rb +32 -32
  35. data/spec/core_spec_suite.rb +18 -0
  36. data/{examples → spec}/environment_fixture_setup.rb +0 -1
  37. data/{examples/high_level_example.rb → spec/high_level_spec.rb} +11 -11
  38. data/spec/rr/adapters/rr_methods_argument_matcher_spec.rb +67 -0
  39. data/spec/rr/adapters/rr_methods_creator_spec.rb +365 -0
  40. data/spec/rr/adapters/rr_methods_space_spec.rb +134 -0
  41. data/spec/rr/adapters/rr_methods_spec_helper.rb +11 -0
  42. data/{examples/rr/extensions/instance_methods_times_matcher_example.rb → spec/rr/adapters/rr_methods_times_matcher_spec.rb} +4 -4
  43. data/spec/rr/double/double_insertion_bind_spec.rb +78 -0
  44. data/spec/rr/double/double_insertion_dispatching_spec.rb +221 -0
  45. data/spec/rr/double/double_insertion_has_original_method_spec.rb +56 -0
  46. data/spec/rr/double/double_insertion_register_scenario_spec.rb +24 -0
  47. data/spec/rr/double/double_insertion_reset_spec.rb +89 -0
  48. data/spec/rr/double/double_insertion_spec.rb +66 -0
  49. data/spec/rr/double/double_insertion_verify_spec.rb +23 -0
  50. data/spec/rr/double_creator_spec.rb +454 -0
  51. data/{examples/rr/scenario_definition_example.rb → spec/rr/double_definition_spec.rb} +143 -143
  52. data/spec/rr/double_method_proxy_spec.rb +71 -0
  53. data/spec/rr/double_spec.rb +654 -0
  54. data/spec/rr/errors/rr_error_spec.rb +65 -0
  55. data/spec/rr/expectations/any_argument_expectation_spec.rb +47 -0
  56. data/spec/rr/expectations/anything_argument_equality_expectation_spec.rb +38 -0
  57. data/spec/rr/expectations/argument_equality_expectation_spec.rb +58 -0
  58. data/spec/rr/expectations/boolean_argument_equality_expectation_spec.rb +53 -0
  59. data/spec/rr/expectations/duck_type_argument_equality_expectation_spec.rb +71 -0
  60. data/spec/rr/expectations/is_a_argument_equality_expectation_spec.rb +51 -0
  61. data/spec/rr/expectations/numeric_argument_equality_expectation_spec.rb +47 -0
  62. data/spec/rr/expectations/range_argument_equality_expectation_spec.rb +59 -0
  63. data/spec/rr/expectations/regexp_argument_equality_expectation_spec.rb +72 -0
  64. data/spec/rr/expectations/times_called_expectation/times_called_expectation_any_times_spec.rb +43 -0
  65. data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_least_spec.rb +67 -0
  66. data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_most_spec.rb +71 -0
  67. data/spec/rr/expectations/times_called_expectation/times_called_expectation_helper.rb +21 -0
  68. data/spec/rr/expectations/times_called_expectation/times_called_expectation_integer_spec.rb +103 -0
  69. data/spec/rr/expectations/times_called_expectation/times_called_expectation_proc_spec.rb +79 -0
  70. data/spec/rr/expectations/times_called_expectation/times_called_expectation_range_spec.rb +81 -0
  71. data/spec/rr/expectations/times_called_expectation/times_called_expectation_spec.rb +40 -0
  72. data/spec/rr/rspec/rspec_adapter_spec.rb +65 -0
  73. data/spec/rr/rspec/rspec_backtrace_tweaking_spec.rb +52 -0
  74. data/spec/rr/rspec/rspec_usage_spec.rb +67 -0
  75. data/spec/rr/space/hash_with_object_id_key_spec.rb +88 -0
  76. data/spec/rr/space/space_create_spec.rb +278 -0
  77. data/spec/rr/space/space_helper.rb +7 -0
  78. data/spec/rr/space/space_register_spec.rb +32 -0
  79. data/spec/rr/space/space_reset_spec.rb +131 -0
  80. data/spec/rr/space/space_spec.rb +32 -0
  81. data/spec/rr/space/space_verify_spec.rb +181 -0
  82. data/{examples → spec}/rr/test_unit/test_helper.rb +1 -1
  83. data/{examples → spec}/rr/test_unit/test_unit_backtrace_test.rb +0 -0
  84. data/{examples → spec}/rr/test_unit/test_unit_integration_test.rb +4 -4
  85. data/spec/rr/times_called_matchers/any_times_matcher_spec.rb +47 -0
  86. data/spec/rr/times_called_matchers/at_least_matcher_spec.rb +55 -0
  87. data/spec/rr/times_called_matchers/at_most_matcher_spec.rb +70 -0
  88. data/spec/rr/times_called_matchers/integer_matcher_spec.rb +70 -0
  89. data/spec/rr/times_called_matchers/proc_matcher_spec.rb +55 -0
  90. data/spec/rr/times_called_matchers/range_matcher_spec.rb +76 -0
  91. data/spec/rr/times_called_matchers/times_called_matcher_spec.rb +118 -0
  92. data/spec/rspec_spec_suite.rb +16 -0
  93. data/spec/spec_helper.rb +9 -0
  94. data/{examples/example_suite.rb → spec/spec_suite.rb} +3 -3
  95. data/{examples/test_unit_example_suite.rb → spec/test_unit_spec_suite.rb} +0 -0
  96. metadata +93 -93
  97. data/examples/core_example_suite.rb +0 -31
  98. data/examples/example_helper.rb +0 -9
  99. data/examples/rr/double/double_bind_example.rb +0 -70
  100. data/examples/rr/double/double_dispatching_example.rb +0 -236
  101. data/examples/rr/double/double_example.rb +0 -66
  102. data/examples/rr/double/double_has_original_method_example.rb +0 -56
  103. data/examples/rr/double/double_register_scenario_example.rb +0 -24
  104. data/examples/rr/double/double_reset_example.rb +0 -89
  105. data/examples/rr/double/double_verify_example.rb +0 -23
  106. data/examples/rr/errors/rr_error_example.rb +0 -65
  107. data/examples/rr/expectations/any_argument_expectation_example.rb +0 -52
  108. data/examples/rr/expectations/anything_argument_equality_expectation_example.rb +0 -38
  109. data/examples/rr/expectations/argument_equality_expectation_example.rb +0 -62
  110. data/examples/rr/expectations/boolean_argument_equality_expectation_example.rb +0 -48
  111. data/examples/rr/expectations/duck_type_argument_equality_expectation_example.rb +0 -67
  112. data/examples/rr/expectations/is_a_argument_equality_expectation_example.rb +0 -50
  113. data/examples/rr/expectations/numeric_argument_equality_expectation_example.rb +0 -46
  114. data/examples/rr/expectations/range_argument_equality_expectation_example.rb +0 -59
  115. data/examples/rr/expectations/regexp_argument_equality_expectation_example.rb +0 -67
  116. data/examples/rr/expectations/times_called_expectation/times_called_expectation_any_times_example.rb +0 -50
  117. data/examples/rr/expectations/times_called_expectation/times_called_expectation_at_least_example.rb +0 -73
  118. data/examples/rr/expectations/times_called_expectation/times_called_expectation_at_most_example.rb +0 -77
  119. data/examples/rr/expectations/times_called_expectation/times_called_expectation_example.rb +0 -42
  120. data/examples/rr/expectations/times_called_expectation/times_called_expectation_helper.rb +0 -20
  121. data/examples/rr/expectations/times_called_expectation/times_called_expectation_integer_example.rb +0 -111
  122. data/examples/rr/expectations/times_called_expectation/times_called_expectation_proc_example.rb +0 -88
  123. data/examples/rr/expectations/times_called_expectation/times_called_expectation_range_example.rb +0 -90
  124. data/examples/rr/extensions/instance_methods_argument_matcher_example.rb +0 -65
  125. data/examples/rr/extensions/instance_methods_creator_example.rb +0 -363
  126. data/examples/rr/extensions/instance_methods_example_helper.rb +0 -11
  127. data/examples/rr/extensions/instance_methods_space_example.rb +0 -122
  128. data/examples/rr/rspec/rspec_adapter_example.rb +0 -63
  129. data/examples/rr/rspec/rspec_backtrace_tweaking_example.rb +0 -36
  130. data/examples/rr/rspec/rspec_usage_example.rb +0 -65
  131. data/examples/rr/scenario_creator_example.rb +0 -459
  132. data/examples/rr/scenario_example.rb +0 -701
  133. data/examples/rr/scenario_method_proxy_example.rb +0 -71
  134. data/examples/rr/space/hash_with_object_id_key_example.rb +0 -86
  135. data/examples/rr/space/space_create_example.rb +0 -278
  136. data/examples/rr/space/space_example.rb +0 -29
  137. data/examples/rr/space/space_helper.rb +0 -7
  138. data/examples/rr/space/space_register_example.rb +0 -32
  139. data/examples/rr/space/space_reset_example.rb +0 -120
  140. data/examples/rr/space/space_verify_example.rb +0 -169
  141. data/examples/rr/times_called_matchers/any_times_matcher_example.rb +0 -63
  142. data/examples/rr/times_called_matchers/at_least_matcher_example.rb +0 -70
  143. data/examples/rr/times_called_matchers/at_most_matcher_example.rb +0 -85
  144. data/examples/rr/times_called_matchers/integer_matcher_example.rb +0 -91
  145. data/examples/rr/times_called_matchers/proc_matcher_example.rb +0 -77
  146. data/examples/rr/times_called_matchers/range_matcher_example.rb +0 -97
  147. data/examples/rr/times_called_matchers/times_called_matcher_example.rb +0 -53
  148. data/examples/rspec_example_suite.rb +0 -25
  149. data/lib/rr/extensions/instance_methods.rb +0 -228
  150. data/lib/rr/scenario.rb +0 -337
@@ -0,0 +1,72 @@
1
+ require "spec/spec_helper"
2
+
3
+ module RR
4
+ module Expectations
5
+ describe ArgumentEqualityExpectation, "with regexp matcher" do
6
+ attr_reader :expectation
7
+
8
+ before do
9
+ @expectation = ArgumentEqualityExpectation.new(/abc/)
10
+ end
11
+
12
+ describe "#exact_match?" do
13
+ it "returns true when passed in an Regexp matcher with the same argument list" do
14
+ expectation.should be_exact_match(/abc/)
15
+ end
16
+
17
+ it "returns false when passed in an Regexp matcher with a different argument list" do
18
+ expectation.should_not be_exact_match(/def/)
19
+ end
20
+
21
+ it "returns false otherwise" do
22
+ expectation.should_not be_exact_match("abc")
23
+ expectation.should_not be_exact_match(:hello)
24
+ expectation.should_not be_exact_match(1)
25
+ expectation.should_not be_exact_match(nil)
26
+ expectation.should_not be_exact_match(true)
27
+ expectation.should_not be_exact_match()
28
+ end
29
+ end
30
+
31
+ describe "#wildcard_match?" do
32
+ before do
33
+ @matching_object = Object.new
34
+ def @matching_object.quack
35
+ end
36
+ def @matching_object.waddle
37
+ end
38
+
39
+ @partial_matching_object = Object.new
40
+ def @partial_matching_object.quack
41
+ end
42
+
43
+ @not_match_object = Object.new
44
+
45
+ expectation = ArgumentEqualityExpectation.new(/abc/)
46
+ end
47
+
48
+ it "returns true when string matches the regexp" do
49
+ expectation.should be_wildcard_match("Tabcola")
50
+ end
51
+
52
+ it "returns false when string does not match the regexp" do
53
+ expectation.should_not be_wildcard_match("no match here")
54
+ end
55
+
56
+ it "returns true when an exact match" do
57
+ expectation.should be_wildcard_match(/abc/)
58
+ end
59
+
60
+ it "returns false when not an exact match" do
61
+ expectation.should_not be_wildcard_match(/def/)
62
+ end
63
+
64
+ it "returns false when not passed correct number of arguments" do
65
+ expectation.should_not be_wildcard_match()
66
+ expectation.should_not be_wildcard_match('abc', 'abc')
67
+ end
68
+ end
69
+ end
70
+
71
+ end
72
+ end
@@ -0,0 +1,43 @@
1
+ require "spec/spec_helper"
2
+
3
+ module RR
4
+ module Expectations
5
+ describe TimesCalledExpectation, ' with AnyTimesMatcher' do
6
+ it_should_behave_like "RR::Expectations::TimesCalledExpectation"
7
+ attr_reader :at_least
8
+
9
+ before do
10
+ @at_least = TimesCalledMatchers::AnyTimesMatcher.new
11
+ @expectation = TimesCalledExpectation.new(scenario, at_least)
12
+ end
13
+
14
+ describe "#verify!" do
15
+ it "always passes" do
16
+ expectation.verify!
17
+ 10.times {expectation.attempt!}
18
+ expectation.verify!
19
+ end
20
+ end
21
+
22
+ describe "#attempt?" do
23
+ it "always returns true" do
24
+ expectation.should be_attempt
25
+ 10.times {expectation.attempt!}
26
+ expectation.should be_attempt
27
+ end
28
+ end
29
+
30
+ describe "#attempt!" do
31
+ it "always passes" do
32
+ 10.times {expectation.attempt!}
33
+ end
34
+ end
35
+
36
+ describe "#terminal?" do
37
+ it "returns false" do
38
+ expectation.should_not be_terminal
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,67 @@
1
+ require "spec/spec_helper"
2
+
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(scenario, 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
20
+
21
+ it "passes when times called == times" do
22
+ 3.times {expectation.attempt!}
23
+ expectation.verify!
24
+ end
25
+
26
+ it "raises error when times called < times" do
27
+ expectation.attempt!
28
+ proc 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
36
+
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
44
+
45
+ describe "#attempt!" do
46
+ it "passes when times called more than times" do
47
+ 4.times {expectation.attempt!}
48
+ end
49
+
50
+ it "passes when times called == times" do
51
+ 3.times {expectation.attempt!}
52
+ end
53
+
54
+ it "passes when times called < times" do
55
+ expectation.attempt!
56
+ end
57
+ end
58
+
59
+ describe "#terminal?" do
60
+ it "returns false" do
61
+ expectation.should_not be_terminal
62
+ end
63
+ end
64
+ end
65
+
66
+ end
67
+ end
@@ -0,0 +1,71 @@
1
+ require "spec/spec_helper"
2
+
3
+ module RR
4
+ module Expectations
5
+ describe TimesCalledExpectation, ' with AtMostMatcher' do
6
+ it_should_behave_like "RR::Expectations::TimesCalledExpectation"
7
+ attr_reader :times, :at_most
8
+
9
+ before do
10
+ @times = 3
11
+ @at_most = TimesCalledMatchers::AtMostMatcher.new(times)
12
+ @expectation = TimesCalledExpectation.new(scenario, 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!
19
+ end
20
+
21
+ it "raises error when times called < times" do
22
+ 2.times {expectation.attempt!}
23
+ expectation.verify!
24
+ end
25
+ end
26
+
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
31
+ end
32
+
33
+ it "returns false when attempted expected times" do
34
+ 3.times {expectation.attempt!}
35
+ expectation.should_not be_attempt
36
+ end
37
+
38
+ it "raises error before attempted more than expected times" do
39
+ 3.times {expectation.attempt!}
40
+ proc {expectation.attempt!}.should raise_error(
41
+ Errors::TimesCalledError
42
+ )
43
+ end
44
+ end
45
+
46
+ describe "#attempt!" do
47
+ it "fails when times called more than times" do
48
+ 3.times {expectation.attempt!}
49
+ proc do
50
+ expectation.attempt!
51
+ end.should raise_error(Errors::TimesCalledError, "foobar()\nCalled 4 times.\nExpected at most 3 times.")
52
+ end
53
+
54
+ it "passes when times called == times" do
55
+ 3.times {expectation.attempt!}
56
+ end
57
+
58
+ it "passes when times called < times" do
59
+ expectation.attempt!
60
+ end
61
+ end
62
+
63
+ describe "#terminal?" do
64
+ it "returns true" do
65
+ expectation.should be_terminal
66
+ end
67
+ end
68
+ end
69
+
70
+ end
71
+ end
@@ -0,0 +1,21 @@
1
+ require "spec/spec_helper"
2
+
3
+ module RR
4
+ module Expectations
5
+ describe TimesCalledExpectation, :shared => true do
6
+ attr_reader :space, :object, :method_name, :double_insertion, :scenario, :expectation
7
+ before do
8
+ @space = Space.new
9
+ @object = Object.new
10
+ @method_name = :foobar
11
+ @double_insertion = space.double_insertion(object, method_name)
12
+ @scenario = space.scenario(double_insertion)
13
+ scenario.with_any_args
14
+ end
15
+
16
+ def raises_expectation_error(&block)
17
+ proc {block.call}.should raise_error(Errors::TimesCalledError)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,103 @@
1
+ require "spec/spec_helper"
2
+
3
+ module RR
4
+ module Expectations
5
+ describe TimesCalledExpectation, " with IntegerMatcher" do
6
+ it_should_behave_like "RR::Expectations::TimesCalledExpectation"
7
+ attr_reader :matcher, :expected_line
8
+
9
+ before do
10
+ @matcher = TimesCalledMatchers::IntegerMatcher.new(2)
11
+ @expectation = TimesCalledExpectation.new(scenario, 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
22
+ end
23
+ end
24
+
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!
30
+ end
31
+
32
+ it "fails after attempt! called 1 time" do
33
+ expectation.attempt!
34
+ proc {expectation.verify!}.should raise_error(
35
+ Errors::TimesCalledError,
36
+ "foobar()\nCalled 1 time.\nExpected 2 times."
37
+ )
38
+ end
39
+
40
+ it "can't be called when attempt! is called 3 times" do
41
+ expectation.attempt!
42
+ expectation.attempt!
43
+ proc do
44
+ expectation.attempt!
45
+ end.should raise_error(Errors::TimesCalledError, "foobar()\nCalled 3 times.\nExpected 2 times.")
46
+ end
47
+
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
54
+ end
55
+ e.backtrace.first.should include(__FILE__)
56
+ e.backtrace.first.should include(":#{expected_line}")
57
+ end
58
+
59
+ it "has an error message that includes the number of times called and expected number of times" do
60
+ proc do
61
+ expectation.verify!
62
+ end.should raise_error(Errors::TimesCalledError, "foobar()\nCalled 0 times.\nExpected 2 times.")
63
+ end
64
+ end
65
+
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
70
+ end
71
+
72
+ it "returns false when attempted expected times" do
73
+ 2.times {expectation.attempt!}
74
+ expectation.should_not be_attempt
75
+ end
76
+
77
+ it "raises error before attempted more than expected times" do
78
+ 2.times {expectation.attempt!}
79
+ proc {expectation.attempt!}.should raise_error(
80
+ Errors::TimesCalledError
81
+ )
82
+ end
83
+ end
84
+
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
+ proc do
90
+ expectation.attempt!
91
+ end.should raise_error(Errors::TimesCalledError)
92
+ end
93
+ end
94
+
95
+ describe "#terminal?" do
96
+ it "returns true" do
97
+ expectation.should be_terminal
98
+ end
99
+ end
100
+ end
101
+
102
+ end
103
+ end
@@ -0,0 +1,79 @@
1
+ require "spec/spec_helper"
2
+
3
+ module RR
4
+ module Expectations
5
+ describe TimesCalledExpectation, " with ProcMatcher" do
6
+ it_should_behave_like "RR::Expectations::TimesCalledExpectation"
7
+ attr_reader :matcher
8
+
9
+ before do
10
+ @matcher = TimesCalledMatchers::ProcMatcher.new(proc {|value| value == 2})
11
+ @expectation = TimesCalledExpectation.new(scenario, 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
23
+ end
24
+ end
25
+
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!
31
+ end
32
+
33
+ it "fails after attempt! called 1 time" do
34
+ expectation.attempt!
35
+ proc {expectation.verify!}.should raise_error(Errors::TimesCalledError)
36
+ end
37
+
38
+ it "fails after attempt! called 3 times" do
39
+ expectation.attempt!
40
+ expectation.attempt!
41
+ expectation.attempt!
42
+ proc {expectation.verify!}.should raise_error(Errors::TimesCalledError)
43
+ end
44
+ end
45
+
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
50
+ end
51
+
52
+ it "returns true when attempted expected times" do
53
+ 2.times {expectation.attempt!}
54
+ expectation.should be_attempt
55
+ end
56
+
57
+ it "returns true when attempted more than expected times" do
58
+ 3.times {expectation.attempt!}
59
+ expectation.should be_attempt
60
+ end
61
+ end
62
+
63
+ describe "#attempt! for a proc expectation" do
64
+ it "lets everything pass" do
65
+ @object.foobar
66
+ @object.foobar
67
+ @object.foobar
68
+ end
69
+ end
70
+
71
+ describe "#terminal? with ProcMatcher" do
72
+ it "returns false" do
73
+ expectation.should_not be_terminal
74
+ end
75
+ end
76
+ end
77
+
78
+ end
79
+ end