public
Description: Behaviour Driven Development framework for Ruby
Homepage: http://rspec.info
Clone URL: git://github.com/dchelimsky/rspec.git
Click here to lend your support to: rspec and make a donation at www.pledgie.com !
change matchers to use #__send__ instead of #send
pat-maddox (author)
Sat Jul 12 21:17:14 -0700 2008
commit  5bb989c6a54e325198e180ef3d4e59b5bf6eb21c
tree    e079c3412e8617c569fd4b88c09448d4fdd0868c
parent  91290a511dd74c5b06bed2e2575a367af42c2345
...
27
28
29
30
 
31
32
 
33
34
35
...
27
28
29
 
30
31
 
32
33
34
35
0
@@ -27,9 +27,9 @@ EOF
0
       end
0
       
0
       def execute_change
0
-        @before = @block.nil? ? @receiver.send(@message) : @block.call
0
+        @before = @block.nil? ? @receiver.__send__(@message) : @block.call
0
         @target.call
0
-        @after = @block.nil? ? @receiver.send(@message) : @block.call
0
+        @after = @block.nil? ? @receiver.__send__(@message) : @block.call
0
       end
0
       
0
       def failure_message
...
8
9
10
11
 
12
13
14
...
8
9
10
 
11
12
13
14
0
@@ -8,7 +8,7 @@ module Spec
0
       end
0
       
0
       def matches?(target)
0
-        target.send(predicate, *@args)
0
+        target.__send__(predicate, *@args)
0
       end
0
       
0
       def failure_message
...
27
28
29
30
 
31
32
 
33
34
35
36
 
37
38
39
...
27
28
29
 
30
31
 
32
33
34
35
 
36
37
38
39
0
@@ -27,13 +27,13 @@ module Spec
0
     
0
       def matches?(collection_owner)
0
         if collection_owner.respond_to?(@collection_name)
0
-          collection = collection_owner.send(@collection_name, *@args, &@block)
0
+          collection = collection_owner.__send__(@collection_name, *@args, &@block)
0
         elsif (@plural_collection_name && collection_owner.respond_to?(@plural_collection_name))
0
-          collection = collection_owner.send(@plural_collection_name, *@args, &@block)
0
+          collection = collection_owner.__send__(@plural_collection_name, *@args, &@block)
0
         elsif (collection_owner.respond_to?(:length) || collection_owner.respond_to?(:size))
0
           collection = collection_owner
0
         else
0
-          collection_owner.send(@collection_name, *@args, &@block)
0
+          collection_owner.__send__(@collection_name, *@args, &@block)
0
         end
0
         @actual = collection.size if collection.respond_to?(:size)
0
         @actual = collection.length if collection.respond_to?(:length)
...
57
58
59
60
 
61
62
63
...
69
70
71
72
 
73
74
75
...
57
58
59
 
60
61
62
63
...
69
70
71
 
72
73
74
75
0
@@ -57,7 +57,7 @@ module Spec
0
       def __delegate_method_missing_to_target(operator, expected)
0
         @operator = operator
0
         ::Spec::Matchers.last_matcher = self
0
-        return true if @target.send(operator, expected)
0
+        return true if @target.__send__(operator, expected)
0
         return fail_with_message("expected: #{expected.inspect},\n     got: #{@target.inspect} (using #{operator})") if ['==','===', '=~'].include?(operator)
0
         return fail_with_message("expected: #{operator} #{expected.inspect},\n     got: #{operator.gsub(/./, ' ')} #{@target.inspect}")
0
       end
0
@@ -69,7 +69,7 @@ module Spec
0
       def __delegate_method_missing_to_target(operator, expected)
0
         @operator = operator
0
         ::Spec::Matchers.last_matcher = self
0
-        return true unless @target.send(operator, expected)
0
+        return true unless @target.__send__(operator, expected)
0
         return fail_with_message("expected not: #{operator} #{expected.inspect},\n         got: #{operator.gsub(/./, ' ')} #{@target.inspect}")
0
       end
0
 
