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
@@ -1,85 +0,0 @@
|
|
1
|
-
require "examples/example_helper"
|
2
|
-
|
3
|
-
module RR
|
4
|
-
module TimesCalledMatchers
|
5
|
-
describe AtMostMatcher, :shared => true do
|
6
|
-
before do
|
7
|
-
@times = 3
|
8
|
-
@matcher = AtMostMatcher.new(@times)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
describe TimesCalledMatcher, ".create when passed a AtMostMatcher" do
|
13
|
-
it "returns the passed in argument" do
|
14
|
-
matcher = AtMostMatcher.new(5)
|
15
|
-
TimesCalledMatcher.create(matcher).should === matcher
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
describe AtMostMatcher, "#possible_match?" do
|
20
|
-
it_should_behave_like "RR::TimesCalledMatchers::AtMostMatcher"
|
21
|
-
|
22
|
-
it "returns true when times called < times" do
|
23
|
-
@matcher.should be_possible_match(2)
|
24
|
-
end
|
25
|
-
|
26
|
-
it "returns true when times called == times" do
|
27
|
-
@matcher.should be_possible_match(3)
|
28
|
-
end
|
29
|
-
|
30
|
-
it "returns false when times called > times" do
|
31
|
-
@matcher.should_not be_possible_match(4)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
describe AtMostMatcher, "#matches?" do
|
36
|
-
it_should_behave_like "RR::TimesCalledMatchers::AtMostMatcher"
|
37
|
-
|
38
|
-
it "returns true when times_called less than times" do
|
39
|
-
@matcher.should be_matches(2)
|
40
|
-
end
|
41
|
-
|
42
|
-
it "returns true when times_called == times" do
|
43
|
-
@matcher.should be_matches(3)
|
44
|
-
end
|
45
|
-
|
46
|
-
it "returns false when times_called > times" do
|
47
|
-
@matcher.should_not be_matches(4)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
describe AtMostMatcher, "#attempt?" do
|
52
|
-
it_should_behave_like "RR::TimesCalledMatchers::AtMostMatcher"
|
53
|
-
|
54
|
-
it "returns true when less than expected times" do
|
55
|
-
@matcher.should be_attempt(2)
|
56
|
-
end
|
57
|
-
|
58
|
-
it "returns false when == expected times" do
|
59
|
-
@matcher.should_not be_attempt(3)
|
60
|
-
end
|
61
|
-
|
62
|
-
it "returns false when > expected times" do
|
63
|
-
@matcher.should_not be_attempt(4)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
describe AnyTimesMatcher, "#terminal?" do
|
68
|
-
it_should_behave_like "RR::TimesCalledMatchers::AtMostMatcher"
|
69
|
-
|
70
|
-
it "returns true" do
|
71
|
-
@matcher.should be_terminal
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
describe AtMostMatcher, "#error_message" do
|
76
|
-
it_should_behave_like "RR::TimesCalledMatchers::AtMostMatcher"
|
77
|
-
|
78
|
-
it "has an error message" do
|
79
|
-
@matcher.error_message(5).should == (
|
80
|
-
"Called 5 times.\nExpected at most 3 times."
|
81
|
-
)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
@@ -1,91 +0,0 @@
|
|
1
|
-
require "examples/example_helper"
|
2
|
-
|
3
|
-
module RR
|
4
|
-
module TimesCalledMatchers
|
5
|
-
describe IntegerMatcher, :shared => true do
|
6
|
-
before do
|
7
|
-
@times = 3
|
8
|
-
@matcher = IntegerMatcher.new(@times)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
describe TimesCalledMatcher, ".create when passed a IntegerMatcher" do
|
13
|
-
it "returns the passed in argument" do
|
14
|
-
matcher = IntegerMatcher.new(5)
|
15
|
-
TimesCalledMatcher.create(matcher).should === matcher
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
describe TimesCalledMatcher, ".create when passed a Integer" do
|
20
|
-
it "returns IntegerMatcher" do
|
21
|
-
TimesCalledMatcher.create(5).should == IntegerMatcher.new(5)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
describe IntegerMatcher, "#possible_match?" do
|
26
|
-
it_should_behave_like "RR::TimesCalledMatchers::IntegerMatcher"
|
27
|
-
|
28
|
-
it "returns true when times called < times" do
|
29
|
-
@matcher.should be_possible_match(2)
|
30
|
-
end
|
31
|
-
|
32
|
-
it "returns true when times called == times" do
|
33
|
-
@matcher.should be_possible_match(3)
|
34
|
-
end
|
35
|
-
|
36
|
-
it "returns false when times called > times" do
|
37
|
-
@matcher.should_not be_possible_match(4)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
describe IntegerMatcher, "#matches?" do
|
42
|
-
it_should_behave_like "RR::TimesCalledMatchers::IntegerMatcher"
|
43
|
-
|
44
|
-
it "returns false when times_called less than times" do
|
45
|
-
@matcher.should_not be_matches(2)
|
46
|
-
end
|
47
|
-
|
48
|
-
it "returns true when times_called == times" do
|
49
|
-
@matcher.should be_matches(3)
|
50
|
-
end
|
51
|
-
|
52
|
-
it "returns false when times_called > times" do
|
53
|
-
@matcher.should_not be_matches(4)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
describe IntegerMatcher, "#attempt?" do
|
58
|
-
it_should_behave_like "RR::TimesCalledMatchers::IntegerMatcher"
|
59
|
-
|
60
|
-
it "returns true when less than expected times" do
|
61
|
-
@matcher.should be_attempt(2)
|
62
|
-
end
|
63
|
-
|
64
|
-
it "returns false when == expected times" do
|
65
|
-
@matcher.should_not be_attempt(3)
|
66
|
-
end
|
67
|
-
|
68
|
-
it "returns false when > expected times" do
|
69
|
-
@matcher.should_not be_attempt(4)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
describe AnyTimesMatcher, "#terminal?" do
|
74
|
-
it_should_behave_like "RR::TimesCalledMatchers::IntegerMatcher"
|
75
|
-
|
76
|
-
it "returns true" do
|
77
|
-
@matcher.should be_terminal
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
describe IntegerMatcher, "#error_message" do
|
82
|
-
it_should_behave_like "RR::TimesCalledMatchers::IntegerMatcher"
|
83
|
-
|
84
|
-
it "has an error message" do
|
85
|
-
@matcher.error_message(2).should == (
|
86
|
-
"Called 2 times.\nExpected 3 times."
|
87
|
-
)
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
@@ -1,77 +0,0 @@
|
|
1
|
-
require "examples/example_helper"
|
2
|
-
|
3
|
-
module RR
|
4
|
-
module TimesCalledMatchers
|
5
|
-
describe ProcMatcher, :shared => true do
|
6
|
-
before do
|
7
|
-
@times = proc {|other| other == 3}
|
8
|
-
@matcher = ProcMatcher.new(@times)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
describe TimesCalledMatcher, ".create when passed a ProcMatcher" do
|
13
|
-
it "returns the passed in argument" do
|
14
|
-
matcher = ProcMatcher.new(proc {|other| other == 5})
|
15
|
-
TimesCalledMatcher.create(matcher).should === matcher
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
describe TimesCalledMatcher, ".create when passed a Integer" do
|
20
|
-
it "returns ProcMatcher" do
|
21
|
-
value = proc {|other| other == 5}
|
22
|
-
TimesCalledMatcher.create(value).should == ProcMatcher.new(value)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
describe ProcMatcher, "#possible_match?" do
|
27
|
-
it_should_behave_like "RR::TimesCalledMatchers::ProcMatcher"
|
28
|
-
|
29
|
-
it "always returns true" do
|
30
|
-
@matcher.should be_possible_match(2)
|
31
|
-
@matcher.should be_possible_match(3)
|
32
|
-
@matcher.should be_possible_match(10)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
describe ProcMatcher, "#matches?" do
|
37
|
-
it_should_behave_like "RR::TimesCalledMatchers::ProcMatcher"
|
38
|
-
|
39
|
-
it "returns false when proc returns false" do
|
40
|
-
@times.call(2).should be_false
|
41
|
-
@matcher.should_not be_matches(2)
|
42
|
-
end
|
43
|
-
|
44
|
-
it "returns true when proc returns true" do
|
45
|
-
@times.call(3).should be_true
|
46
|
-
@matcher.should be_matches(3)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
describe ProcMatcher, "#attempt?" do
|
51
|
-
it_should_behave_like "RR::TimesCalledMatchers::ProcMatcher"
|
52
|
-
|
53
|
-
it "always returns true" do
|
54
|
-
@matcher.should be_attempt(2)
|
55
|
-
@matcher.should be_attempt(3)
|
56
|
-
@matcher.should be_attempt(10)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
describe ProcMatcher, "#terminal?" do
|
61
|
-
it_should_behave_like "RR::TimesCalledMatchers::ProcMatcher"
|
62
|
-
|
63
|
-
it "returns false" do
|
64
|
-
@matcher.should_not be_terminal
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
describe ProcMatcher, "#error_message" do
|
69
|
-
it_should_behave_like "RR::TimesCalledMatchers::ProcMatcher"
|
70
|
-
|
71
|
-
it "has an error message" do
|
72
|
-
@matcher.error_message(1).should =~
|
73
|
-
/Called 1 time.\nExpected #<Proc.*> times./
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
@@ -1,97 +0,0 @@
|
|
1
|
-
require "examples/example_helper"
|
2
|
-
|
3
|
-
module RR
|
4
|
-
module TimesCalledMatchers
|
5
|
-
describe RangeMatcher, :shared => true do
|
6
|
-
before do
|
7
|
-
@times = 2..4
|
8
|
-
@matcher = RangeMatcher.new(@times)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
describe TimesCalledMatcher, ".create when passed a IntegerMatcher" do
|
13
|
-
it "returns the passed in argument" do
|
14
|
-
matcher = RangeMatcher.new(2..4)
|
15
|
-
TimesCalledMatcher.create(matcher).should === matcher
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
describe TimesCalledMatcher, ".create when passed a Integer" do
|
20
|
-
it "returns RangeMatcher" do
|
21
|
-
TimesCalledMatcher.create(2..4).should == RangeMatcher.new(2..4)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
describe RangeMatcher, "#possible_match?" do
|
26
|
-
it_should_behave_like "RR::TimesCalledMatchers::RangeMatcher"
|
27
|
-
|
28
|
-
it "returns true when times called < start of range" do
|
29
|
-
@matcher.should be_possible_match(1)
|
30
|
-
end
|
31
|
-
|
32
|
-
it "returns true when times called in range" do
|
33
|
-
@matcher.should be_possible_match(2)
|
34
|
-
@matcher.should be_possible_match(3)
|
35
|
-
@matcher.should be_possible_match(4)
|
36
|
-
end
|
37
|
-
|
38
|
-
it "returns false when times called > end of range" do
|
39
|
-
@matcher.should_not be_possible_match(5)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe RangeMatcher, "#matches?" do
|
44
|
-
it_should_behave_like "RR::TimesCalledMatchers::RangeMatcher"
|
45
|
-
|
46
|
-
it "returns false when times_called less than start of range" do
|
47
|
-
@matcher.should_not be_matches(1)
|
48
|
-
end
|
49
|
-
|
50
|
-
it "returns true when times_called in range" do
|
51
|
-
@matcher.should be_matches(2)
|
52
|
-
@matcher.should be_matches(3)
|
53
|
-
@matcher.should be_matches(4)
|
54
|
-
end
|
55
|
-
|
56
|
-
it "returns false when times_called > end of range" do
|
57
|
-
@matcher.should_not be_matches(5)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
describe RangeMatcher, "#attempt?" do
|
62
|
-
it_should_behave_like "RR::TimesCalledMatchers::RangeMatcher"
|
63
|
-
|
64
|
-
it "returns true when less than start of range" do
|
65
|
-
@matcher.should be_attempt(1)
|
66
|
-
end
|
67
|
-
|
68
|
-
it "returns true when in range" do
|
69
|
-
@matcher.should be_attempt(2)
|
70
|
-
@matcher.should be_attempt(3)
|
71
|
-
@matcher.should be_attempt(4)
|
72
|
-
end
|
73
|
-
|
74
|
-
it "returns false when > end of range" do
|
75
|
-
@matcher.should_not be_attempt(5)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
describe RangeMatcher, "#terminal?" do
|
80
|
-
it_should_behave_like "RR::TimesCalledMatchers::RangeMatcher"
|
81
|
-
|
82
|
-
it "returns true" do
|
83
|
-
@matcher.should be_terminal
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
describe RangeMatcher, "#error_message" do
|
88
|
-
it_should_behave_like "RR::TimesCalledMatchers::RangeMatcher"
|
89
|
-
|
90
|
-
it "has an error message" do
|
91
|
-
@matcher.error_message(1).should == (
|
92
|
-
"Called 1 time.\nExpected 2..4 times."
|
93
|
-
)
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
require "examples/example_helper"
|
2
|
-
|
3
|
-
module RR
|
4
|
-
module TimesCalledMatchers
|
5
|
-
describe TimesCalledMatcher, ".create when passed a TimesCalledMatcher" do
|
6
|
-
it "returns the passed in argument" do
|
7
|
-
matcher = TimesCalledMatcher.new(5)
|
8
|
-
TimesCalledMatcher.create(matcher).should === matcher
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
describe TimesCalledMatcher, ".create when passed an unsupported type" do
|
13
|
-
it "raises an ArgumentError" do
|
14
|
-
matcher = Object.new
|
15
|
-
proc do
|
16
|
-
TimesCalledMatcher.create(matcher)
|
17
|
-
end.should raise_error(ArgumentError, "There is no TimesCalledMatcher for #{matcher.inspect}.")
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
describe TimesCalledMatcher, "#error_message" do
|
22
|
-
before do
|
23
|
-
@times = 3
|
24
|
-
@matcher = TimesCalledMatcher.new(@times)
|
25
|
-
end
|
26
|
-
|
27
|
-
it "has an error message" do
|
28
|
-
@matcher.error_message(5).should == (
|
29
|
-
"Called 5 times.\nExpected 3 times."
|
30
|
-
)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
describe TimesCalledMatcher, "#==" do
|
35
|
-
before do
|
36
|
-
@times = 3
|
37
|
-
@matcher = TimesCalledMatcher.new(@times)
|
38
|
-
end
|
39
|
-
|
40
|
-
it "returns true when other is the same class and times are ==" do
|
41
|
-
@matcher.should == TimesCalledMatcher.new(@times)
|
42
|
-
end
|
43
|
-
|
44
|
-
it "returns false when other is a different class and times are ==" do
|
45
|
-
@matcher.should_not == IntegerMatcher.new(@times)
|
46
|
-
end
|
47
|
-
|
48
|
-
it "returns false when is the same class and times are not ==" do
|
49
|
-
@matcher.should_not == TimesCalledMatcher.new(1)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
require "rubygems"
|
2
|
-
require "spec"
|
3
|
-
|
4
|
-
class RspecExampleSuite
|
5
|
-
def run
|
6
|
-
options = ::Spec::Runner::OptionParser.new.parse(ARGV.dup, STDERR, STDOUT, false)
|
7
|
-
options.configure
|
8
|
-
$behaviour_runner = options.create_behaviour_runner
|
9
|
-
|
10
|
-
require_specs
|
11
|
-
puts "Running Rspec Example Suite"
|
12
|
-
$behaviour_runner.run(ARGV, false)
|
13
|
-
end
|
14
|
-
|
15
|
-
def require_specs
|
16
|
-
dir = File.dirname(__FILE__)
|
17
|
-
Dir["#{dir}/rr/rspec/**/*_example.rb"].each do |file|
|
18
|
-
require file
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
if $0 == __FILE__
|
24
|
-
RspecExampleSuite.new.run
|
25
|
-
end
|
@@ -1,228 +0,0 @@
|
|
1
|
-
module RR
|
2
|
-
module Extensions
|
3
|
-
module InstanceMethods
|
4
|
-
# Verifies all the Double objects have met their
|
5
|
-
# TimesCalledExpectations.
|
6
|
-
def verify
|
7
|
-
RR::Space.instance.verify_doubles
|
8
|
-
end
|
9
|
-
|
10
|
-
# Resets the registered Doubles and ordered Scenarios
|
11
|
-
def reset
|
12
|
-
RR::Space.instance.reset
|
13
|
-
end
|
14
|
-
|
15
|
-
# This method sets the Scenario to have a mock strategy. A mock strategy
|
16
|
-
# sets the default state of the Scenario to expect the method call
|
17
|
-
# with arguments exactly one time. The Scenario's expectations can be
|
18
|
-
# changed.
|
19
|
-
#
|
20
|
-
# This method can be chained with probe.
|
21
|
-
# mock.probe(subject).method_name_1
|
22
|
-
# or
|
23
|
-
# probe.mock(subject).method_name_1
|
24
|
-
#
|
25
|
-
# When passed the subject, a ScenarioMethodProxy is returned. Passing
|
26
|
-
# a method with arguments to the proxy will set up expectations that
|
27
|
-
# the a call to the subject's method with the arguments will happen,
|
28
|
-
# and return the prescribed value.
|
29
|
-
# mock(subject).method_name_1 {return_value_1}
|
30
|
-
# mock(subject).method_name_2(arg1, arg2) {return_value_2}
|
31
|
-
#
|
32
|
-
# When passed the subject and the method_name, this method returns
|
33
|
-
# a mock Scenario with the method already set.
|
34
|
-
#
|
35
|
-
# mock(subject, :method_name_1) {return_value_1}
|
36
|
-
# mock(subject, :method_name_2).with(arg1, arg2) {return_value_2}
|
37
|
-
#
|
38
|
-
# mock also takes a block for definitions.
|
39
|
-
# mock(subject) do
|
40
|
-
# method_name_1 {return_value_1}
|
41
|
-
# method_name_2(arg_1, arg_2) {return_value_2}
|
42
|
-
# end
|
43
|
-
def mock(subject=ScenarioCreator::NO_SUBJECT_ARG, method_name=nil, &definition)
|
44
|
-
creator = RR::Space.scenario_creator
|
45
|
-
creator.mock(subject, method_name, &definition)
|
46
|
-
end
|
47
|
-
|
48
|
-
|
49
|
-
# This method sets the Scenario to have a stub strategy. A stub strategy
|
50
|
-
# sets the default state of the Scenario to expect the method call
|
51
|
-
# with any arguments any number of times. The Scenario's
|
52
|
-
# expectations can be changed.
|
53
|
-
#
|
54
|
-
# This method can be chained with probe.
|
55
|
-
# stub.probe(subject).method_name_1
|
56
|
-
# or
|
57
|
-
# probe.stub(subject).method_name_1
|
58
|
-
#
|
59
|
-
# When passed the subject, a ScenarioMethodProxy is returned. Passing
|
60
|
-
# a method with arguments to the proxy will set up expectations that
|
61
|
-
# the a call to the subject's method with the arguments will happen,
|
62
|
-
# and return the prescribed value.
|
63
|
-
# stub(subject).method_name_1 {return_value_1}
|
64
|
-
# stub(subject).method_name_2(arg_1, arg_2) {return_value_2}
|
65
|
-
#
|
66
|
-
# When passed the subject and the method_name, this method returns
|
67
|
-
# a stub Scenario with the method already set.
|
68
|
-
#
|
69
|
-
# mock(subject, :method_name_1) {return_value_1}
|
70
|
-
# mock(subject, :method_name_2).with(arg1, arg2) {return_value_2}
|
71
|
-
#
|
72
|
-
# stub also takes a block for definitions.
|
73
|
-
# stub(subject) do
|
74
|
-
# method_name_1 {return_value_1}
|
75
|
-
# method_name_2(arg_1, arg_2) {return_value_2}
|
76
|
-
# end
|
77
|
-
def stub(subject=ScenarioCreator::NO_SUBJECT_ARG, method_name=nil, &definition)
|
78
|
-
creator = RR::Space.scenario_creator
|
79
|
-
creator.stub(subject, method_name, &definition)
|
80
|
-
end
|
81
|
-
|
82
|
-
# This method add probe capabilities to the Scenario. probe can be called
|
83
|
-
# with mock or stub.
|
84
|
-
#
|
85
|
-
# mock.probe(controller.template).render(:partial => "my/socks")
|
86
|
-
#
|
87
|
-
# stub.probe(controller.template).render(:partial => "my/socks") do |html|
|
88
|
-
# html.should include("My socks are wet")
|
89
|
-
# html
|
90
|
-
# end
|
91
|
-
#
|
92
|
-
# mock.probe(controller.template).render(:partial => "my/socks") do |html|
|
93
|
-
# html.should include("My socks are wet")
|
94
|
-
# "My new return value"
|
95
|
-
# end
|
96
|
-
#
|
97
|
-
# mock.probe also takes a block for definitions.
|
98
|
-
# mock.probe(subject) do
|
99
|
-
# render(:partial => "my/socks")
|
100
|
-
#
|
101
|
-
# render(:partial => "my/socks") do |html|
|
102
|
-
# html.should include("My socks are wet")
|
103
|
-
# html
|
104
|
-
# end
|
105
|
-
#
|
106
|
-
# render(:partial => "my/socks") do |html|
|
107
|
-
# html.should include("My socks are wet")
|
108
|
-
# html
|
109
|
-
# end
|
110
|
-
#
|
111
|
-
# render(:partial => "my/socks") do |html|
|
112
|
-
# html.should include("My socks are wet")
|
113
|
-
# "My new return value"
|
114
|
-
# end
|
115
|
-
# end
|
116
|
-
#
|
117
|
-
# Passing a block to the Scenario (after the method name and arguments)
|
118
|
-
# allows you to intercept the return value.
|
119
|
-
# The return value can be modified, validated, and/or overridden by
|
120
|
-
# passing in a block. The return value of the block will replace
|
121
|
-
# the actual return value.
|
122
|
-
#
|
123
|
-
# mock.probe(controller.template).render(:partial => "my/socks") do |html|
|
124
|
-
# html.should include("My socks are wet")
|
125
|
-
# "My new return value"
|
126
|
-
# end
|
127
|
-
def probe(subject=ScenarioCreator::NO_SUBJECT_ARG, method_name=nil, &definition)
|
128
|
-
creator = RR::Space.scenario_creator
|
129
|
-
creator.probe(subject, method_name, &definition)
|
130
|
-
end
|
131
|
-
|
132
|
-
# This method sets the Scenario to have a do_not_call strategy.
|
133
|
-
# A do_not_call strategy sets the default state of the Scenario
|
134
|
-
# to expect never to be called. The Scenario's expectations can be
|
135
|
-
# changed.
|
136
|
-
#
|
137
|
-
# The following example sets the expectation that subject.method_name
|
138
|
-
# will never be called with arg1 and arg2.
|
139
|
-
#
|
140
|
-
# do_not_allow(subject).method_name(arg1, arg2)
|
141
|
-
#
|
142
|
-
# do_not_call also supports a block sytnax.
|
143
|
-
# do_not_call(subject) do |m|
|
144
|
-
# m.method1 # Do not allow method1 with any arguments
|
145
|
-
# m.method2(arg1, arg2) # Do not allow method2 with arguments arg1 and arg2
|
146
|
-
# m.method3.with_no_args # Do not allow method3 with no arguments
|
147
|
-
# end
|
148
|
-
def do_not_call(subject=ScenarioCreator::NO_SUBJECT_ARG, method_name=nil, &definition)
|
149
|
-
creator = RR::Space.scenario_creator
|
150
|
-
creator.do_not_call(subject, method_name, &definition)
|
151
|
-
end
|
152
|
-
alias_method :dont_call, :do_not_call
|
153
|
-
alias_method :do_not_allow, :do_not_call
|
154
|
-
alias_method :dont_allow, :do_not_call
|
155
|
-
|
156
|
-
# Calling instance_of will cause all instances of the passed in Class
|
157
|
-
# to have the Scenario defined.
|
158
|
-
#
|
159
|
-
# The following example mocks all User's valid? method and return false.
|
160
|
-
# mock.instance_of(User).valid? {false}
|
161
|
-
#
|
162
|
-
# The following example mocks and probes User#projects and returns the
|
163
|
-
# first 3 projects.
|
164
|
-
# mock.instance_of(User).projects do |projects|
|
165
|
-
# projects[0..2]
|
166
|
-
# end
|
167
|
-
def instance_of(subject=ScenarioCreator::NO_SUBJECT_ARG, method_name=nil, &definition)
|
168
|
-
creator = RR::Space.scenario_creator
|
169
|
-
creator.instance_of(subject, method_name, &definition)
|
170
|
-
end
|
171
|
-
|
172
|
-
# Returns a AnyTimesMatcher. This is meant to be passed in as an argument
|
173
|
-
# to Scenario#times.
|
174
|
-
#
|
175
|
-
# mock(object).method_name(anything).times(any_times) {return_value}
|
176
|
-
def any_times
|
177
|
-
TimesCalledMatchers::AnyTimesMatcher.new
|
178
|
-
end
|
179
|
-
|
180
|
-
# Sets up an Anything wildcard ArgumentEqualityExpectation
|
181
|
-
# that succeeds when passed any argument.
|
182
|
-
# mock(object).method_name(anything) {return_value}
|
183
|
-
# object.method_name("an arbitrary value") # passes
|
184
|
-
def anything
|
185
|
-
RR::WildcardMatchers::Anything.new
|
186
|
-
end
|
187
|
-
|
188
|
-
# Sets up an IsA wildcard ArgumentEqualityExpectation
|
189
|
-
# that succeeds when passed an argument of a certain type.
|
190
|
-
# mock(object).method_name(is_a(String)) {return_value}
|
191
|
-
# object.method_name("A String") # passes
|
192
|
-
def is_a(klass)
|
193
|
-
RR::WildcardMatchers::IsA.new(klass)
|
194
|
-
end
|
195
|
-
|
196
|
-
# Sets up an Numeric wildcard ArgumentEqualityExpectation
|
197
|
-
# that succeeds when passed an argument that is ::Numeric.
|
198
|
-
# mock(object).method_name(numeric) {return_value}
|
199
|
-
# object.method_name(99) # passes
|
200
|
-
def numeric
|
201
|
-
RR::WildcardMatchers::Numeric.new
|
202
|
-
end
|
203
|
-
|
204
|
-
# Sets up an Boolean wildcard ArgumentEqualityExpectation
|
205
|
-
# that succeeds when passed an argument that is a ::Boolean.
|
206
|
-
# mock(object).method_name(boolean) {return_value}
|
207
|
-
# object.method_name(false) # passes
|
208
|
-
def boolean
|
209
|
-
RR::WildcardMatchers::Boolean.new
|
210
|
-
end
|
211
|
-
|
212
|
-
# Sets up a DuckType wildcard ArgumentEqualityExpectation
|
213
|
-
# that succeeds when passed the argument implements the methods.
|
214
|
-
# arg = Object.new
|
215
|
-
# def arg.foo; end
|
216
|
-
# def arg.bar; end
|
217
|
-
# mock(object).method_name(duck_type(:foo, :bar)) {return_value}
|
218
|
-
# object.method_name(arg) # passes
|
219
|
-
def duck_type(*args)
|
220
|
-
RR::WildcardMatchers::DuckType.new(*args)
|
221
|
-
end
|
222
|
-
|
223
|
-
instance_methods.each do |name|
|
224
|
-
alias_method "rr_#{name}", name
|
225
|
-
end
|
226
|
-
end
|
227
|
-
end
|
228
|
-
end
|