Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
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
View
2  lib/rspec/mocks/test_double.rb
@@ -64,7 +64,7 @@ def __initialize_as_test_double(name=nil, stubs_and_options={})
end
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)
View
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)
end
+ 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

@exviva

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

@myronmarston

@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?

@JonRowe
Owner

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

@exviva

@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 :/

@JonRowe
Owner

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.

@exviva

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

@JonRowe
Owner

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.

@exviva

Yeah, I meant the issue :)

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