...
315
316
317
 
 
 
 
 
 
 
 
 
 
 
 
...
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
0
@@ -315,3 +315,15 @@ describe "should change{ block }.from(old).to(new)" do
0
     lambda { @instance.some_value = "cat" }.should change{@instance.some_value}.from("string").to("cat")
0
   end
0
 end
0
+
0
+describe Spec::Matchers::Change do
0
+  it "should work when the receiver has implemented #send" do
0
+    @instance = SomethingExpected.new
0
+    @instance.some_value = "string"
0
+    def @instance.send(*args); raise "DOH! Library developers shouldn't use #send!" end
0
+    
0
+    lambda {
0
+      lambda { @instance.some_value = "cat" }.should change(@instance, :some_value)
0
+    }.should_not raise_error
0
+  end
0
+end
...
51
52
53
 
 
 
 
 
 
 
 
 
 
...
51
52
53
54
55
56
57
58
59
60
61
62
63
0
@@ -51,3 +51,13 @@ describe "should_not have_sym(*args)" do
0
     lambda { o.should_not have_sym(:foo) }.should raise_error("Funky exception")
0
   end
0
 end
0
+
0
+describe Spec::Matchers::Has do
0
+  it "should work when the target implements #send" do
0
+    o = {:a => "A"}
0
+    def o.send(*args); raise "DOH! Library developers shouldn't use #send!" end
0
+    lambda {
0
+      o.should have_key(:a)
0
+    }.should_not raise_error
0
+  end
0
+end
...
324
325
326
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
0
@@ -324,3 +324,32 @@ describe "have(n).things on an object which is not a collection nor contains one
0
     lambda { Object.new.should have(2).things }.should raise_error(NoMethodError, /undefined method `things' for #<Object:/)
0
   end
0
 end
0
+
0
+describe Spec::Matchers::Have, "for a collection owner that implements #send" do
0
+  include HaveSpecHelper
0
+
0
+  before(:each) do
0
+    @collection = Object.new
0
+    def @collection.floozles; [1,2] end
0
+    def @collection.send(*args); raise "DOH! Library developers shouldn't use #send!" end
0
+  end
0
+  
0
+  it "should work in the straightforward case" do
0
+    lambda {
0
+      @collection.should have(2).floozles
0
+    }.should_not raise_error
0
+  end
0
+
0
+  it "should work when doing automatic pluralization" do
0
+    lambda {
0
+      @collection.should have_at_least(1).floozle
0
+    }.should_not raise_error
0
+  end
0
+
0
+  it "should blow up when the owner doesn't respond to that method" do
0
+    lambda {
0
+      @collection.should have(99).problems
0
+    }.should raise_error(NoMethodError, /problems/)
0
+  end
0
+  
0
+end
...
20
21
22
23
 
24
25
26
...
166
167
168
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
20
21
22
 
23
24
25
26
...
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
0
@@ -20,7 +20,7 @@ describe "should ==" do
0
     Spec::Expectations.should_receive(:fail_with).with(%[expected: "orange",\n     got: "apple" (using ==)], "orange", "apple")
0
     subject.should == "orange"
0
   end
0
-
0
+  
0
 end
0
 
0
 describe "should_not ==" do
0
@@ -166,3 +166,26 @@ describe "should <=" do
0
 
0
 end
0
 
0
+describe Spec::Matchers::PositiveOperatorMatcher do
0
+
0
+  it "should work when the target has implemented #send" do
0
+    o = Object.new
0
+    def o.send(*args); raise "DOH! Library developers shouldn't use #send!" end
0
+    lambda {
0
+      o.should == o
0
+    }.should_not raise_error
0
+  end
0
+
0
+end
0
+
0
+describe Spec::Matchers::NegativeOperatorMatcher do
0
+
0
+  it "should work when the target has implemented #send" do
0
+    o = Object.new
0
+    def o.send(*args); raise "DOH! Library developers shouldn't use #send!" end
0
+    lambda {
0
+      o.should_not == :foo
0
+    }.should_not raise_error
0
+  end
0
+
0
+end

Comments