Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

respond_to? returns true for :to_ary, but call of :to_ary raises NoMethodError #63

Merged
merged 2 commits into from

3 participants

@Mik-die

fixed bug, when respond_to? returns true for method :to_ary, and then, when this method calls, raise NoMethodError. For example, at this point: https://github.com/rails/rails/blob/v3.0.8/activesupport/lib/active_support/core_ext/array/wrap.rb#L43

@dchelimsky
Owner

Please add a spec that fails without this change and passes with it.

@justinko justinko merged commit b101687 into rspec:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 10 additions and 1 deletion.
  1. +1 −1  lib/rspec/mocks/mock.rb
  2. +9 −0 spec/rspec/mocks/to_ary_spec.rb
View
2  lib/rspec/mocks/mock.rb
@@ -35,7 +35,7 @@ def to_s
alias_method :to_str, :to_s
def respond_to?(sym, incl_private=false)
- __mock_proxy.null_object? ? true : super
+ __mock_proxy.null_object? && sym != :to_ary ? true : super
end
private
View
9 spec/rspec/mocks/to_ary_spec.rb
@@ -7,11 +7,20 @@
obj.to_ary.should be_nil
end.to raise_error(NoMethodError)
end
+
+ it "doesn't respond" do
+ obj.should_not be_respond_to(:to_ary)
+ end
it "can be overridden with a stub" do
obj.stub(:to_ary) { :non_nil_value }
obj.to_ary.should be(:non_nil_value)
end
+
+ it "responds when overriden" do
+ obj.stub(:to_ary) { :non_nil_value }
+ obj.should be_respond_to(:to_ary)
+ end
it "supports Array#flatten" do
obj = double('foo')
Something went wrong with that request. Please try again.