rr 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +7 -0
- data/Rakefile +1 -1
- data/examples/environment_fixture_setup.rb +1 -1
- data/examples/example_helper.rb +1 -0
- data/examples/high_level_example.rb +1 -2
- data/examples/rr/do_not_allow_creator_example.rb +1 -2
- data/examples/rr/double_bind_example.rb +1 -2
- data/examples/rr/double_dispatching_example.rb +2 -3
- data/examples/rr/double_example.rb +1 -2
- data/examples/rr/double_register_scenario_example.rb +1 -2
- data/examples/rr/double_reset_example.rb +1 -2
- data/examples/rr/double_verify_example.rb +1 -2
- data/examples/rr/errors/rr_error_example.rb +1 -2
- data/examples/rr/expectations/any_argument_expectation_example.rb +1 -2
- data/examples/rr/expectations/anything_argument_equality_expectation_example.rb +1 -2
- data/examples/rr/expectations/argument_equality_expectation_example.rb +1 -2
- data/examples/rr/expectations/boolean_argument_equality_expectation_example.rb +1 -2
- data/examples/rr/expectations/duck_type_argument_equality_expectation_example.rb +1 -2
- data/examples/rr/expectations/is_a_argument_equality_expectation_example.rb +1 -2
- data/examples/rr/expectations/numeric_argument_equality_expectation_example.rb +1 -2
- data/examples/rr/expectations/range_argument_equality_expectation_example.rb +1 -2
- data/examples/rr/expectations/regexp_argument_equality_expectation_example.rb +1 -2
- data/examples/rr/expectations/times_called_expectation/times_called_expectation_at_least_example.rb +74 -0
- data/examples/rr/expectations/times_called_expectation/times_called_expectation_at_most_example.rb +69 -0
- data/examples/rr/expectations/times_called_expectation/times_called_expectation_helper.rb +18 -0
- data/examples/rr/expectations/times_called_expectation/times_called_expectation_integer_example.rb +102 -0
- data/examples/rr/expectations/times_called_expectation/times_called_expectation_proc_example.rb +80 -0
- data/examples/rr/expectations/times_called_expectation/times_called_expectation_range_example.rb +81 -0
- data/examples/rr/expectations/times_called_expectation_example.rb +1 -185
- data/examples/rr/extensions/double_methods_example.rb +3 -4
- data/examples/rr/mock_creator_example.rb +1 -2
- data/examples/rr/probe_creator_example.rb +1 -2
- data/examples/rr/rspec/rspec_adapter_example.rb +1 -2
- data/examples/rr/rspec/rspec_backtrace_tweaking_example.rb +1 -2
- data/examples/rr/rspec/rspec_usage_example.rb +1 -2
- data/examples/rr/scenario_example.rb +60 -15
- data/examples/rr/space_create_example.rb +1 -2
- data/examples/rr/space_example.rb +1 -2
- data/examples/rr/space_register_example.rb +1 -2
- data/examples/rr/space_reset_example.rb +51 -4
- data/examples/rr/space_verify_example.rb +4 -5
- data/examples/rr/stub_creator_example.rb +1 -2
- data/examples/rr/test_unit/test_helper.rb +1 -1
- data/examples/rr/times_called_matchers/at_least_matcher_example.rb +74 -0
- data/examples/rr/times_called_matchers/at_most_matcher_example.rb +82 -0
- data/examples/rr/times_called_matchers/integer_matcher_example.rb +88 -0
- data/examples/rr/times_called_matchers/proc_matcher_example.rb +74 -0
- data/examples/rr/times_called_matchers/range_matcher_example.rb +94 -0
- data/examples/rr/times_called_matchers/times_called_matcher_example.rb +53 -0
- data/lib/rr.rb +15 -7
- data/lib/rr/adapters/rspec.rb +2 -2
- data/lib/rr/adapters/test_unit.rb +1 -1
- data/lib/rr/double.rb +2 -2
- data/lib/rr/expectations/times_called_expectation.rb +14 -13
- data/lib/rr/extensions/double_methods.rb +5 -5
- data/lib/rr/scenario.rb +35 -7
- data/lib/rr/space.rb +20 -8
- data/lib/rr/times_called_matchers/at_least_matcher.rb +22 -0
- data/lib/rr/times_called_matchers/at_most_matcher.rb +22 -0
- data/lib/rr/times_called_matchers/integer_matcher.rb +17 -0
- data/lib/rr/times_called_matchers/proc_matcher.rb +17 -0
- data/lib/rr/times_called_matchers/range_matcher.rb +19 -0
- data/lib/rr/times_called_matchers/times_called_matcher.rb +44 -0
- data/lib/rr/wildcard_matchers/anything.rb +13 -0
- data/lib/rr/wildcard_matchers/boolean.rb +18 -0
- data/lib/rr/wildcard_matchers/duck_type.rb +24 -0
- data/lib/rr/wildcard_matchers/is_a.rb +20 -0
- data/lib/rr/wildcard_matchers/numeric.rb +9 -0
- data/lib/rr/{expectations/wildcard_matchers → wildcard_matchers}/range.rb +0 -0
- data/lib/rr/{expectations/wildcard_matchers → wildcard_matchers}/regexp.rb +0 -0
- metadata +27 -9
- data/lib/rr/expectations/wildcard_matchers/anything.rb +0 -15
- data/lib/rr/expectations/wildcard_matchers/boolean.rb +0 -20
- data/lib/rr/expectations/wildcard_matchers/duck_type.rb +0 -26
- data/lib/rr/expectations/wildcard_matchers/is_a.rb +0 -22
- data/lib/rr/expectations/wildcard_matchers/numeric.rb +0 -11
data/CHANGES
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
* 0.1.7
|
2
|
+
- Fixed [#12194] Double#reset_doubles are not clearing Ordered Scenarios bug
|
3
|
+
- Added Space#reset
|
4
|
+
- Space#reset_doubles and Space#reset_ordered_scenarios is now protected
|
5
|
+
- Added Scenario#at_least
|
6
|
+
- Added Scenario#at_most
|
7
|
+
|
1
8
|
* 0.1.6
|
2
9
|
- [#12120] probe allows a the return value to be intercepted
|
3
10
|
|
data/Rakefile
CHANGED
data/examples/example_helper.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
dir = File.dirname(__FILE__)
|
2
2
|
require "#{dir}/environment_fixture_setup"
|
3
3
|
require "examples/rr/space_helper"
|
4
|
+
require "examples/rr/expectations/times_called_expectation/times_called_expectation_helper"
|
4
5
|
|
5
6
|
require "rr/adapters/rspec"
|
6
7
|
Spec::Runner.configure do |config|
|
@@ -8,7 +8,7 @@ describe "RR", :shared => true do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
after(:each) do
|
11
|
-
RR::Space.instance.
|
11
|
+
RR::Space.instance.reset
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
@@ -116,7 +116,6 @@ describe "RR stub:" do
|
|
116
116
|
|
117
117
|
it "allows ordering" do
|
118
118
|
stub(@obj).to_s {"value 1"}.once.ordered
|
119
|
-
|
120
119
|
stub(@obj).to_s {"value 2"}.once.ordered
|
121
120
|
|
122
121
|
@obj.to_s.should == "value 1"
|
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
require "#{dir}/../example_helper"
|
1
|
+
require "examples/example_helper"
|
3
2
|
|
4
3
|
module RR
|
5
4
|
describe Double, "method dispatching", :shared => true do
|
@@ -24,7 +23,7 @@ describe Double, " method dispatching where method name has a ! in it" do
|
|
24
23
|
it "executes the block" do
|
25
24
|
scenario = @space.create_scenario(@double)
|
26
25
|
scenario.with(1, 2) {:return_value}
|
27
|
-
|
26
|
+
@object.foobar!(1, 2).should == :return_value
|
28
27
|
end
|
29
28
|
end
|
30
29
|
|
data/examples/rr/expectations/times_called_expectation/times_called_expectation_at_least_example.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
require "examples/example_helper"
|
2
|
+
|
3
|
+
module RR
|
4
|
+
module Expectations
|
5
|
+
describe TimesCalledExpectation, ' with AtLeastMatcher', :shared => true do
|
6
|
+
it_should_behave_like "RR::Expectations::TimesCalledExpectation"
|
7
|
+
|
8
|
+
before do
|
9
|
+
@times = 3
|
10
|
+
@at_least = TimesCalledMatchers::AtLeastMatcher.new(@times)
|
11
|
+
@expectation = TimesCalledExpectation.new(@at_least)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe TimesCalledExpectation, "#verify! with AtLeastMatcher" do
|
16
|
+
it_should_behave_like "RR::Expectations::TimesCalledExpectation with AtLeastMatcher"
|
17
|
+
|
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
|
+
proc do
|
31
|
+
@expectation.verify!
|
32
|
+
end.should raise_error(
|
33
|
+
RR::Errors::TimesCalledError,
|
34
|
+
"Called 1 time. Expected at least 3 times."
|
35
|
+
)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe TimesCalledExpectation, "#attempt? with AtLeastMatcher" do
|
40
|
+
it_should_behave_like "RR::Expectations::TimesCalledExpectation with AtLeastMatcher"
|
41
|
+
|
42
|
+
it "returns true when attempted less than expected times" do
|
43
|
+
2.times {@expectation.attempt!}
|
44
|
+
@expectation.should be_attempt
|
45
|
+
end
|
46
|
+
|
47
|
+
it "returns false when attempted expected times" do
|
48
|
+
3.times {@expectation.attempt!}
|
49
|
+
@expectation.should_not be_attempt
|
50
|
+
end
|
51
|
+
|
52
|
+
it "returns false when attempted more than expected times" do
|
53
|
+
4.times {@expectation.attempt!}
|
54
|
+
@expectation.should_not be_attempt
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe TimesCalledExpectation, "#attempt! with AtLeastMatcher" do
|
59
|
+
it_should_behave_like "RR::Expectations::TimesCalledExpectation with AtLeastMatcher"
|
60
|
+
|
61
|
+
it "passes when times called more than times" do
|
62
|
+
4.times {@expectation.attempt!}
|
63
|
+
end
|
64
|
+
|
65
|
+
it "passes when times called == times" do
|
66
|
+
3.times {@expectation.attempt!}
|
67
|
+
end
|
68
|
+
|
69
|
+
it "passes when times called < times" do
|
70
|
+
@expectation.attempt!
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
data/examples/rr/expectations/times_called_expectation/times_called_expectation_at_most_example.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
require "examples/example_helper"
|
2
|
+
|
3
|
+
module RR
|
4
|
+
module Expectations
|
5
|
+
describe TimesCalledExpectation, ' with AtMostMatcher', :shared => true do
|
6
|
+
it_should_behave_like "RR::Expectations::TimesCalledExpectation"
|
7
|
+
|
8
|
+
before do
|
9
|
+
@times = 3
|
10
|
+
@at_most = TimesCalledMatchers::AtMostMatcher.new(@times)
|
11
|
+
@expectation = TimesCalledExpectation.new(@at_most)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe TimesCalledExpectation, "#verify! with AtMostMatcher" do
|
16
|
+
it_should_behave_like "RR::Expectations::TimesCalledExpectation with AtMostMatcher"
|
17
|
+
|
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 TimesCalledExpectation, "#attempt? with AtMostMatcher" do
|
30
|
+
it_should_behave_like "RR::Expectations::TimesCalledExpectation with AtMostMatcher"
|
31
|
+
|
32
|
+
it "returns true when attempted less than expected times" do
|
33
|
+
2.times {@expectation.attempt!}
|
34
|
+
@expectation.should be_attempt
|
35
|
+
end
|
36
|
+
|
37
|
+
it "returns false when attempted expected times" do
|
38
|
+
3.times {@expectation.attempt!}
|
39
|
+
@expectation.should_not be_attempt
|
40
|
+
end
|
41
|
+
|
42
|
+
it "raises error before attempted more than expected times" do
|
43
|
+
3.times {@expectation.attempt!}
|
44
|
+
proc {@expectation.attempt!}.should raise_error(
|
45
|
+
Errors::TimesCalledError
|
46
|
+
)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe TimesCalledExpectation, "#attempt! with AtMostMatcher" do
|
51
|
+
it_should_behave_like "RR::Expectations::TimesCalledExpectation with AtMostMatcher"
|
52
|
+
|
53
|
+
it "fails when times called more than times" do
|
54
|
+
3.times {@expectation.attempt!}
|
55
|
+
proc do
|
56
|
+
@expectation.attempt!
|
57
|
+
end.should raise_error(Errors::TimesCalledError, "Called 4 times. Expected at most 3 times.")
|
58
|
+
end
|
59
|
+
|
60
|
+
it "passes when times called == times" do
|
61
|
+
3.times {@expectation.attempt!}
|
62
|
+
end
|
63
|
+
|
64
|
+
it "passes when times called < times" do
|
65
|
+
@expectation.attempt!
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module RR
|
2
|
+
module Expectations
|
3
|
+
describe TimesCalledExpectation, :shared => true do
|
4
|
+
before do
|
5
|
+
@space = Space.new
|
6
|
+
@object = Object.new
|
7
|
+
@method_name = :foobar
|
8
|
+
@double = @space.create_double(@object, @method_name)
|
9
|
+
@scenario = @space.create_scenario(@double)
|
10
|
+
@scenario.with_any_args
|
11
|
+
end
|
12
|
+
|
13
|
+
def raises_expectation_error(&block)
|
14
|
+
proc {block.call}.should raise_error(Errors::TimesCalledError)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/examples/rr/expectations/times_called_expectation/times_called_expectation_integer_example.rb
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
require "examples/example_helper"
|
2
|
+
|
3
|
+
module RR
|
4
|
+
module Expectations
|
5
|
+
describe TimesCalledExpectation, " with IntegerMatcher", :shared => true do
|
6
|
+
it_should_behave_like "RR::Expectations::TimesCalledExpectation"
|
7
|
+
|
8
|
+
before do
|
9
|
+
@expectation = TimesCalledExpectation.new(2)
|
10
|
+
@expected_line = __LINE__ - 1
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe TimesCalledExpectation, "#verify" do
|
15
|
+
it_should_behave_like "RR::Expectations::TimesCalledExpectation with IntegerMatcher"
|
16
|
+
|
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 TimesCalledExpectation, "#verify! when passed an Integer (2)" do
|
27
|
+
it_should_behave_like "RR::Expectations::TimesCalledExpectation with IntegerMatcher"
|
28
|
+
|
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
|
+
proc {@expectation.verify!}.should raise_error(
|
38
|
+
Errors::TimesCalledError,
|
39
|
+
"Called 1 time. Expected 2 times."
|
40
|
+
)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "can't be called when attempt! is called 3 times" do
|
44
|
+
@expectation.attempt!
|
45
|
+
@expectation.attempt!
|
46
|
+
proc do
|
47
|
+
@expectation.attempt!
|
48
|
+
end.should raise_error(Errors::TimesCalledError, "Called 3 times. Expected 2 times.")
|
49
|
+
end
|
50
|
+
|
51
|
+
it "has a backtrace to where the TimesCalledExpectation was instantiated on failure" do
|
52
|
+
error = nil
|
53
|
+
begin
|
54
|
+
@expectation.verify!
|
55
|
+
rescue Errors::TimesCalledError => e
|
56
|
+
error = e
|
57
|
+
end
|
58
|
+
e.backtrace.first.should include(__FILE__)
|
59
|
+
e.backtrace.first.should include(":#{@expected_line}")
|
60
|
+
end
|
61
|
+
|
62
|
+
it "has an error message that includes the number of times called and expected number of times" do
|
63
|
+
proc do
|
64
|
+
@expectation.verify!
|
65
|
+
end.should raise_error(Errors::TimesCalledError, "Called 0 times. Expected 2 times.")
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe TimesCalledExpectation, "#attempt? with IntegerMatcher" do
|
70
|
+
it_should_behave_like "RR::Expectations::TimesCalledExpectation with IntegerMatcher"
|
71
|
+
|
72
|
+
it "returns true when attempted less than expected times" do
|
73
|
+
1.times {@expectation.attempt!}
|
74
|
+
@expectation.should be_attempt
|
75
|
+
end
|
76
|
+
|
77
|
+
it "returns false when attempted expected times" do
|
78
|
+
2.times {@expectation.attempt!}
|
79
|
+
@expectation.should_not be_attempt
|
80
|
+
end
|
81
|
+
|
82
|
+
it "raises error before attempted more than expected times" do
|
83
|
+
2.times {@expectation.attempt!}
|
84
|
+
proc {@expectation.attempt!}.should raise_error(
|
85
|
+
Errors::TimesCalledError
|
86
|
+
)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe TimesCalledExpectation, "#attempt! for an IntegerMatcher" do
|
91
|
+
it_should_behave_like "RR::Expectations::TimesCalledExpectation with IntegerMatcher"
|
92
|
+
|
93
|
+
it "raises error when attempt! called more than the expected number of times" do
|
94
|
+
@expectation.attempt!
|
95
|
+
@expectation.attempt!
|
96
|
+
proc do
|
97
|
+
@expectation.attempt!
|
98
|
+
end.should raise_error(Errors::TimesCalledError)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|