Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

Fix 1.9.2 bug with wrapping doubles in arrays

  • Loading branch information...
commit 5416b2c6e4254aaae54fd2bceeefbee8eadadf5e 1 parent c5a83d4
@JonRowe JonRowe authored
2  lib/rspec/mocks/test_double.rb
@@ -64,7 +64,7 @@ def __initialize_as_test_double(name=nil, stubs_and_options={})
def method_missing(message, *args, &block)
- raise NoMethodError if message == :to_ary
+ raise NoMethodError if message == :to_ary || message == :to_a
return 0 if message == :to_int && __mock_proxy.null_object?
__mock_proxy.record_message_received(message, *args, &block)
4 spec/rspec/mocks/mock_spec.rb
@@ -185,6 +185,10 @@ def @double.method_with_default_argument(arg={}); end
}.to raise_error(RSpec::Expectations::ExpectationNotMetError)
+ it "is wrappable in an array" do
+ expect( Array(@double) ).to eq([@double])
+ end
context "with Ruby > 1.8.6", :unless => RUBY_VERSION.to_s == '1.8.6' do
it "passes proc to expectation block without an argument" do
# We eval this because Ruby 1.8.6's syntax parser barfs on { |&block| ... }

9 comments on commit 5416b2c


I actually want to stub an object, on which I'm calling to_a in the code. Any ideas for workarounds?


@exviva: can you open an issue showing a code example of what you're trying to do, how you expect it to behave, and what it's doing instead?


FYI, You can explicitly stub to_a, it's tested all over the place.


@JonRowe yup, that's what I did, but in my case, the to_a is called in a chain, and I want the null object to return self from to_a, and I can't do anything like d = double(to_a: d).as_null_object :/


Unfortunately we cannot return self from to_a or to_ary as it breaks Ruby functionality with flatten and Arrays. We could return nil when it's a NullObject.


I see. So I guess we should close this one?


Well this is a discussion of a commit, you can't close it ;), I'm working on a PR for returning nil when the object is a null object, but it's currently got issues on 1.8.7.


Yeah, I meant the issue :)

Please sign in to comment.
Something went wrong with that request. Please try again.