redinger-rr 0.10.3

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 (133) hide show
  1. data/CHANGES +221 -0
  2. data/README.rdoc +343 -0
  3. data/Rakefile +88 -0
  4. data/VERSION.yml +4 -0
  5. data/lib/rr.rb +88 -0
  6. data/lib/rr/adapters/rr_methods.rb +122 -0
  7. data/lib/rr/adapters/rspec.rb +59 -0
  8. data/lib/rr/adapters/test_unit.rb +29 -0
  9. data/lib/rr/double.rb +152 -0
  10. data/lib/rr/double_definitions/child_double_definition_creator.rb +27 -0
  11. data/lib/rr/double_definitions/double_definition.rb +348 -0
  12. data/lib/rr/double_definitions/double_definition_creator.rb +167 -0
  13. data/lib/rr/double_definitions/double_definition_creator_proxy.rb +37 -0
  14. data/lib/rr/double_definitions/strategies/implementation/implementation_strategy.rb +15 -0
  15. data/lib/rr/double_definitions/strategies/implementation/proxy.rb +62 -0
  16. data/lib/rr/double_definitions/strategies/implementation/reimplementation.rb +14 -0
  17. data/lib/rr/double_definitions/strategies/implementation/strongly_typed_reimplementation.rb +17 -0
  18. data/lib/rr/double_definitions/strategies/scope/instance.rb +15 -0
  19. data/lib/rr/double_definitions/strategies/scope/instance_of_class.rb +50 -0
  20. data/lib/rr/double_definitions/strategies/scope/scope_strategy.rb +15 -0
  21. data/lib/rr/double_definitions/strategies/strategy.rb +70 -0
  22. data/lib/rr/double_definitions/strategies/verification/dont_allow.rb +34 -0
  23. data/lib/rr/double_definitions/strategies/verification/mock.rb +44 -0
  24. data/lib/rr/double_definitions/strategies/verification/stub.rb +45 -0
  25. data/lib/rr/double_definitions/strategies/verification/verification_strategy.rb +15 -0
  26. data/lib/rr/double_injection.rb +180 -0
  27. data/lib/rr/double_matches.rb +51 -0
  28. data/lib/rr/errors/argument_equality_error.rb +6 -0
  29. data/lib/rr/errors/double_definition_error.rb +6 -0
  30. data/lib/rr/errors/double_not_found_error.rb +6 -0
  31. data/lib/rr/errors/double_order_error.rb +6 -0
  32. data/lib/rr/errors/rr_error.rb +20 -0
  33. data/lib/rr/errors/spy_verification_errors/double_injection_not_found_error.rb +8 -0
  34. data/lib/rr/errors/spy_verification_errors/invocation_count_error.rb +8 -0
  35. data/lib/rr/errors/spy_verification_errors/spy_verification_error.rb +8 -0
  36. data/lib/rr/errors/subject_does_not_implement_method_error.rb +6 -0
  37. data/lib/rr/errors/subject_has_different_arity_error.rb +6 -0
  38. data/lib/rr/errors/times_called_error.rb +6 -0
  39. data/lib/rr/expectations/any_argument_expectation.rb +21 -0
  40. data/lib/rr/expectations/argument_equality_expectation.rb +41 -0
  41. data/lib/rr/expectations/times_called_expectation.rb +57 -0
  42. data/lib/rr/hash_with_object_id_key.rb +44 -0
  43. data/lib/rr/method_dispatches/base_method_dispatch.rb +108 -0
  44. data/lib/rr/method_dispatches/method_dispatch.rb +61 -0
  45. data/lib/rr/method_dispatches/method_missing_dispatch.rb +49 -0
  46. data/lib/rr/proc_from_block.rb +7 -0
  47. data/lib/rr/recorded_calls.rb +103 -0
  48. data/lib/rr/space.rb +123 -0
  49. data/lib/rr/spy_verification.rb +48 -0
  50. data/lib/rr/spy_verification_proxy.rb +18 -0
  51. data/lib/rr/times_called_matchers/any_times_matcher.rb +18 -0
  52. data/lib/rr/times_called_matchers/at_least_matcher.rb +15 -0
  53. data/lib/rr/times_called_matchers/at_most_matcher.rb +23 -0
  54. data/lib/rr/times_called_matchers/integer_matcher.rb +19 -0
  55. data/lib/rr/times_called_matchers/non_terminal.rb +27 -0
  56. data/lib/rr/times_called_matchers/proc_matcher.rb +11 -0
  57. data/lib/rr/times_called_matchers/range_matcher.rb +21 -0
  58. data/lib/rr/times_called_matchers/terminal.rb +20 -0
  59. data/lib/rr/times_called_matchers/times_called_matcher.rb +44 -0
  60. data/lib/rr/wildcard_matchers.rb +158 -0
  61. data/lib/rr/wildcard_matchers/anything.rb +18 -0
  62. data/lib/rr/wildcard_matchers/boolean.rb +23 -0
  63. data/lib/rr/wildcard_matchers/duck_type.rb +32 -0
  64. data/lib/rr/wildcard_matchers/hash_including.rb +29 -0
  65. data/lib/rr/wildcard_matchers/is_a.rb +25 -0
  66. data/lib/rr/wildcard_matchers/numeric.rb +13 -0
  67. data/lib/rr/wildcard_matchers/range.rb +7 -0
  68. data/lib/rr/wildcard_matchers/regexp.rb +7 -0
  69. data/lib/rr/wildcard_matchers/satisfy.rb +26 -0
  70. data/spec/core_spec_suite.rb +19 -0
  71. data/spec/environment_fixture_setup.rb +7 -0
  72. data/spec/high_level_spec.rb +398 -0
  73. data/spec/proc_from_block_spec.rb +14 -0
  74. data/spec/rr/adapters/rr_methods_argument_matcher_spec.rb +67 -0
  75. data/spec/rr/adapters/rr_methods_creator_spec.rb +149 -0
  76. data/spec/rr/adapters/rr_methods_space_spec.rb +115 -0
  77. data/spec/rr/adapters/rr_methods_spec_helper.rb +11 -0
  78. data/spec/rr/adapters/rr_methods_times_matcher_spec.rb +17 -0
  79. data/spec/rr/double_definitions/child_double_definition_creator_spec.rb +112 -0
  80. data/spec/rr/double_definitions/double_definition_creator_proxy_spec.rb +155 -0
  81. data/spec/rr/double_definitions/double_definition_creator_spec.rb +502 -0
  82. data/spec/rr/double_definitions/double_definition_spec.rb +1165 -0
  83. data/spec/rr/double_injection/double_injection_spec.rb +339 -0
  84. data/spec/rr/double_injection/double_injection_verify_spec.rb +29 -0
  85. data/spec/rr/double_spec.rb +352 -0
  86. data/spec/rr/errors/rr_error_spec.rb +67 -0
  87. data/spec/rr/expectations/any_argument_expectation_spec.rb +47 -0
  88. data/spec/rr/expectations/anything_argument_equality_expectation_spec.rb +14 -0
  89. data/spec/rr/expectations/argument_equality_expectation_spec.rb +135 -0
  90. data/spec/rr/expectations/boolean_argument_equality_expectation_spec.rb +34 -0
  91. data/spec/rr/expectations/hash_including_argument_equality_expectation_spec.rb +82 -0
  92. data/spec/rr/expectations/hash_including_spec.rb +17 -0
  93. data/spec/rr/expectations/satisfy_argument_equality_expectation_spec.rb +59 -0
  94. data/spec/rr/expectations/satisfy_spec.rb +14 -0
  95. data/spec/rr/expectations/times_called_expectation/times_called_expectation_any_times_spec.rb +46 -0
  96. data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_least_spec.rb +69 -0
  97. data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_most_spec.rb +71 -0
  98. data/spec/rr/expectations/times_called_expectation/times_called_expectation_helper.rb +23 -0
  99. data/spec/rr/expectations/times_called_expectation/times_called_expectation_integer_spec.rb +104 -0
  100. data/spec/rr/expectations/times_called_expectation/times_called_expectation_proc_spec.rb +81 -0
  101. data/spec/rr/expectations/times_called_expectation/times_called_expectation_range_spec.rb +83 -0
  102. data/spec/rr/expectations/times_called_expectation/times_called_expectation_spec.rb +38 -0
  103. data/spec/rr/rspec/invocation_matcher_spec.rb +279 -0
  104. data/spec/rr/rspec/rspec_adapter_spec.rb +66 -0
  105. data/spec/rr/rspec/rspec_backtrace_tweaking_spec.rb +31 -0
  106. data/spec/rr/rspec/rspec_backtrace_tweaking_spec_fixture.rb +11 -0
  107. data/spec/rr/rspec/rspec_usage_spec.rb +86 -0
  108. data/spec/rr/space/hash_with_object_id_key_spec.rb +88 -0
  109. data/spec/rr/space/space_spec.rb +550 -0
  110. data/spec/rr/test_unit/test_helper.rb +7 -0
  111. data/spec/rr/test_unit/test_unit_backtrace_test.rb +36 -0
  112. data/spec/rr/test_unit/test_unit_integration_test.rb +57 -0
  113. data/spec/rr/times_called_matchers/any_times_matcher_spec.rb +47 -0
  114. data/spec/rr/times_called_matchers/at_least_matcher_spec.rb +55 -0
  115. data/spec/rr/times_called_matchers/at_most_matcher_spec.rb +70 -0
  116. data/spec/rr/times_called_matchers/integer_matcher_spec.rb +70 -0
  117. data/spec/rr/times_called_matchers/proc_matcher_spec.rb +55 -0
  118. data/spec/rr/times_called_matchers/range_matcher_spec.rb +76 -0
  119. data/spec/rr/times_called_matchers/times_called_matcher_spec.rb +118 -0
  120. data/spec/rr/wildcard_matchers/anything_spec.rb +24 -0
  121. data/spec/rr/wildcard_matchers/boolean_spec.rb +36 -0
  122. data/spec/rr/wildcard_matchers/duck_type_spec.rb +52 -0
  123. data/spec/rr/wildcard_matchers/is_a_spec.rb +32 -0
  124. data/spec/rr/wildcard_matchers/numeric_spec.rb +32 -0
  125. data/spec/rr/wildcard_matchers/range_spec.rb +35 -0
  126. data/spec/rr/wildcard_matchers/regexp_spec.rb +43 -0
  127. data/spec/rr_spec.rb +28 -0
  128. data/spec/rspec_spec_suite.rb +17 -0
  129. data/spec/spec_helper.rb +109 -0
  130. data/spec/spec_suite.rb +31 -0
  131. data/spec/spy_verification_spec.rb +129 -0
  132. data/spec/test_unit_spec_suite.rb +21 -0
  133. metadata +193 -0
