redinger-rr 0.10.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +221 -0
- data/README.rdoc +343 -0
- data/Rakefile +88 -0
- data/VERSION.yml +4 -0
- data/lib/rr.rb +88 -0
- data/lib/rr/adapters/rr_methods.rb +122 -0
- data/lib/rr/adapters/rspec.rb +59 -0
- data/lib/rr/adapters/test_unit.rb +29 -0
- data/lib/rr/double.rb +152 -0
- data/lib/rr/double_definitions/child_double_definition_creator.rb +27 -0
- data/lib/rr/double_definitions/double_definition.rb +348 -0
- data/lib/rr/double_definitions/double_definition_creator.rb +167 -0
- data/lib/rr/double_definitions/double_definition_creator_proxy.rb +37 -0
- data/lib/rr/double_definitions/strategies/implementation/implementation_strategy.rb +15 -0
- data/lib/rr/double_definitions/strategies/implementation/proxy.rb +62 -0
- data/lib/rr/double_definitions/strategies/implementation/reimplementation.rb +14 -0
- data/lib/rr/double_definitions/strategies/implementation/strongly_typed_reimplementation.rb +17 -0
- data/lib/rr/double_definitions/strategies/scope/instance.rb +15 -0
- data/lib/rr/double_definitions/strategies/scope/instance_of_class.rb +50 -0
- data/lib/rr/double_definitions/strategies/scope/scope_strategy.rb +15 -0
- data/lib/rr/double_definitions/strategies/strategy.rb +70 -0
- data/lib/rr/double_definitions/strategies/verification/dont_allow.rb +34 -0
- data/lib/rr/double_definitions/strategies/verification/mock.rb +44 -0
- data/lib/rr/double_definitions/strategies/verification/stub.rb +45 -0
- data/lib/rr/double_definitions/strategies/verification/verification_strategy.rb +15 -0
- data/lib/rr/double_injection.rb +180 -0
- data/lib/rr/double_matches.rb +51 -0
- data/lib/rr/errors/argument_equality_error.rb +6 -0
- data/lib/rr/errors/double_definition_error.rb +6 -0
- data/lib/rr/errors/double_not_found_error.rb +6 -0
- data/lib/rr/errors/double_order_error.rb +6 -0
- data/lib/rr/errors/rr_error.rb +20 -0
- data/lib/rr/errors/spy_verification_errors/double_injection_not_found_error.rb +8 -0
- data/lib/rr/errors/spy_verification_errors/invocation_count_error.rb +8 -0
- data/lib/rr/errors/spy_verification_errors/spy_verification_error.rb +8 -0
- data/lib/rr/errors/subject_does_not_implement_method_error.rb +6 -0
- data/lib/rr/errors/subject_has_different_arity_error.rb +6 -0
- data/lib/rr/errors/times_called_error.rb +6 -0
- data/lib/rr/expectations/any_argument_expectation.rb +21 -0
- data/lib/rr/expectations/argument_equality_expectation.rb +41 -0
- data/lib/rr/expectations/times_called_expectation.rb +57 -0
- data/lib/rr/hash_with_object_id_key.rb +44 -0
- data/lib/rr/method_dispatches/base_method_dispatch.rb +108 -0
- data/lib/rr/method_dispatches/method_dispatch.rb +61 -0
- data/lib/rr/method_dispatches/method_missing_dispatch.rb +49 -0
- data/lib/rr/proc_from_block.rb +7 -0
- data/lib/rr/recorded_calls.rb +103 -0
- data/lib/rr/space.rb +123 -0
- data/lib/rr/spy_verification.rb +48 -0
- data/lib/rr/spy_verification_proxy.rb +18 -0
- data/lib/rr/times_called_matchers/any_times_matcher.rb +18 -0
- data/lib/rr/times_called_matchers/at_least_matcher.rb +15 -0
- data/lib/rr/times_called_matchers/at_most_matcher.rb +23 -0
- data/lib/rr/times_called_matchers/integer_matcher.rb +19 -0
- data/lib/rr/times_called_matchers/non_terminal.rb +27 -0
- data/lib/rr/times_called_matchers/proc_matcher.rb +11 -0
- data/lib/rr/times_called_matchers/range_matcher.rb +21 -0
- data/lib/rr/times_called_matchers/terminal.rb +20 -0
- data/lib/rr/times_called_matchers/times_called_matcher.rb +44 -0
- data/lib/rr/wildcard_matchers.rb +158 -0
- data/lib/rr/wildcard_matchers/anything.rb +18 -0
- data/lib/rr/wildcard_matchers/boolean.rb +23 -0
- data/lib/rr/wildcard_matchers/duck_type.rb +32 -0
- data/lib/rr/wildcard_matchers/hash_including.rb +29 -0
- data/lib/rr/wildcard_matchers/is_a.rb +25 -0
- data/lib/rr/wildcard_matchers/numeric.rb +13 -0
- data/lib/rr/wildcard_matchers/range.rb +7 -0
- data/lib/rr/wildcard_matchers/regexp.rb +7 -0
- data/lib/rr/wildcard_matchers/satisfy.rb +26 -0
- data/spec/core_spec_suite.rb +19 -0
- data/spec/environment_fixture_setup.rb +7 -0
- data/spec/high_level_spec.rb +398 -0
- data/spec/proc_from_block_spec.rb +14 -0
- data/spec/rr/adapters/rr_methods_argument_matcher_spec.rb +67 -0
- data/spec/rr/adapters/rr_methods_creator_spec.rb +149 -0
- data/spec/rr/adapters/rr_methods_space_spec.rb +115 -0
- data/spec/rr/adapters/rr_methods_spec_helper.rb +11 -0
- data/spec/rr/adapters/rr_methods_times_matcher_spec.rb +17 -0
- data/spec/rr/double_definitions/child_double_definition_creator_spec.rb +112 -0
- data/spec/rr/double_definitions/double_definition_creator_proxy_spec.rb +155 -0
- data/spec/rr/double_definitions/double_definition_creator_spec.rb +502 -0
- data/spec/rr/double_definitions/double_definition_spec.rb +1165 -0
- data/spec/rr/double_injection/double_injection_spec.rb +339 -0
- data/spec/rr/double_injection/double_injection_verify_spec.rb +29 -0
- data/spec/rr/double_spec.rb +352 -0
- data/spec/rr/errors/rr_error_spec.rb +67 -0
- data/spec/rr/expectations/any_argument_expectation_spec.rb +47 -0
- data/spec/rr/expectations/anything_argument_equality_expectation_spec.rb +14 -0
- data/spec/rr/expectations/argument_equality_expectation_spec.rb +135 -0
- data/spec/rr/expectations/boolean_argument_equality_expectation_spec.rb +34 -0
- data/spec/rr/expectations/hash_including_argument_equality_expectation_spec.rb +82 -0
- data/spec/rr/expectations/hash_including_spec.rb +17 -0
- data/spec/rr/expectations/satisfy_argument_equality_expectation_spec.rb +59 -0
- data/spec/rr/expectations/satisfy_spec.rb +14 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_any_times_spec.rb +46 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_least_spec.rb +69 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_most_spec.rb +71 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_helper.rb +23 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_integer_spec.rb +104 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_proc_spec.rb +81 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_range_spec.rb +83 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_spec.rb +38 -0
- data/spec/rr/rspec/invocation_matcher_spec.rb +279 -0
- data/spec/rr/rspec/rspec_adapter_spec.rb +66 -0
- data/spec/rr/rspec/rspec_backtrace_tweaking_spec.rb +31 -0
- data/spec/rr/rspec/rspec_backtrace_tweaking_spec_fixture.rb +11 -0
- data/spec/rr/rspec/rspec_usage_spec.rb +86 -0
- data/spec/rr/space/hash_with_object_id_key_spec.rb +88 -0
- data/spec/rr/space/space_spec.rb +550 -0
- data/spec/rr/test_unit/test_helper.rb +7 -0
- data/spec/rr/test_unit/test_unit_backtrace_test.rb +36 -0
- data/spec/rr/test_unit/test_unit_integration_test.rb +57 -0
- data/spec/rr/times_called_matchers/any_times_matcher_spec.rb +47 -0
- data/spec/rr/times_called_matchers/at_least_matcher_spec.rb +55 -0
- data/spec/rr/times_called_matchers/at_most_matcher_spec.rb +70 -0
- data/spec/rr/times_called_matchers/integer_matcher_spec.rb +70 -0
- data/spec/rr/times_called_matchers/proc_matcher_spec.rb +55 -0
- data/spec/rr/times_called_matchers/range_matcher_spec.rb +76 -0
- data/spec/rr/times_called_matchers/times_called_matcher_spec.rb +118 -0
- data/spec/rr/wildcard_matchers/anything_spec.rb +24 -0
- data/spec/rr/wildcard_matchers/boolean_spec.rb +36 -0
- data/spec/rr/wildcard_matchers/duck_type_spec.rb +52 -0
- data/spec/rr/wildcard_matchers/is_a_spec.rb +32 -0
- data/spec/rr/wildcard_matchers/numeric_spec.rb +32 -0
- data/spec/rr/wildcard_matchers/range_spec.rb +35 -0
- data/spec/rr/wildcard_matchers/regexp_spec.rb +43 -0
- data/spec/rr_spec.rb +28 -0
- data/spec/rspec_spec_suite.rb +17 -0
- data/spec/spec_helper.rb +109 -0
- data/spec/spec_suite.rb +31 -0
- data/spec/spy_verification_spec.rb +129 -0
- data/spec/test_unit_spec_suite.rb +21 -0
- metadata +193 -0
@@ -0,0 +1,36 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
|
2
|
+
|
3
|
+
class TestUnitBacktraceTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
super
|
6
|
+
@subject = Object.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
super
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_trim_backtrace_is_set
|
14
|
+
assert RR.trim_backtrace
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_backtrace_tweaking
|
18
|
+
skip "Skipped, because there is no Test::Unit::TestResult in this Test::Unit. Don't worry, this is totally fine." unless defined?(Test::Unit::TestResult)
|
19
|
+
old_result = @_result
|
20
|
+
result = Test::Unit::TestResult.new
|
21
|
+
|
22
|
+
error_display = nil
|
23
|
+
result.add_listener(Test::Unit::TestResult::FAULT) do |f|
|
24
|
+
error_display = f.long_display
|
25
|
+
end
|
26
|
+
test_case = self.class.new(:backtrace_tweaking)
|
27
|
+
test_case.run(result) {}
|
28
|
+
|
29
|
+
assert !error_display.include?("lib/rr")
|
30
|
+
end
|
31
|
+
|
32
|
+
def backtrace_tweaking
|
33
|
+
mock(@subject).foobar
|
34
|
+
RR::Space::instance.verify_double(@subject, :foobar)
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
|
2
|
+
|
3
|
+
class TestUnitIntegrationTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
super
|
6
|
+
@subject = Object.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
super
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_using_a_mock
|
14
|
+
mock(@subject).foobar(1, 2) {:baz}
|
15
|
+
assert_equal :baz, @subject.foobar(1, 2)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_using_a_stub
|
19
|
+
stub(@subject).foobar {:baz}
|
20
|
+
assert_equal :baz, @subject.foobar("any", "thing")
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_using_a_mock_proxy
|
24
|
+
def @subject.foobar
|
25
|
+
:baz
|
26
|
+
end
|
27
|
+
|
28
|
+
mock.proxy(@subject).foobar
|
29
|
+
assert_equal :baz, @subject.foobar
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_using_a_stub_proxy
|
33
|
+
def @subject.foobar
|
34
|
+
:baz
|
35
|
+
end
|
36
|
+
|
37
|
+
stub.proxy(@subject).foobar
|
38
|
+
assert_equal :baz, @subject.foobar
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_times_called_verification
|
42
|
+
mock(@subject).foobar(1, 2) {:baz}
|
43
|
+
assert_raise RR::Errors::TimesCalledError do
|
44
|
+
teardown
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_using_assert_received
|
49
|
+
stub(@subject).foobar(1, 2)
|
50
|
+
@subject.foobar(1, 2)
|
51
|
+
assert_received(@subject) {|subject| subject.foobar(1, 2)}
|
52
|
+
|
53
|
+
assert_raise(RR::Errors::SpyVerificationErrors::InvocationCountError) do
|
54
|
+
assert_received(@subject) {|subject| subject.foobar(1, 2, 3)}
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
|
2
|
+
|
3
|
+
module RR
|
4
|
+
module TimesCalledMatchers
|
5
|
+
describe AnyTimesMatcher do
|
6
|
+
attr_reader :matcher
|
7
|
+
before do
|
8
|
+
@matcher = AnyTimesMatcher.new
|
9
|
+
end
|
10
|
+
|
11
|
+
describe AnyTimesMatcher, "#possible_match?" do
|
12
|
+
it "always returns true" do
|
13
|
+
matcher.should be_possible_match(0)
|
14
|
+
matcher.should be_possible_match(99999)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe AnyTimesMatcher, "#matches?" do
|
19
|
+
it "always returns true" do
|
20
|
+
matcher.should be_matches(0)
|
21
|
+
matcher.should be_matches(99999)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe AnyTimesMatcher, "#attempt?" do
|
26
|
+
it "always returns true" do
|
27
|
+
matcher.should be_attempt(0)
|
28
|
+
matcher.should be_attempt(99999)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe AnyTimesMatcher, "#terminal?" do
|
33
|
+
it "returns false" do
|
34
|
+
matcher.should_not be_terminal
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe AnyTimesMatcher, "#error_message" do
|
39
|
+
it "has an error message" do
|
40
|
+
matcher.error_message(2).should == (
|
41
|
+
"Called 2 times.\nExpected any number of times."
|
42
|
+
)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
|
2
|
+
|
3
|
+
module RR
|
4
|
+
module TimesCalledMatchers
|
5
|
+
describe AtLeastMatcher do
|
6
|
+
attr_reader :matcher, :times
|
7
|
+
before do
|
8
|
+
@times = 3
|
9
|
+
@matcher = AtLeastMatcher.new(times)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#possible_match?" do
|
13
|
+
it "always returns true" do
|
14
|
+
matcher.should be_possible_match(99999)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#matches?" do
|
19
|
+
it "returns false when times_called less than times" do
|
20
|
+
matcher.should_not be_matches(2)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "returns true when times_called == times" do
|
24
|
+
matcher.should be_matches(3)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "returns true when times_called > times" do
|
28
|
+
matcher.should be_matches(4)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "#attempt?" do
|
33
|
+
it "always returns true" do
|
34
|
+
matcher.should be_attempt(1)
|
35
|
+
matcher.should be_attempt(100000)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe AnyTimesMatcher, "#terminal?" do
|
40
|
+
it "returns false" do
|
41
|
+
matcher.should_not be_terminal
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "#error_message" do
|
46
|
+
it "has an error message" do
|
47
|
+
matcher.error_message(2).should == (
|
48
|
+
"Called 2 times.\nExpected at least 3 times."
|
49
|
+
)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
|
2
|
+
|
3
|
+
module RR
|
4
|
+
module TimesCalledMatchers
|
5
|
+
describe AtMostMatcher do
|
6
|
+
attr_reader :matcher, :times
|
7
|
+
before do
|
8
|
+
@times = 3
|
9
|
+
@matcher = AtMostMatcher.new(times)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe AtMostMatcher, "#possible_match?" do
|
13
|
+
it "returns true when times called < times" do
|
14
|
+
matcher.should be_possible_match(2)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "returns true when times called == times" do
|
18
|
+
matcher.should be_possible_match(3)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns false when times called > times" do
|
22
|
+
matcher.should_not be_possible_match(4)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe AtMostMatcher, "#matches?" do
|
27
|
+
it "returns true when times_called less than times" do
|
28
|
+
matcher.should be_matches(2)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "returns true when times_called == times" do
|
32
|
+
matcher.should be_matches(3)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "returns false when times_called > times" do
|
36
|
+
matcher.should_not be_matches(4)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe AtMostMatcher, "#attempt?" do
|
41
|
+
it "returns true when less than expected times" do
|
42
|
+
matcher.should be_attempt(2)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "returns false when == expected times" do
|
46
|
+
matcher.should_not be_attempt(3)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "returns false when > expected times" do
|
50
|
+
matcher.should_not be_attempt(4)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe AnyTimesMatcher, "#terminal?" do
|
55
|
+
it "returns true" do
|
56
|
+
matcher.should be_terminal
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe AtMostMatcher, "#error_message" do
|
61
|
+
it "has an error message" do
|
62
|
+
matcher.error_message(5).should == (
|
63
|
+
"Called 5 times.\nExpected at most 3 times."
|
64
|
+
)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
|
2
|
+
|
3
|
+
module RR
|
4
|
+
module TimesCalledMatchers
|
5
|
+
describe IntegerMatcher do
|
6
|
+
attr_reader :matcher, :times
|
7
|
+
before do
|
8
|
+
@times = 3
|
9
|
+
@matcher = IntegerMatcher.new(times)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#possible_match?" do
|
13
|
+
it "returns true when times called < times" do
|
14
|
+
matcher.should be_possible_match(2)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "returns true when times called == times" do
|
18
|
+
matcher.should be_possible_match(3)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns false when times called > times" do
|
22
|
+
matcher.should_not be_possible_match(4)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#matches?" do
|
27
|
+
it "returns false when times_called less than times" do
|
28
|
+
matcher.should_not be_matches(2)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "returns true when times_called == times" do
|
32
|
+
matcher.should be_matches(3)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "returns false when times_called > times" do
|
36
|
+
matcher.should_not be_matches(4)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "#attempt?" do
|
41
|
+
it "returns true when less than expected times" do
|
42
|
+
matcher.should be_attempt(2)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "returns false when == expected times" do
|
46
|
+
matcher.should_not be_attempt(3)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "returns false when > expected times" do
|
50
|
+
matcher.should_not be_attempt(4)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe AnyTimesMatcher, "#terminal?" do
|
55
|
+
it "returns true" do
|
56
|
+
matcher.should be_terminal
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "#error_message" do
|
61
|
+
it "has an error message" do
|
62
|
+
matcher.error_message(2).should == (
|
63
|
+
"Called 2 times.\nExpected 3 times."
|
64
|
+
)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
|
2
|
+
|
3
|
+
module RR
|
4
|
+
module TimesCalledMatchers
|
5
|
+
describe ProcMatcher do
|
6
|
+
attr_reader :matcher, :times
|
7
|
+
before do
|
8
|
+
@times = lambda {|other| other == 3}
|
9
|
+
@matcher = ProcMatcher.new(times)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#possible_match?" do
|
13
|
+
it "always returns true" do
|
14
|
+
matcher.should be_possible_match(2)
|
15
|
+
matcher.should be_possible_match(3)
|
16
|
+
matcher.should be_possible_match(10)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#matches?" do
|
21
|
+
it "returns false when lambda returns false" do
|
22
|
+
times.call(2).should be_false
|
23
|
+
matcher.should_not be_matches(2)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "returns true when lambda returns true" do
|
27
|
+
times.call(3).should be_true
|
28
|
+
matcher.should be_matches(3)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "#attempt?" do
|
33
|
+
it "always returns true" do
|
34
|
+
matcher.should be_attempt(2)
|
35
|
+
matcher.should be_attempt(3)
|
36
|
+
matcher.should be_attempt(10)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "#terminal?" do
|
41
|
+
it "returns false" do
|
42
|
+
matcher.should_not be_terminal
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "#error_message" do
|
47
|
+
it "has an error message" do
|
48
|
+
matcher.error_message(1).should =~
|
49
|
+
/Called 1 time.\nExpected #<Proc.*> times./
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
|
2
|
+
|
3
|
+
module RR
|
4
|
+
module TimesCalledMatchers
|
5
|
+
describe RangeMatcher do
|
6
|
+
attr_reader :matcher, :times
|
7
|
+
before do
|
8
|
+
@times = 2..4
|
9
|
+
@matcher = RangeMatcher.new(times)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#possible_match?" do
|
13
|
+
it "returns true when times called < start of range" do
|
14
|
+
matcher.should be_possible_match(1)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "returns true when times called in range" do
|
18
|
+
matcher.should be_possible_match(2)
|
19
|
+
matcher.should be_possible_match(3)
|
20
|
+
matcher.should be_possible_match(4)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "returns false when times called > end of range" do
|
24
|
+
matcher.should_not be_possible_match(5)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "#matches?" do
|
29
|
+
it "returns false when times_called less than start of range" do
|
30
|
+
matcher.should_not be_matches(1)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "returns true when times_called in range" do
|
34
|
+
matcher.should be_matches(2)
|
35
|
+
matcher.should be_matches(3)
|
36
|
+
matcher.should be_matches(4)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "returns false when times_called > end of range" do
|
40
|
+
matcher.should_not be_matches(5)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "#attempt?" do
|
45
|
+
it "returns true when less than start of range" do
|
46
|
+
matcher.should be_attempt(1)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "returns true when in range" do
|
50
|
+
matcher.should be_attempt(2)
|
51
|
+
matcher.should be_attempt(3)
|
52
|
+
matcher.should be_attempt(4)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "returns false when > end of range" do
|
56
|
+
matcher.should_not be_attempt(5)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "#terminal?" do
|
61
|
+
it "returns true" do
|
62
|
+
matcher.should be_terminal
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "#error_message" do
|
67
|
+
it "has an error message" do
|
68
|
+
matcher.error_message(1).should == (
|
69
|
+
"Called 1 time.\nExpected 2..4 times."
|
70
|
+
)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|