rr 0.8.0 → 0.8.1
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 +4 -0
- data/VERSION.yml +2 -2
- data/lib/rr/double_injection.rb +5 -2
- data/spec/environment_fixture_setup.rb +1 -0
- data/spec/rr/double_injection/double_injection_spec.rb +32 -5
- data/spec/spec_helper.rb +62 -62
- metadata +1 -1
data/CHANGES
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
* 0.8.1
|
2
|
+
- Fixed exception where the Subject uses method delegation via method_missing (e.g. certain ActiveRecord AssociationProxy methods)
|
3
|
+
|
4
|
+
* 0.8.0
|
1
5
|
- Fixed compatability issues with Ruby 1.9
|
2
6
|
- Aliased any_number_of_times with any_times
|
3
7
|
- Better error messages for have_received and assert_received matchers (Patch by Joe Ferris)
|
data/VERSION.yml
CHANGED
data/lib/rr/double_injection.rb
CHANGED
@@ -14,8 +14,11 @@ module RR
|
|
14
14
|
begin
|
15
15
|
meta.__send__(:alias_method, original_method_name, method_name)
|
16
16
|
rescue NameError => e
|
17
|
-
|
18
|
-
|
17
|
+
begin
|
18
|
+
subject.send(method_name)
|
19
|
+
meta.__send__(:alias_method, original_method_name, method_name)
|
20
|
+
rescue NameError => e
|
21
|
+
end
|
19
22
|
end
|
20
23
|
end
|
21
24
|
@doubles = []
|
@@ -34,17 +34,44 @@ module RR
|
|
34
34
|
end
|
35
35
|
|
36
36
|
context "when method does not exist on object" do
|
37
|
-
send("sets up object and method_name")
|
38
|
-
|
39
37
|
before do
|
40
38
|
@subject = Object.new
|
41
39
|
@method_name = :foobar
|
42
40
|
subject.methods.should_not include(method_name.to_s)
|
43
|
-
@double_injection = DoubleInjection.new(subject, method_name)
|
44
41
|
end
|
45
42
|
|
46
|
-
|
47
|
-
|
43
|
+
context "and invoking the method for the first time does not add the method" do
|
44
|
+
before do
|
45
|
+
@double_injection = DoubleInjection.new(subject, method_name)
|
46
|
+
end
|
47
|
+
send("sets up object and method_name")
|
48
|
+
|
49
|
+
example "object does not have original method" do
|
50
|
+
double_injection.object_has_original_method?.should be_false
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
context "and invoking the method for the first time adds the method" do
|
56
|
+
before do
|
57
|
+
class << subject
|
58
|
+
def respond_to?(method_name)
|
59
|
+
true
|
60
|
+
end
|
61
|
+
|
62
|
+
def method_missing(method_name, *args, &block)
|
63
|
+
(class << self; self; end).class_eval do
|
64
|
+
define_method(method_name) {}
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
@double_injection = DoubleInjection.new(subject, method_name)
|
69
|
+
end
|
70
|
+
send("sets up object and method_name")
|
71
|
+
|
72
|
+
example "object has original method" do
|
73
|
+
double_injection.object_has_original_method?.should be_true
|
74
|
+
end
|
48
75
|
end
|
49
76
|
end
|
50
77
|
|
data/spec/spec_helper.rb
CHANGED
@@ -20,88 +20,88 @@ describe "Swapped Space", :shared => true do
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
double_injection,
|
30
|
-
double_definition
|
31
|
-
)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
module Spec::Example::ExampleGroupMethods
|
36
|
-
def macro(name, &implementation)
|
37
|
-
(class << self; self; end).class_eval do
|
38
|
-
define_method(name, &implementation)
|
23
|
+
class Spec::ExampleGroup
|
24
|
+
class << self
|
25
|
+
def macro(name, &implementation)
|
26
|
+
(class << self; self; end).class_eval do
|
27
|
+
define_method(name, &implementation)
|
28
|
+
end
|
39
29
|
end
|
40
|
-
end
|
41
30
|
|
42
|
-
|
43
|
-
|
44
|
-
|
31
|
+
define_method("normal strategy definition") do
|
32
|
+
describe "strategy definition" do
|
33
|
+
attr_reader :strategy_method_name
|
45
34
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
35
|
+
context "when passed a subject" do
|
36
|
+
it "returns a DoubleDefinitionCreatorProxy" do
|
37
|
+
double = call_strategy(subject).foobar
|
38
|
+
double.should be_instance_of(RR::DoubleDefinitions::DoubleDefinition)
|
39
|
+
end
|
50
40
|
end
|
51
|
-
end
|
52
41
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
42
|
+
context "when passed a method name and a definition_eval_block" do
|
43
|
+
it "raises an ArgumentError" do
|
44
|
+
lambda do
|
45
|
+
call_strategy(subject, :foobar) {}
|
46
|
+
end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
|
47
|
+
end
|
58
48
|
end
|
59
49
|
end
|
60
50
|
end
|
61
|
-
end
|
62
51
|
|
63
|
-
|
64
|
-
|
65
|
-
|
52
|
+
define_method("! strategy definition") do
|
53
|
+
describe "strategy definition" do
|
54
|
+
attr_reader :strategy_method_name
|
66
55
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
56
|
+
context "when not passed a method_name argument" do
|
57
|
+
it "returns a DoubleDefinitionCreatorProxy" do
|
58
|
+
call_strategy.should respond_to(:__subject__)
|
59
|
+
end
|
71
60
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
61
|
+
context "when passed a definition_eval_block argument" do
|
62
|
+
it "calls the definition_eval_block and passes in the DoubleDefinitionCreatorProxy" do
|
63
|
+
passed_in_proxy = nil
|
64
|
+
proxy = call_strategy do |proxy|
|
65
|
+
passed_in_proxy = proxy
|
66
|
+
end
|
78
67
|
|
79
|
-
|
68
|
+
passed_in_proxy.should == proxy
|
69
|
+
end
|
80
70
|
end
|
81
71
|
end
|
82
|
-
end
|
83
72
|
|
84
|
-
|
85
|
-
|
86
|
-
double_definition = call_strategy(:foobar)
|
87
|
-
double_definition.class.should == RR::DoubleDefinitions::DoubleDefinition
|
88
|
-
end
|
89
|
-
|
90
|
-
describe "the returned DoubleDefinition" do
|
91
|
-
it "has #subject set to an anonymous Object" do
|
73
|
+
context "when passed a method_name argument" do
|
74
|
+
it "returns a DoubleDefinition" do
|
92
75
|
double_definition = call_strategy(:foobar)
|
93
|
-
double_definition.
|
76
|
+
double_definition.class.should == RR::DoubleDefinitions::DoubleDefinition
|
77
|
+
end
|
78
|
+
|
79
|
+
describe "the returned DoubleDefinition" do
|
80
|
+
it "has #subject set to an anonymous Object" do
|
81
|
+
double_definition = call_strategy(:foobar)
|
82
|
+
double_definition.subject.class.should == Object
|
83
|
+
end
|
94
84
|
end
|
95
85
|
end
|
96
|
-
end
|
97
86
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
87
|
+
context "when passed a method name and a definition_eval_block" do
|
88
|
+
it "raises an ArgumentError" do
|
89
|
+
lambda do
|
90
|
+
call_strategy(:foobar) {}
|
91
|
+
end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
|
92
|
+
end
|
103
93
|
end
|
104
94
|
end
|
105
95
|
end
|
106
96
|
end
|
107
|
-
|
97
|
+
|
98
|
+
def new_double(
|
99
|
+
double_injection=double_injection,
|
100
|
+
double_definition=RR::DoubleDefinitions::DoubleDefinition.new(creator = RR::DoubleDefinitions::DoubleDefinitionCreator.new, subject).with_any_args.any_number_of_times
|
101
|
+
)
|
102
|
+
RR::Double.new(
|
103
|
+
double_injection,
|
104
|
+
double_definition
|
105
|
+
)
|
106
|
+
end
|
107
|
+
end
|