rr 0.4.10 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +14 -0
- data/README.rdoc +67 -13
- data/Rakefile +1 -1
- data/lib/rr.rb +29 -9
- data/lib/rr/adapters/rr_methods.rb +38 -158
- data/lib/rr/double.rb +46 -41
- data/lib/rr/double_definitions/child_double_definition_creator.rb +23 -0
- data/lib/rr/double_definitions/double_definition.rb +212 -0
- data/lib/rr/double_definitions/double_definition_creator.rb +153 -0
- data/lib/rr/double_definitions/double_definition_creator_proxy.rb +25 -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/scope/instance.rb +15 -0
- data/lib/rr/double_definitions/strategies/scope/instance_of_class.rb +43 -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 +21 -15
- data/lib/rr/expectations/argument_equality_expectation.rb +2 -1
- data/lib/rr/space.rb +23 -22
- data/lib/rr/wildcard_matchers/hash_including.rb +29 -0
- data/lib/rr/wildcard_matchers/satisfy.rb +26 -0
- data/spec/high_level_spec.rb +111 -64
- data/spec/rr/adapters/rr_methods_argument_matcher_spec.rb +1 -1
- data/spec/rr/adapters/rr_methods_creator_spec.rb +99 -315
- data/spec/rr/adapters/rr_methods_space_spec.rb +90 -109
- data/spec/rr/adapters/rr_methods_spec_helper.rb +1 -1
- data/spec/rr/adapters/rr_methods_times_matcher_spec.rb +1 -1
- data/spec/rr/double_definitions/child_double_definition_creator_spec.rb +103 -0
- data/spec/rr/double_definitions/double_definition_creator_proxy_spec.rb +83 -0
- data/spec/rr/double_definitions/double_definition_creator_spec.rb +495 -0
- data/spec/rr/double_definitions/double_definition_spec.rb +1116 -0
- data/spec/rr/double_injection/double_injection_bind_spec.rb +111 -0
- data/spec/rr/double_injection/double_injection_dispatching_spec.rb +245 -0
- data/spec/rr/{double → double_injection}/double_injection_has_original_method_spec.rb +9 -9
- data/spec/rr/double_injection/double_injection_reset_spec.rb +90 -0
- data/spec/rr/double_injection/double_injection_spec.rb +77 -0
- data/spec/rr/double_injection/double_injection_verify_spec.rb +29 -0
- data/spec/rr/double_spec.rb +156 -136
- data/spec/rr/errors/rr_error_spec.rb +1 -1
- data/spec/rr/expectations/any_argument_expectation_spec.rb +1 -1
- data/spec/rr/expectations/anything_argument_equality_expectation_spec.rb +6 -30
- data/spec/rr/expectations/argument_equality_expectation_spec.rb +35 -18
- data/spec/rr/expectations/boolean_argument_equality_expectation_spec.rb +22 -41
- 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 +30 -28
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_least_spec.rb +55 -54
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_most_spec.rb +49 -48
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_helper.rb +9 -7
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_integer_spec.rb +77 -76
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_proc_spec.rb +58 -57
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_range_spec.rb +59 -58
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_spec.rb +25 -24
- data/spec/rr/rspec/rspec_adapter_spec.rb +12 -11
- data/spec/rr/rspec/rspec_backtrace_tweaking_spec.rb +10 -8
- data/spec/rr/rspec/rspec_usage_spec.rb +1 -1
- data/spec/rr/space/hash_with_object_id_key_spec.rb +1 -1
- data/spec/rr/space/space_spec.rb +330 -192
- data/spec/rr/test_unit/test_helper.rb +1 -2
- data/spec/rr/test_unit/test_unit_backtrace_test.rb +1 -2
- data/spec/rr/test_unit/test_unit_integration_test.rb +1 -2
- data/spec/rr/times_called_matchers/any_times_matcher_spec.rb +1 -1
- data/spec/rr/times_called_matchers/at_least_matcher_spec.rb +1 -1
- data/spec/rr/times_called_matchers/at_most_matcher_spec.rb +1 -1
- data/spec/rr/times_called_matchers/integer_matcher_spec.rb +1 -1
- data/spec/rr/times_called_matchers/proc_matcher_spec.rb +1 -1
- data/spec/rr/times_called_matchers/range_matcher_spec.rb +1 -1
- data/spec/rr/times_called_matchers/times_called_matcher_spec.rb +1 -1
- 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/spec_helper.rb +84 -0
- metadata +43 -29
- data/lib/rr/double_creator.rb +0 -271
- data/lib/rr/double_definition.rb +0 -179
- data/lib/rr/double_definition_builder.rb +0 -44
- data/lib/rr/double_definition_creator.rb +0 -156
- data/lib/rr/double_definition_creator_proxy.rb +0 -20
- data/spec/rr/double/double_injection_bind_spec.rb +0 -105
- data/spec/rr/double/double_injection_dispatching_spec.rb +0 -228
- data/spec/rr/double/double_injection_reset_spec.rb +0 -86
- data/spec/rr/double/double_injection_spec.rb +0 -72
- data/spec/rr/double/double_injection_verify_spec.rb +0 -24
- data/spec/rr/double_definition_creator_proxy_spec.rb +0 -85
- data/spec/rr/double_definition_creator_spec.rb +0 -496
- data/spec/rr/double_definition_spec.rb +0 -815
- data/spec/rr/expectations/anything_spec.rb +0 -14
- data/spec/rr/expectations/boolean_spec.rb +0 -14
- data/spec/rr/expectations/duck_type_argument_equality_expectation_spec.rb +0 -71
- data/spec/rr/expectations/duck_type_spec.rb +0 -14
- data/spec/rr/expectations/is_a_argument_equality_expectation_spec.rb +0 -51
- data/spec/rr/expectations/is_a_spec.rb +0 -14
- data/spec/rr/expectations/numeric_argument_equality_expectation_spec.rb +0 -47
- data/spec/rr/expectations/numeric_spec.rb +0 -14
- data/spec/rr/expectations/range_argument_equality_expectation_spec.rb +0 -59
- data/spec/rr/expectations/range_spec.rb +0 -10
- data/spec/rr/expectations/regexp_argument_equality_expectation_spec.rb +0 -72
- data/spec/rr/expectations/regexp_spec.rb +0 -10
data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_least_spec.rb
CHANGED
@@ -1,67 +1,68 @@
|
|
1
|
-
require "
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../../spec_helper")
|
2
2
|
|
3
3
|
module RR
|
4
|
-
module Expectations
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
before do
|
10
|
-
@times = 3
|
11
|
-
@at_least = TimesCalledMatchers::AtLeastMatcher.new(times)
|
12
|
-
@expectation = TimesCalledExpectation.new(double, at_least)
|
13
|
-
end
|
14
|
-
|
15
|
-
describe "#verify!" do
|
16
|
-
it "passes when times called > times" do
|
17
|
-
4.times {expectation.attempt}
|
18
|
-
expectation.verify!
|
19
|
-
end
|
4
|
+
module Expectations
|
5
|
+
describe TimesCalledExpectation do
|
6
|
+
context "when using an AtLeastMatcher" do
|
7
|
+
it_should_behave_like "RR::Expectations::TimesCalledExpectation"
|
8
|
+
attr_reader :times, :at_least, :expectation
|
20
9
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
10
|
+
before do
|
11
|
+
@times = 3
|
12
|
+
@at_least = TimesCalledMatchers::AtLeastMatcher.new(times)
|
13
|
+
@expectation = TimesCalledExpectation.new(double, at_least)
|
14
|
+
end
|
25
15
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
RR::Errors::TimesCalledError,
|
32
|
-
"foobar()\nCalled 1 time.\nExpected at least 3 times."
|
33
|
-
)
|
34
|
-
end
|
35
|
-
end
|
16
|
+
describe "#verify!" do
|
17
|
+
it "passes when times called > times" do
|
18
|
+
4.times {expectation.attempt}
|
19
|
+
expectation.verify!
|
20
|
+
end
|
36
21
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
expectation.should be_attempt
|
42
|
-
end
|
43
|
-
end
|
22
|
+
it "passes when times called == times" do
|
23
|
+
3.times {expectation.attempt}
|
24
|
+
expectation.verify!
|
25
|
+
end
|
44
26
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
27
|
+
it "raises error when times called < times" do
|
28
|
+
expectation.attempt
|
29
|
+
lambda do
|
30
|
+
expectation.verify!
|
31
|
+
end.should raise_error(
|
32
|
+
RR::Errors::TimesCalledError,
|
33
|
+
"foobar()\nCalled 1 time.\nExpected at least 3 times."
|
34
|
+
)
|
35
|
+
end
|
36
|
+
end
|
49
37
|
|
50
|
-
|
51
|
-
|
52
|
-
|
38
|
+
describe "#attempt?" do
|
39
|
+
it "always returns true" do
|
40
|
+
expectation.should be_attempt
|
41
|
+
10.times {expectation.attempt}
|
42
|
+
expectation.should be_attempt
|
43
|
+
end
|
44
|
+
end
|
53
45
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
46
|
+
describe "#attempt!" do
|
47
|
+
it "passes when times called more than times" do
|
48
|
+
4.times {expectation.attempt}
|
49
|
+
end
|
58
50
|
|
59
|
-
|
60
|
-
|
61
|
-
|
51
|
+
it "passes when times called == times" do
|
52
|
+
3.times {expectation.attempt}
|
53
|
+
end
|
54
|
+
|
55
|
+
it "passes when times called < times" do
|
56
|
+
expectation.attempt
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "#terminal?" do
|
61
|
+
it "returns false" do
|
62
|
+
expectation.should_not be_terminal
|
63
|
+
end
|
64
|
+
end
|
62
65
|
end
|
63
66
|
end
|
64
67
|
end
|
65
|
-
|
66
|
-
end
|
67
68
|
end
|
@@ -1,69 +1,70 @@
|
|
1
|
-
require "
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../../spec_helper")
|
2
2
|
|
3
3
|
module RR
|
4
4
|
module Expectations
|
5
|
-
describe TimesCalledExpectation
|
6
|
-
|
7
|
-
|
5
|
+
describe TimesCalledExpectation do
|
6
|
+
context "when using an AtMostMatcher" do
|
7
|
+
it_should_behave_like "RR::Expectations::TimesCalledExpectation"
|
8
|
+
attr_reader :times, :at_most, :expectation
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
describe "#verify!" do
|
16
|
-
it "returns true when times called == times" do
|
17
|
-
3.times {expectation.attempt}
|
18
|
-
expectation.verify!
|
10
|
+
before do
|
11
|
+
@times = 3
|
12
|
+
@at_most = TimesCalledMatchers::AtMostMatcher.new(times)
|
13
|
+
@expectation = TimesCalledExpectation.new(double, at_most)
|
19
14
|
end
|
20
15
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
16
|
+
describe "#verify!" do
|
17
|
+
it "returns true when times called == times" do
|
18
|
+
3.times {expectation.attempt}
|
19
|
+
expectation.verify!
|
20
|
+
end
|
26
21
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
22
|
+
it "raises error when times called < times" do
|
23
|
+
2.times {expectation.attempt}
|
24
|
+
expectation.verify!
|
25
|
+
end
|
31
26
|
end
|
32
27
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
28
|
+
describe "#attempt?" do
|
29
|
+
it "returns true when attempted less than expected times" do
|
30
|
+
2.times {expectation.attempt}
|
31
|
+
expectation.should be_attempt
|
32
|
+
end
|
37
33
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
end
|
34
|
+
it "returns false when attempted expected times" do
|
35
|
+
3.times {expectation.attempt}
|
36
|
+
expectation.should_not be_attempt
|
37
|
+
end
|
43
38
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
expectation.attempt
|
49
|
-
end.should raise_error(Errors::TimesCalledError, "foobar()\nCalled 4 times.\nExpected at most 3 times.")
|
39
|
+
it "raises error before attempted more than expected times" do
|
40
|
+
3.times {expectation.attempt}
|
41
|
+
lambda {expectation.attempt}.should raise_error( Errors::TimesCalledError )
|
42
|
+
end
|
50
43
|
end
|
51
44
|
|
52
|
-
|
53
|
-
|
54
|
-
|
45
|
+
describe "#attempt!" do
|
46
|
+
it "fails when times called more than times" do
|
47
|
+
3.times {expectation.attempt}
|
48
|
+
lambda do
|
49
|
+
expectation.attempt
|
50
|
+
end.should raise_error(Errors::TimesCalledError, "foobar()\nCalled 4 times.\nExpected at most 3 times.")
|
51
|
+
end
|
52
|
+
|
53
|
+
it "passes when times called == times" do
|
54
|
+
3.times {expectation.attempt}
|
55
|
+
end
|
55
56
|
|
56
|
-
|
57
|
-
|
57
|
+
it "passes when times called < times" do
|
58
|
+
expectation.attempt
|
59
|
+
end
|
58
60
|
end
|
59
|
-
end
|
60
61
|
|
61
|
-
|
62
|
-
|
63
|
-
|
62
|
+
describe "#terminal?" do
|
63
|
+
it "returns true" do
|
64
|
+
expectation.should be_terminal
|
65
|
+
end
|
64
66
|
end
|
65
67
|
end
|
66
68
|
end
|
67
|
-
|
68
69
|
end
|
69
70
|
end
|
@@ -1,15 +1,17 @@
|
|
1
|
-
require "spec/spec_helper"
|
2
|
-
|
3
1
|
module RR
|
4
2
|
module Expectations
|
5
3
|
describe TimesCalledExpectation, :shared => true do
|
6
|
-
attr_reader :space, :
|
4
|
+
attr_reader :space, :subject, :method_name, :double_injection, :double, :double_definition
|
5
|
+
it_should_behave_like "Swapped Space"
|
7
6
|
before do
|
8
|
-
@
|
9
|
-
@object = Object.new
|
7
|
+
@subject = Object.new
|
10
8
|
@method_name = :foobar
|
11
|
-
@double_injection = space.double_injection(
|
12
|
-
@
|
9
|
+
@double_injection = space.double_injection(subject, method_name)
|
10
|
+
@double_definition = DoubleDefinitions::DoubleDefinition.new(
|
11
|
+
DoubleDefinitions::DoubleDefinitionCreator.new,
|
12
|
+
subject
|
13
|
+
)
|
14
|
+
@double = new_double(double_injection)
|
13
15
|
double.with_any_args
|
14
16
|
end
|
15
17
|
|
@@ -1,103 +1,104 @@
|
|
1
|
-
require "
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../../spec_helper")
|
2
2
|
|
3
3
|
module RR
|
4
4
|
module Expectations
|
5
|
-
describe TimesCalledExpectation
|
6
|
-
|
7
|
-
|
5
|
+
describe TimesCalledExpectation do
|
6
|
+
context "when using an IntegerMatcher" do
|
7
|
+
it_should_behave_like "RR::Expectations::TimesCalledExpectation"
|
8
|
+
attr_reader :matcher, :expected_line, :expectation
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
describe "#verify" do
|
16
|
-
it "returns true when times called exactly matches an integer" do
|
17
|
-
expectation.verify.should == false
|
18
|
-
expectation.attempt
|
19
|
-
expectation.verify.should == false
|
20
|
-
expectation.attempt
|
21
|
-
expectation.verify.should == true
|
10
|
+
before do
|
11
|
+
@matcher = TimesCalledMatchers::IntegerMatcher.new(2)
|
12
|
+
@expectation = TimesCalledExpectation.new(double, matcher)
|
13
|
+
@expected_line = __LINE__ - 1
|
22
14
|
end
|
23
|
-
end
|
24
15
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
16
|
+
describe "#verify" do
|
17
|
+
it "returns true when times called exactly matches an integer" do
|
18
|
+
expectation.verify.should == false
|
19
|
+
expectation.attempt
|
20
|
+
expectation.verify.should == false
|
21
|
+
expectation.attempt
|
22
|
+
expectation.verify.should == true
|
23
|
+
end
|
30
24
|
end
|
31
25
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
end
|
26
|
+
describe "#verify! when passed an Integer (2)" do
|
27
|
+
it "passes after attempt! called 2 times" do
|
28
|
+
expectation.attempt
|
29
|
+
expectation.attempt
|
30
|
+
expectation.verify!
|
31
|
+
end
|
39
32
|
|
40
|
-
|
41
|
-
expectation.attempt
|
42
|
-
expectation.attempt
|
43
|
-
lambda do
|
33
|
+
it "fails after attempt! called 1 time" do
|
44
34
|
expectation.attempt
|
45
|
-
|
46
|
-
|
35
|
+
lambda {expectation.verify!}.should raise_error(
|
36
|
+
Errors::TimesCalledError,
|
37
|
+
"foobar()\nCalled 1 time.\nExpected 2 times."
|
38
|
+
)
|
39
|
+
end
|
47
40
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
41
|
+
it "can't be called when attempt! is called 3 times" do
|
42
|
+
expectation.attempt
|
43
|
+
expectation.attempt
|
44
|
+
lambda do
|
45
|
+
expectation.attempt
|
46
|
+
end.should raise_error(Errors::TimesCalledError, "foobar()\nCalled 3 times.\nExpected 2 times.")
|
54
47
|
end
|
55
|
-
e.backtrace.first.should include(__FILE__)
|
56
|
-
e.backtrace.first.should include(":#{expected_line}")
|
57
|
-
end
|
58
48
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
49
|
+
it "has a backtrace to where the TimesCalledExpectation was instantiated on failure" do
|
50
|
+
error = nil
|
51
|
+
begin
|
52
|
+
expectation.verify!
|
53
|
+
rescue Errors::TimesCalledError => e
|
54
|
+
error = e
|
55
|
+
end
|
56
|
+
e.backtrace.first.should include(__FILE__)
|
57
|
+
e.backtrace.first.should include(":#{expected_line}")
|
58
|
+
end
|
65
59
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
60
|
+
it "has an error message that includes the number of times called and expected number of times" do
|
61
|
+
lambda do
|
62
|
+
expectation.verify!
|
63
|
+
end.should raise_error(Errors::TimesCalledError, "foobar()\nCalled 0 times.\nExpected 2 times.")
|
64
|
+
end
|
70
65
|
end
|
71
66
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
67
|
+
describe "#attempt?" do
|
68
|
+
it "returns true when attempted less than expected times" do
|
69
|
+
1.times {expectation.attempt}
|
70
|
+
expectation.should be_attempt
|
71
|
+
end
|
72
|
+
|
73
|
+
it "returns false when attempted expected times" do
|
74
|
+
2.times {expectation.attempt}
|
75
|
+
expectation.should_not be_attempt
|
76
|
+
end
|
76
77
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
78
|
+
it "raises error before attempted more than expected times" do
|
79
|
+
2.times {expectation.attempt}
|
80
|
+
lambda {expectation.attempt}.should raise_error(
|
81
|
+
Errors::TimesCalledError
|
82
|
+
)
|
83
|
+
end
|
82
84
|
end
|
83
|
-
end
|
84
85
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
expectation.attempt
|
89
|
-
lambda do
|
86
|
+
describe "#attempt! for an IntegerMatcher" do
|
87
|
+
it "raises error when attempt! called more than the expected number of times" do
|
88
|
+
expectation.attempt
|
90
89
|
expectation.attempt
|
91
|
-
|
90
|
+
lambda do
|
91
|
+
expectation.attempt
|
92
|
+
end.should raise_error(Errors::TimesCalledError)
|
93
|
+
end
|
92
94
|
end
|
93
|
-
end
|
94
95
|
|
95
|
-
|
96
|
-
|
97
|
-
|
96
|
+
describe "#terminal?" do
|
97
|
+
it "returns true" do
|
98
|
+
expectation.should be_terminal
|
99
|
+
end
|
98
100
|
end
|
99
101
|
end
|
100
102
|
end
|
101
|
-
|
102
103
|
end
|
103
104
|
end
|
@@ -1,79 +1,80 @@
|
|
1
|
-
require "
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../../spec_helper")
|
2
2
|
|
3
3
|
module RR
|
4
4
|
module Expectations
|
5
|
-
describe TimesCalledExpectation
|
6
|
-
|
7
|
-
|
5
|
+
describe TimesCalledExpectation do
|
6
|
+
context "when using a ProcMatcher" do
|
7
|
+
it_should_behave_like "RR::Expectations::TimesCalledExpectation"
|
8
|
+
attr_reader :matcher, :expectation
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
end
|
13
|
-
|
14
|
-
describe "#verify" do
|
15
|
-
it "matches a block" do
|
16
|
-
expectation.verify.should == false
|
17
|
-
expectation.attempt
|
18
|
-
expectation.verify.should == false
|
19
|
-
expectation.attempt
|
20
|
-
expectation.verify.should == true
|
21
|
-
expectation.attempt
|
22
|
-
expectation.verify.should == false
|
10
|
+
before do
|
11
|
+
@matcher = TimesCalledMatchers::ProcMatcher.new(lambda {|value| value == 2})
|
12
|
+
@expectation = TimesCalledExpectation.new(double, matcher)
|
23
13
|
end
|
24
|
-
end
|
25
14
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
15
|
+
describe "#verify" do
|
16
|
+
it "matches a block" do
|
17
|
+
expectation.verify.should == false
|
18
|
+
expectation.attempt
|
19
|
+
expectation.verify.should == false
|
20
|
+
expectation.attempt
|
21
|
+
expectation.verify.should == true
|
22
|
+
expectation.attempt
|
23
|
+
expectation.verify.should == false
|
24
|
+
end
|
31
25
|
end
|
32
26
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
27
|
+
describe "#verify! when passed a block (== 2 times)" do
|
28
|
+
it "passes after attempt! called 2 times" do
|
29
|
+
expectation.attempt
|
30
|
+
expectation.attempt
|
31
|
+
expectation.verify!
|
32
|
+
end
|
37
33
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
lambda {expectation.verify!}.should raise_error(Errors::TimesCalledError)
|
43
|
-
end
|
44
|
-
end
|
34
|
+
it "fails after attempt! called 1 time" do
|
35
|
+
expectation.attempt
|
36
|
+
lambda {expectation.verify!}.should raise_error(Errors::TimesCalledError)
|
37
|
+
end
|
45
38
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
39
|
+
it "fails after attempt! called 3 times" do
|
40
|
+
expectation.attempt
|
41
|
+
expectation.attempt
|
42
|
+
expectation.attempt
|
43
|
+
lambda {expectation.verify!}.should raise_error(Errors::TimesCalledError)
|
44
|
+
end
|
50
45
|
end
|
51
46
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
47
|
+
describe "#attempt? with IntegerMatcher" do
|
48
|
+
it "returns true when attempted less than expected times" do
|
49
|
+
1.times {expectation.attempt}
|
50
|
+
expectation.should be_attempt
|
51
|
+
end
|
52
|
+
|
53
|
+
it "returns true when attempted expected times" do
|
54
|
+
2.times {expectation.attempt}
|
55
|
+
expectation.should be_attempt
|
56
|
+
end
|
56
57
|
|
57
|
-
|
58
|
-
|
59
|
-
|
58
|
+
it "returns true when attempted more than expected times" do
|
59
|
+
3.times {expectation.attempt}
|
60
|
+
expectation.should be_attempt
|
61
|
+
end
|
60
62
|
end
|
61
|
-
end
|
62
63
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
64
|
+
describe "#attempt! for a lambda expectation" do
|
65
|
+
it "lets everything pass" do
|
66
|
+
@subject.foobar
|
67
|
+
@subject.foobar
|
68
|
+
@subject.foobar
|
69
|
+
end
|
68
70
|
end
|
69
|
-
end
|
70
71
|
|
71
|
-
|
72
|
-
|
73
|
-
|
72
|
+
describe "#terminal? with ProcMatcher" do
|
73
|
+
it "returns false" do
|
74
|
+
expectation.should_not be_terminal
|
75
|
+
end
|
74
76
|
end
|
75
77
|
end
|
76
78
|
end
|
77
|
-
|
78
79
|
end
|
79
80
|
end
|