rr 0.3.11 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +8 -3
- data/README +130 -39
- data/Rakefile +6 -5
- data/lib/rr.rb +8 -8
- data/lib/rr/adapters/rr_methods.rb +228 -0
- data/lib/rr/adapters/rspec.rb +1 -1
- data/lib/rr/adapters/test_unit.rb +1 -1
- data/lib/rr/double.rb +294 -89
- data/lib/rr/{scenario_creator.rb → double_creator.rb} +65 -66
- data/lib/rr/{scenario_definition.rb → double_definition.rb} +36 -36
- data/lib/rr/{scenario_definition_builder.rb → double_definition_builder.rb} +3 -3
- data/lib/rr/double_insertion.rb +132 -0
- data/lib/rr/{scenario_matches.rb → double_matches.rb} +2 -2
- data/lib/rr/{scenario_method_proxy.rb → double_method_proxy.rb} +2 -2
- data/lib/rr/errors/argument_equality_error.rb +3 -3
- data/lib/rr/errors/rr_error.rb +13 -13
- data/lib/rr/errors/scenario_definition_error.rb +3 -3
- data/lib/rr/errors/scenario_not_found_error.rb +3 -3
- data/lib/rr/errors/scenario_order_error.rb +3 -3
- data/lib/rr/errors/times_called_error.rb +3 -3
- data/lib/rr/expectations/any_argument_expectation.rb +1 -1
- data/lib/rr/expectations/argument_equality_expectation.rb +1 -1
- data/lib/rr/expectations/times_called_expectation.rb +1 -1
- data/lib/rr/hash_with_object_id_key.rb +1 -1
- data/lib/rr/space.rb +40 -40
- data/lib/rr/times_called_matchers/any_times_matcher.rb +13 -13
- data/lib/rr/times_called_matchers/at_least_matcher.rb +11 -11
- data/lib/rr/times_called_matchers/at_most_matcher.rb +16 -16
- data/lib/rr/times_called_matchers/integer_matcher.rb +13 -13
- data/lib/rr/times_called_matchers/non_terminal.rb +21 -21
- data/lib/rr/times_called_matchers/proc_matcher.rb +7 -7
- data/lib/rr/times_called_matchers/range_matcher.rb +14 -14
- data/lib/rr/times_called_matchers/terminal.rb +16 -16
- data/lib/rr/times_called_matchers/times_called_matcher.rb +32 -32
- data/spec/core_spec_suite.rb +18 -0
- data/{examples → spec}/environment_fixture_setup.rb +0 -1
- data/{examples/high_level_example.rb → spec/high_level_spec.rb} +11 -11
- data/spec/rr/adapters/rr_methods_argument_matcher_spec.rb +67 -0
- data/spec/rr/adapters/rr_methods_creator_spec.rb +365 -0
- data/spec/rr/adapters/rr_methods_space_spec.rb +134 -0
- data/spec/rr/adapters/rr_methods_spec_helper.rb +11 -0
- data/{examples/rr/extensions/instance_methods_times_matcher_example.rb → spec/rr/adapters/rr_methods_times_matcher_spec.rb} +4 -4
- data/spec/rr/double/double_insertion_bind_spec.rb +78 -0
- data/spec/rr/double/double_insertion_dispatching_spec.rb +221 -0
- data/spec/rr/double/double_insertion_has_original_method_spec.rb +56 -0
- data/spec/rr/double/double_insertion_register_scenario_spec.rb +24 -0
- data/spec/rr/double/double_insertion_reset_spec.rb +89 -0
- data/spec/rr/double/double_insertion_spec.rb +66 -0
- data/spec/rr/double/double_insertion_verify_spec.rb +23 -0
- data/spec/rr/double_creator_spec.rb +454 -0
- data/{examples/rr/scenario_definition_example.rb → spec/rr/double_definition_spec.rb} +143 -143
- data/spec/rr/double_method_proxy_spec.rb +71 -0
- data/spec/rr/double_spec.rb +654 -0
- data/spec/rr/errors/rr_error_spec.rb +65 -0
- data/spec/rr/expectations/any_argument_expectation_spec.rb +47 -0
- data/spec/rr/expectations/anything_argument_equality_expectation_spec.rb +38 -0
- data/spec/rr/expectations/argument_equality_expectation_spec.rb +58 -0
- data/spec/rr/expectations/boolean_argument_equality_expectation_spec.rb +53 -0
- data/spec/rr/expectations/duck_type_argument_equality_expectation_spec.rb +71 -0
- data/spec/rr/expectations/is_a_argument_equality_expectation_spec.rb +51 -0
- data/spec/rr/expectations/numeric_argument_equality_expectation_spec.rb +47 -0
- data/spec/rr/expectations/range_argument_equality_expectation_spec.rb +59 -0
- data/spec/rr/expectations/regexp_argument_equality_expectation_spec.rb +72 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_any_times_spec.rb +43 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_least_spec.rb +67 -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 +21 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_integer_spec.rb +103 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_proc_spec.rb +79 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_range_spec.rb +81 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_spec.rb +40 -0
- data/spec/rr/rspec/rspec_adapter_spec.rb +65 -0
- data/spec/rr/rspec/rspec_backtrace_tweaking_spec.rb +52 -0
- data/spec/rr/rspec/rspec_usage_spec.rb +67 -0
- data/spec/rr/space/hash_with_object_id_key_spec.rb +88 -0
- data/spec/rr/space/space_create_spec.rb +278 -0
- data/spec/rr/space/space_helper.rb +7 -0
- data/spec/rr/space/space_register_spec.rb +32 -0
- data/spec/rr/space/space_reset_spec.rb +131 -0
- data/spec/rr/space/space_spec.rb +32 -0
- data/spec/rr/space/space_verify_spec.rb +181 -0
- data/{examples → spec}/rr/test_unit/test_helper.rb +1 -1
- data/{examples → spec}/rr/test_unit/test_unit_backtrace_test.rb +0 -0
- data/{examples → spec}/rr/test_unit/test_unit_integration_test.rb +4 -4
- 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/rspec_spec_suite.rb +16 -0
- data/spec/spec_helper.rb +9 -0
- data/{examples/example_suite.rb → spec/spec_suite.rb} +3 -3
- data/{examples/test_unit_example_suite.rb → spec/test_unit_spec_suite.rb} +0 -0
- metadata +93 -93
- data/examples/core_example_suite.rb +0 -31
- data/examples/example_helper.rb +0 -9
- data/examples/rr/double/double_bind_example.rb +0 -70
- data/examples/rr/double/double_dispatching_example.rb +0 -236
- data/examples/rr/double/double_example.rb +0 -66
- data/examples/rr/double/double_has_original_method_example.rb +0 -56
- data/examples/rr/double/double_register_scenario_example.rb +0 -24
- data/examples/rr/double/double_reset_example.rb +0 -89
- data/examples/rr/double/double_verify_example.rb +0 -23
- data/examples/rr/errors/rr_error_example.rb +0 -65
- data/examples/rr/expectations/any_argument_expectation_example.rb +0 -52
- data/examples/rr/expectations/anything_argument_equality_expectation_example.rb +0 -38
- data/examples/rr/expectations/argument_equality_expectation_example.rb +0 -62
- data/examples/rr/expectations/boolean_argument_equality_expectation_example.rb +0 -48
- data/examples/rr/expectations/duck_type_argument_equality_expectation_example.rb +0 -67
- data/examples/rr/expectations/is_a_argument_equality_expectation_example.rb +0 -50
- data/examples/rr/expectations/numeric_argument_equality_expectation_example.rb +0 -46
- data/examples/rr/expectations/range_argument_equality_expectation_example.rb +0 -59
- data/examples/rr/expectations/regexp_argument_equality_expectation_example.rb +0 -67
- data/examples/rr/expectations/times_called_expectation/times_called_expectation_any_times_example.rb +0 -50
- data/examples/rr/expectations/times_called_expectation/times_called_expectation_at_least_example.rb +0 -73
- data/examples/rr/expectations/times_called_expectation/times_called_expectation_at_most_example.rb +0 -77
- data/examples/rr/expectations/times_called_expectation/times_called_expectation_example.rb +0 -42
- data/examples/rr/expectations/times_called_expectation/times_called_expectation_helper.rb +0 -20
- data/examples/rr/expectations/times_called_expectation/times_called_expectation_integer_example.rb +0 -111
- data/examples/rr/expectations/times_called_expectation/times_called_expectation_proc_example.rb +0 -88
- data/examples/rr/expectations/times_called_expectation/times_called_expectation_range_example.rb +0 -90
- data/examples/rr/extensions/instance_methods_argument_matcher_example.rb +0 -65
- data/examples/rr/extensions/instance_methods_creator_example.rb +0 -363
- data/examples/rr/extensions/instance_methods_example_helper.rb +0 -11
- data/examples/rr/extensions/instance_methods_space_example.rb +0 -122
- data/examples/rr/rspec/rspec_adapter_example.rb +0 -63
- data/examples/rr/rspec/rspec_backtrace_tweaking_example.rb +0 -36
- data/examples/rr/rspec/rspec_usage_example.rb +0 -65
- data/examples/rr/scenario_creator_example.rb +0 -459
- data/examples/rr/scenario_example.rb +0 -701
- data/examples/rr/scenario_method_proxy_example.rb +0 -71
- data/examples/rr/space/hash_with_object_id_key_example.rb +0 -86
- data/examples/rr/space/space_create_example.rb +0 -278
- data/examples/rr/space/space_example.rb +0 -29
- data/examples/rr/space/space_helper.rb +0 -7
- data/examples/rr/space/space_register_example.rb +0 -32
- data/examples/rr/space/space_reset_example.rb +0 -120
- data/examples/rr/space/space_verify_example.rb +0 -169
- data/examples/rr/times_called_matchers/any_times_matcher_example.rb +0 -63
- data/examples/rr/times_called_matchers/at_least_matcher_example.rb +0 -70
- data/examples/rr/times_called_matchers/at_most_matcher_example.rb +0 -85
- data/examples/rr/times_called_matchers/integer_matcher_example.rb +0 -91
- data/examples/rr/times_called_matchers/proc_matcher_example.rb +0 -77
- data/examples/rr/times_called_matchers/range_matcher_example.rb +0 -97
- data/examples/rr/times_called_matchers/times_called_matcher_example.rb +0 -53
- data/examples/rspec_example_suite.rb +0 -25
- data/lib/rr/extensions/instance_methods.rb +0 -228
- data/lib/rr/scenario.rb +0 -337
@@ -0,0 +1,55 @@
|
|
1
|
+
require "spec/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 "spec/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 "spec/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 "spec/spec_helper"
|
2
|
+
|
3
|
+
module RR
|
4
|
+
module TimesCalledMatchers
|
5
|
+
describe ProcMatcher do
|
6
|
+
attr_reader :matcher, :times
|
7
|
+
before do
|
8
|
+
@times = proc {|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 proc 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 proc 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 "spec/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
|
@@ -0,0 +1,118 @@
|
|
1
|
+
require "spec/spec_helper"
|
2
|
+
|
3
|
+
module RR
|
4
|
+
module TimesCalledMatchers
|
5
|
+
describe TimesCalledMatcher do
|
6
|
+
describe ".create" do
|
7
|
+
describe "when passed a AnyTimesMatcher" do
|
8
|
+
it "returns the passed in argument" do
|
9
|
+
matcher = AnyTimesMatcher.new
|
10
|
+
TimesCalledMatcher.create(matcher).should === matcher
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "when passed a AtLeastMatcher" do
|
15
|
+
it "returns the passed in argument" do
|
16
|
+
matcher = AtLeastMatcher.new(5)
|
17
|
+
TimesCalledMatcher.create(matcher).should === matcher
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "when passed a AtMostMatcher" do
|
22
|
+
it "returns the passed in argument" do
|
23
|
+
matcher = AtMostMatcher.new(5)
|
24
|
+
TimesCalledMatcher.create(matcher).should === matcher
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "when passed a IntegerMatcher" do
|
29
|
+
it "returns the passed in argument" do
|
30
|
+
matcher = IntegerMatcher.new(5)
|
31
|
+
TimesCalledMatcher.create(matcher).should === matcher
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "when passed a Integer" do
|
36
|
+
it "returns IntegerMatcher" do
|
37
|
+
TimesCalledMatcher.create(5).should == IntegerMatcher.new(5)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "when passed a ProcMatcher" do
|
42
|
+
it "returns the passed in argument" do
|
43
|
+
matcher = ProcMatcher.new(proc {|other| other == 5})
|
44
|
+
TimesCalledMatcher.create(matcher).should === matcher
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "when passed a Lambda" do
|
49
|
+
it "returns ProcMatcher" do
|
50
|
+
value = proc {|other| other == 5}
|
51
|
+
TimesCalledMatcher.create(value).should == ProcMatcher.new(value)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "when passed a IntegerMatcher" do
|
56
|
+
it "returns the passed in argument" do
|
57
|
+
matcher = RangeMatcher.new(2..4)
|
58
|
+
TimesCalledMatcher.create(matcher).should === matcher
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "when passed a Integer" do
|
63
|
+
it "returns RangeMatcher" do
|
64
|
+
TimesCalledMatcher.create(2..4).should == RangeMatcher.new(2..4)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "when passed a TimesCalledMatcher" do
|
69
|
+
it "returns the passed in argument" do
|
70
|
+
matcher = TimesCalledMatcher.new(5)
|
71
|
+
TimesCalledMatcher.create(matcher).should === matcher
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "when passed an unsupported type" do
|
76
|
+
it "raises an ArgumentError" do
|
77
|
+
matcher = Object.new
|
78
|
+
proc do
|
79
|
+
TimesCalledMatcher.create(matcher)
|
80
|
+
end.should raise_error(ArgumentError, "There is no TimesCalledMatcher for #{matcher.inspect}.")
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "#error_message" do
|
86
|
+
before do
|
87
|
+
@times = 3
|
88
|
+
@matcher = TimesCalledMatcher.new(@times)
|
89
|
+
end
|
90
|
+
|
91
|
+
it "has an error message" do
|
92
|
+
@matcher.error_message(5).should == (
|
93
|
+
"Called 5 times.\nExpected 3 times."
|
94
|
+
)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe "#==" do
|
99
|
+
before do
|
100
|
+
@times = 3
|
101
|
+
@matcher = TimesCalledMatcher.new(@times)
|
102
|
+
end
|
103
|
+
|
104
|
+
it "returns true when other is the same class and times are ==" do
|
105
|
+
@matcher.should == TimesCalledMatcher.new(@times)
|
106
|
+
end
|
107
|
+
|
108
|
+
it "returns false when other is a different class and times are ==" do
|
109
|
+
@matcher.should_not == IntegerMatcher.new(@times)
|
110
|
+
end
|
111
|
+
|
112
|
+
it "returns false when is the same class and times are not ==" do
|
113
|
+
@matcher.should_not == TimesCalledMatcher.new(1)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|