@@ -0,0 +1,14 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
2
+
3
+ module RR
4
+ module WildcardMatchers
5
+ describe Satisfy do
6
+ describe "#inspect" do
7
+ it "returns satisfy string" do
8
+ matcher = Satisfy.new(lambda {})
9
+ matcher.inspect.should == "satisfy {block}"
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,46 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../../spec_helper")
2
+
3
+ module RR
4
+ module Expectations
5
+ describe TimesCalledExpectation do
6
+ context "when using an AnyTimesMatcher" do
7
+ it_should_behave_like "RR::Expectations::TimesCalledExpectation"
8
+ attr_reader :matcher, :expectation
9
+
10
+ before do
11
+ double.definition.any_number_of_times
12
+ @matcher = double.definition.times_matcher
13
+ @expectation = TimesCalledExpectation.new(double)
14
+ end
15
+
16
+ describe "#verify!" do
17
+ it "always passes" do
18
+ expectation.verify!
19
+ 10.times {expectation.attempt}
20
+ expectation.verify!
21
+ end
22
+ end
23
+
24
+ describe "#attempt?" do
25
+ it "always returns true" do
26
+ expectation.should be_attempt
27
+ 10.times {expectation.attempt}
28
+ expectation.should be_attempt
29
+ end
30
+ end
31
+
32
+ describe "#attempt!" do
33
+ it "always passes" do
34
+ 10.times {expectation.attempt}
35
+ end
36
+ end
37
+
38
+ describe "#terminal?" do
39
+ it "returns false" do
40
+ expectation.should_not be_terminal
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,69 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../../spec_helper")
2
+
3
+ module RR
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
9
+
10
+ before do
11
+ @times = 3
12
+ double.definition.at_least(times)
13
+ @at_least = double.definition.times_matcher
14
+ @expectation = TimesCalledExpectation.new(double)
15
+ end
16
+
17
+ describe "#verify!" do
18
+ it "passes when times called > times" do
19
+ 4.times {expectation.attempt}
20
+ expectation.verify!
21
+ end
22
+
23
+ it "passes when times called == times" do
24
+ 3.times {expectation.attempt}
25
+ expectation.verify!
26
+ end
27
+
28
+ it "raises error when times called < times" do
29
+ expectation.attempt
30
+ lambda do
31
+ expectation.verify!
32
+ end.should raise_error(
33
+ RR::Errors::TimesCalledError,
34
+ "foobar()\nCalled 1 time.\nExpected at least 3 times."
35
+ )
36
+ end
37
+ end
38
+
39
+ describe "#attempt?" do
40
+ it "always returns true" do
41
+ expectation.should be_attempt
42
+ 10.times {expectation.attempt}
43
+ expectation.should be_attempt
44
+ end
45
+ end
46
+
47
+ describe "#attempt!" do
48
+ it "passes when times called more than times" do
49
+ 4.times {expectation.attempt}
50
+ end
51
+
52
+ it "passes when times called == times" do
53
+ 3.times {expectation.attempt}
54
+ end
55
+
56
+ it "passes when times called < times" do
57
+ expectation.attempt
58
+ end
59
+ end
60
+
61
+ describe "#terminal?" do
62
+ it "returns false" do
63
+ expectation.should_not be_terminal
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,71 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../../spec_helper")
2
+
3
+ module RR
4
+ module Expectations
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
9
+
10
+ before do
11
+ @times = 3
12
+ double.definition.at_most(times)
13
+ @at_most = double.definition.times_matcher
14
+ @expectation = TimesCalledExpectation.new(double)
15
+ end
16
+
17
+ describe "#verify!" do
18
+ it "returns true when times called == times" do
19
+ 3.times {expectation.attempt}
20
+ expectation.verify!
21
+ end
22
+
23
+ it "raises error when times called < times" do
24
+ 2.times {expectation.attempt}
25
+ expectation.verify!
26
+ end
27
+ end
28
+
29
+ describe "#attempt?" do
30
+ it "returns true when attempted less than expected times" do
31
+ 2.times {expectation.attempt}
32
+ expectation.should be_attempt
33
+ end
34
+
35
+ it "returns false when attempted expected times" do
36
+ 3.times {expectation.attempt}
37
+ expectation.should_not be_attempt
38
+ end
39
+
40
+ it "raises error before attempted more than expected times" do
41
+ 3.times {expectation.attempt}
42
+ lambda {expectation.attempt}.should raise_error( Errors::TimesCalledError )
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
+ lambda 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
+ end
70
+ end
71
+ end
@@ -0,0 +1,23 @@
1
+ module RR
2
+ module Expectations
3
+ describe TimesCalledExpectation, :shared => true do
4
+ attr_reader :subject, :method_name, :double_injection, :double, :double_definition
5
+ it_should_behave_like "Swapped Space"
6
+ before do
7
+ @subject = Object.new
8
+ @method_name = :foobar
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)
15
+ double.definition.with_any_args.any_number_of_times
16
+ end
17
+
18
+ def raises_expectation_error(&block)
19
+ lambda {block.call}.should raise_error(Errors::TimesCalledError)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,104 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../../spec_helper")
2
+
3
+ module RR
4
+ module Expectations
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
9
+
10
+ before do
11
+ double.definition.times(2)
12
+ @matcher = double.definition.times_matcher
13
+ @expectation = TimesCalledExpectation.new(double)
14
+ end
15
+
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
24
+ end
25
+
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
32
+
33
+ it "fails after attempt! called 1 time" do
34
+ expectation.attempt
35
+ lambda {expectation.verify!}.should raise_error(
36
+ Errors::TimesCalledError,
37
+ "foobar()\nCalled 1 time.\nExpected 2 times."
38
+ )
39
+ end
40
+
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.")
47
+ end
48
+
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
59
+
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
65
+ end
66
+
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
77
+
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
84
+ end
85
+
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
89
+ expectation.attempt
90
+ lambda do
91
+ expectation.attempt
92
+ end.should raise_error(Errors::TimesCalledError)
93
+ end
94
+ end
95
+
96
+ describe "#terminal?" do
97
+ it "returns true" do
98
+ expectation.should be_terminal
99
+ end
100
+ end
101
+ end
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,81 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../../spec_helper")
2
+
3
+ module RR
4
+ module Expectations
5
+ describe TimesCalledExpectation do
6
+ context "when using a ProcMatcher" do
7
+ it_should_behave_like "RR::Expectations::TimesCalledExpectation"
8
+ attr_reader :matcher, :expectation
9
+
10
+ before do
11
+ double.definition.times(lambda {|value| value == 2})
12
+ @matcher = double.definition.times_matcher
13
+ @expectation = TimesCalledExpectation.new(double)
14
+ end
15
+
16
+ describe "#verify" do
17
+ it "matches a block" do
18
+ expectation.verify.should == false
19
+ expectation.attempt
20
+ expectation.verify.should == false
21
+ expectation.attempt
22
+ expectation.verify.should == true
23
+ expectation.attempt
24
+ expectation.verify.should == false
25
+ end
26
+ end
27
+
28
+ describe "#verify! when passed a block (== 2 times)" do
29
+ it "passes after attempt! called 2 times" do
30
+ expectation.attempt
31
+ expectation.attempt
32
+ expectation.verify!
33
+ end
34
+
35
+ it "fails after attempt! called 1 time" do
36
+ expectation.attempt
37
+ lambda {expectation.verify!}.should raise_error(Errors::TimesCalledError)
38
+ end
39
+
40
+ it "fails after attempt! called 3 times" do
41
+ expectation.attempt
42
+ expectation.attempt
43
+ expectation.attempt
44
+ lambda {expectation.verify!}.should raise_error(Errors::TimesCalledError)
45
+ end
46
+ end
47
+
48
+ describe "#attempt? with IntegerMatcher" do
49
+ it "returns true when attempted less than expected times" do
50
+ 1.times {expectation.attempt}
51
+ expectation.should be_attempt
52
+ end
53
+
54
+ it "returns true when attempted expected times" do
55
+ 2.times {expectation.attempt}
56
+ expectation.should be_attempt
57
+ end
58
+
59
+ it "returns true when attempted more than expected times" do
60
+ 3.times {expectation.attempt}
61
+ expectation.should be_attempt
62
+ end
63
+ end
64
+
65
+ describe "#attempt! for a lambda expectation" do
66
+ it "lets everything pass" do
67
+ subject.foobar
68
+ subject.foobar
69
+ subject.foobar
70
+ end
71
+ end
72
+
73
+ describe "#terminal? with ProcMatcher" do
74
+ it "returns false" do
75
+ expectation.should_not be_terminal
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,83 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../../../spec_helper")
2
+
3
+ module RR
4
+ module Expectations
5
+ describe TimesCalledExpectation do
6
+ context "when using a RangeMatcher" do
7
+ it_should_behave_like "RR::Expectations::TimesCalledExpectation"
8
+ attr_reader :matcher, :expectation
9
+
10
+ before do
11
+ double.definition.times(1..2)
12
+ @matcher = double.definition.times_matcher
13
+ @expectation = TimesCalledExpectation.new(double)
14
+ end
15
+
16
+ describe "#verify" do
17
+ it "returns true when times called falls within a range" do
18
+ expectation.verify.should == false
19
+ expectation.attempt
20
+ expectation.verify.should == true
21
+ expectation.attempt
22
+ expectation.verify.should == true
23
+ end
24
+ end
25
+
26
+ describe "#verify! when passed a Range (1..2)" do
27
+ it "passes after attempt! called 1 time" do
28
+ expectation.attempt
29
+ expectation.verify!
30
+ end
31
+
32
+ it "passes after attempt! called 2 times" do
33
+ expectation.attempt
34
+ expectation.attempt
35
+ expectation.verify!
36
+ end
37
+
38
+ it "can't be called when attempt! is called 3 times" do
39
+ expectation.attempt
40
+ expectation.attempt
41
+ lambda do
42
+ expectation.attempt
43
+ end.should raise_error(Errors::TimesCalledError, "foobar()\nCalled 3 times.\nExpected 1..2 times.")
44
+ end
45
+ end
46
+
47
+ describe "#attempt? with RangeMatcher" do
48
+ it "returns true when attempted less than low end of range" do
49
+ expectation.should be_attempt
50
+ end
51
+
52
+ it "returns false when attempted in range" do
53
+ expectation.attempt
54
+ expectation.should be_attempt
55
+ expectation.attempt
56
+ expectation.should be_attempt
57
+ end
58
+
59
+ it "raises error before attempted more than expected times" do
60
+ 2.times {expectation.attempt}
61
+ lambda {expectation.attempt}.should raise_error(
62
+ Errors::TimesCalledError
63
+ )
64
+ end
65
+ end
66
+
67
+ describe "#attempt! for a range expectation" do
68
+ it "raises error when attempt! called more than range permits" do
69
+ expectation.attempt
70
+ expectation.attempt
71
+ raises_expectation_error {expectation.attempt}
72
+ end
73
+ end
74
+
75
+ describe "#terminal? with RangeMatcher" do
76
+ it "returns true" do
77
+ expectation.should be_terminal
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end