rr 0.4.10 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
|
2
|
+
|
3
|
+
module RR
|
4
|
+
module WildcardMatchers
|
5
|
+
describe Anything do
|
6
|
+
attr_reader :matcher
|
7
|
+
before do
|
8
|
+
@matcher = Anything.new
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#wildcard_match?" do
|
12
|
+
it "returns true" do
|
13
|
+
matcher.should be_wildcard_match(Object.new)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#inspect" do
|
18
|
+
it "returns anything" do
|
19
|
+
matcher.inspect.should == "anything"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
|
2
|
+
|
3
|
+
module RR
|
4
|
+
module WildcardMatchers
|
5
|
+
describe Boolean do
|
6
|
+
attr_reader :matcher
|
7
|
+
|
8
|
+
before do
|
9
|
+
@matcher = Boolean.new
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#wildcard_match?" do
|
13
|
+
context "when passed a Boolean" do
|
14
|
+
it "returns true" do
|
15
|
+
matcher.should be_wildcard_match(true)
|
16
|
+
matcher.should be_wildcard_match(false)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "when not passed a Boolean" do
|
21
|
+
it "returns false" do
|
22
|
+
matcher.should_not be_wildcard_match(:not_a_boolean)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe Boolean do
|
28
|
+
describe "#inspect" do
|
29
|
+
it "returns boolean" do
|
30
|
+
matcher.inspect.should == "boolean"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
|
2
|
+
|
3
|
+
module RR
|
4
|
+
module WildcardMatchers
|
5
|
+
describe DuckType do
|
6
|
+
attr_reader :matcher
|
7
|
+
before do
|
8
|
+
@matcher = DuckType.new(:quack, :waddle)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#wildcard_match?" do
|
12
|
+
before do
|
13
|
+
@matching_object = Object.new
|
14
|
+
def @matching_object.quack
|
15
|
+
end
|
16
|
+
def @matching_object.waddle
|
17
|
+
end
|
18
|
+
|
19
|
+
@partial_matching_object = Object.new
|
20
|
+
def @partial_matching_object.quack
|
21
|
+
end
|
22
|
+
|
23
|
+
@not_match_object = Object.new
|
24
|
+
end
|
25
|
+
|
26
|
+
context "when passed-in object matches all required methods" do
|
27
|
+
it "returns true" do
|
28
|
+
matcher.should be_wildcard_match(@matching_object)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "when passed-in object matches some required methods" do
|
33
|
+
it "returns false" do
|
34
|
+
matcher.should_not be_wildcard_match(@partial_matching_object)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "when passed-in object matches no required methods" do
|
39
|
+
it "returns false" do
|
40
|
+
matcher.should_not be_wildcard_match(@not_match_object)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "#inspect" do
|
46
|
+
it "returns duck_type with methods" do
|
47
|
+
matcher.inspect.should == "duck_type(:quack, :waddle)"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
|
2
|
+
|
3
|
+
module RR
|
4
|
+
module WildcardMatchers
|
5
|
+
describe IsA do
|
6
|
+
attr_reader :matcher
|
7
|
+
before do
|
8
|
+
@matcher = IsA.new(Symbol)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#wildcard_match?" do
|
12
|
+
context "when passed an instance of the expected Module" do
|
13
|
+
it "returns true" do
|
14
|
+
matcher.should be_wildcard_match(:a_symbol)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context "when not passed an instance of the expected Module" do
|
19
|
+
it "returns false" do
|
20
|
+
matcher.should_not be_wildcard_match("not a symbol")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#inspect" do
|
26
|
+
it "returns the is_a(ClassName)" do
|
27
|
+
matcher.inspect.should == "is_a(Symbol)"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
|
2
|
+
|
3
|
+
module RR
|
4
|
+
module WildcardMatchers
|
5
|
+
describe Numeric do
|
6
|
+
attr_reader :matcher
|
7
|
+
before do
|
8
|
+
@matcher = Numeric.new
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#wildcard_match?" do
|
12
|
+
context "when passed a Numeric" do
|
13
|
+
it "returns true" do
|
14
|
+
matcher.should be_wildcard_match(99)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context "when not passed a Numeric" do
|
19
|
+
it "returns false" do
|
20
|
+
matcher.should_not be_wildcard_match(:not_a_numeric)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#inspect" do
|
26
|
+
it "returns numeric" do
|
27
|
+
matcher.inspect.should == "numeric"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
|
2
|
+
|
3
|
+
describe Range do
|
4
|
+
attr_reader :matcher
|
5
|
+
|
6
|
+
before do
|
7
|
+
@matcher = 2..3
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#wildcard_match?" do
|
11
|
+
context "when passed-in number falls within the Range" do
|
12
|
+
it "returns true" do
|
13
|
+
matcher.should be_wildcard_match(3)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context "when passed-in number does not fall within the Range" do
|
18
|
+
it "returns false" do
|
19
|
+
matcher.should_not be_wildcard_match(7)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "when passed-in argument is not a number" do
|
24
|
+
it "returns false" do
|
25
|
+
matcher.should_not be_wildcard_match("Not a number")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#inspect" do
|
31
|
+
it "returns the range" do
|
32
|
+
matcher.inspect.should == "2..3"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
|
2
|
+
|
3
|
+
describe Regexp do
|
4
|
+
attr_reader :matcher
|
5
|
+
|
6
|
+
before do
|
7
|
+
@matcher = /foo/
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#wildcard_match?" do
|
11
|
+
before do
|
12
|
+
@matching_object = Object.new
|
13
|
+
def @matching_object.quack
|
14
|
+
end
|
15
|
+
def @matching_object.waddle
|
16
|
+
end
|
17
|
+
|
18
|
+
@partial_matching_object = Object.new
|
19
|
+
def @partial_matching_object.quack
|
20
|
+
end
|
21
|
+
|
22
|
+
@not_match_object = Object.new
|
23
|
+
end
|
24
|
+
|
25
|
+
context "when passed-in String matches the Regexp" do
|
26
|
+
it "returns true" do
|
27
|
+
matcher.should be_wildcard_match("foobarbaz")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "when passed-in String does not match the Regexp" do
|
32
|
+
it "returns false" do
|
33
|
+
matcher.should_not be_wildcard_match("no match here")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "#inspect" do
|
39
|
+
it "returns the regexp" do
|
40
|
+
matcher.inspect.should == "/foo/"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/spec/rr_spec.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require "#{File.dirname(__FILE__)}/spec_helper"
|
2
|
+
|
3
|
+
describe "RR" do
|
4
|
+
before do
|
5
|
+
Object.class_eval do
|
6
|
+
def verify
|
7
|
+
raise "Dont call me"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
after do
|
13
|
+
Object.class_eval do
|
14
|
+
remove_method :verify
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
it "has proxy methods for each method defined directly on Space" do
|
19
|
+
space_instance_methods = RR::Space.instance_methods(false)
|
20
|
+
space_instance_methods.should_not be_empty
|
21
|
+
|
22
|
+
rr_instance_methods = RR.methods(false)
|
23
|
+
space_instance_methods.each do |space_instance_method|
|
24
|
+
rr_instance_methods.should include(space_instance_method)
|
25
|
+
end
|
26
|
+
RR.verify
|
27
|
+
end
|
28
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -8,6 +8,7 @@ Spec::Runner.configure do |config|
|
|
8
8
|
end
|
9
9
|
|
10
10
|
describe "Swapped Space", :shared => true do
|
11
|
+
attr_reader :space, :original_space
|
11
12
|
before do
|
12
13
|
@original_space = RR::Space.instance
|
13
14
|
RR::Space.instance = RR::Space.new
|
@@ -18,3 +19,86 @@ describe "Swapped Space", :shared => true do
|
|
18
19
|
RR::Space.instance = @original_space
|
19
20
|
end
|
20
21
|
end
|
22
|
+
|
23
|
+
module Spec::Example::ExampleMethods
|
24
|
+
def new_double(double_injection=double_injection, double_definition=RR::DoubleDefinitions::DoubleDefinition.new(creator = RR::DoubleDefinitions::DoubleDefinitionCreator.new, subject))
|
25
|
+
RR::Double.new(
|
26
|
+
double_injection,
|
27
|
+
double_definition
|
28
|
+
)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
module Spec::Example::ExampleGroupMethods
|
33
|
+
def macro(name, &implementation)
|
34
|
+
(class << self; self; end).class_eval do
|
35
|
+
define_method(name, &implementation)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
define_method("normal strategy definition") do
|
40
|
+
describe "strategy definition" do
|
41
|
+
attr_reader :strategy_method_name
|
42
|
+
|
43
|
+
context "when passed a subject" do
|
44
|
+
it "returns a DoubleDefinitionCreatorProxy" do
|
45
|
+
double = call_strategy(subject).foobar
|
46
|
+
double.should be_instance_of(RR::DoubleDefinitions::DoubleDefinition)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context "when passed a method name and a definition_eval_block" do
|
51
|
+
it "raises an ArgumentError" do
|
52
|
+
lambda do
|
53
|
+
call_strategy(subject, :foobar) {}
|
54
|
+
end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
define_method("! strategy definition") do
|
61
|
+
describe "strategy definition" do
|
62
|
+
attr_reader :strategy_method_name
|
63
|
+
|
64
|
+
context "when not passed a method_name argument" do
|
65
|
+
it "returns a DoubleDefinitionCreatorProxy" do
|
66
|
+
call_strategy.should respond_to(:__subject__)
|
67
|
+
end
|
68
|
+
|
69
|
+
context "when passed a definition_eval_block argument" do
|
70
|
+
it "calls the definition_eval_block and passes in the DoubleDefinitionCreatorProxy" do
|
71
|
+
passed_in_proxy = nil
|
72
|
+
proxy = call_strategy do |proxy|
|
73
|
+
passed_in_proxy = proxy
|
74
|
+
end
|
75
|
+
|
76
|
+
passed_in_proxy.should == proxy
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context "when passed a method_name argument" do
|
82
|
+
it "returns a DoubleDefinition" do
|
83
|
+
double_definition = call_strategy(:foobar)
|
84
|
+
double_definition.class.should == RR::DoubleDefinitions::DoubleDefinition
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "the returned DoubleDefinition" do
|
88
|
+
it "has #subject set to an anonymous Object" do
|
89
|
+
double_definition = call_strategy(:foobar)
|
90
|
+
double_definition.subject.class.should == Object
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
context "when passed a method name and a definition_eval_block" do
|
96
|
+
it "raises an ArgumentError" do
|
97
|
+
lambda do
|
98
|
+
call_strategy(:foobar) {}
|
99
|
+
end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|