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 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)
@@ -1,4 +1,4 @@
1
1
  ---
2
- :major: 0
3
2
  :minor: 8
4
- :patch: 0
3
+ :patch: 1
4
+ :major: 0
@@ -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
- subject.send(method_name)
18
- meta.__send__(:alias_method, original_method_name, method_name)
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 = []
@@ -1,5 +1,6 @@
1
1
  require "rubygems"
2
2
  require "spec"
3
+ require "spec/autorun"
3
4
  dir = File.dirname(__FILE__)
4
5
  $LOAD_PATH.unshift "#{dir}/../lib"
5
6
  require "rr"
@@ -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
- it "object does not have original method" do
47
- double_injection.object_has_original_method?.should be_false
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
 
@@ -20,88 +20,88 @@ describe "Swapped Space", :shared => true do
20
20
  end
21
21
  end
22
22
 
23
- module Spec::Example::ExampleMethods
24
- def new_double(
25
- double_injection=double_injection,
26
- double_definition=RR::DoubleDefinitions::DoubleDefinition.new(creator = RR::DoubleDefinitions::DoubleDefinitionCreator.new, subject).with_any_args.any_number_of_times
27
- )
28
- RR::Double.new(
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
- define_method("normal strategy definition") do
43
- describe "strategy definition" do
44
- attr_reader :strategy_method_name
31
+ define_method("normal strategy definition") do
32
+ describe "strategy definition" do
33
+ attr_reader :strategy_method_name
45
34
 
46
- context "when passed a subject" do
47
- it "returns a DoubleDefinitionCreatorProxy" do
48
- double = call_strategy(subject).foobar
49
- double.should be_instance_of(RR::DoubleDefinitions::DoubleDefinition)
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
- context "when passed a method name and a definition_eval_block" do
54
- it "raises an ArgumentError" do
55
- lambda do
56
- call_strategy(subject, :foobar) {}
57
- end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
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
- define_method("! strategy definition") do
64
- describe "strategy definition" do
65
- attr_reader :strategy_method_name
52
+ define_method("! strategy definition") do
53
+ describe "strategy definition" do
54
+ attr_reader :strategy_method_name
66
55
 
67
- context "when not passed a method_name argument" do
68
- it "returns a DoubleDefinitionCreatorProxy" do
69
- call_strategy.should respond_to(:__subject__)
70
- end
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
- context "when passed a definition_eval_block argument" do
73
- it "calls the definition_eval_block and passes in the DoubleDefinitionCreatorProxy" do
74
- passed_in_proxy = nil
75
- proxy = call_strategy do |proxy|
76
- passed_in_proxy = proxy
77
- end
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
- passed_in_proxy.should == proxy
68
+ passed_in_proxy.should == proxy
69
+ end
80
70
  end
81
71
  end
82
- end
83
72
 
84
- context "when passed a method_name argument" do
85
- it "returns a DoubleDefinition" do
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.subject.class.should == Object
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
- context "when passed a method name and a definition_eval_block" do
99
- it "raises an ArgumentError" do
100
- lambda do
101
- call_strategy(:foobar) {}
102
- end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
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
- end
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Takita