-
-
Notifications
You must be signed in to change notification settings - Fork 389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Moves KeyError into Shared spec #576
Conversation
This refactors my work on KeyError features into a shared spec to reduce the duplication.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work!
shared/hash/key_error.rb
Outdated
-> { | ||
@method.call(@object, 'foo') | ||
}.should raise_error(KeyError) { |err| | ||
err.receiver.should == @object |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be should equal(@object)
to make sure it's the same object.
core/hash/fetch_values_spec.rb
Outdated
it "returns the default value from block" do | ||
@hash.fetch_values(:z) { |key| "`#{key}' is not found" }.should == ["`z' is not found"] | ||
@hash.fetch_values(:a, :z) { |key| "`#{key}' is not found" }.should == [1, "`z' is not found"] | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the group describe "with unmatched keys" do
below which should be replace by it_behaves_like
.
lambda { {}.fetch(:a) }.should raise_error(KeyError) | ||
lambda { Hash.new(5).fetch(:a) }.should raise_error(KeyError) | ||
lambda { Hash.new { 5 }.fetch(:a) }.should raise_error(KeyError) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to keep these examples which use different kinds of Hash
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added 3 more it_behaves_like
calls so it can test all the shared specs in each of the Hash creation methods.
That seems unintended bugs. Could you file an issue on https://github.com/ruby/mspec ? |
I've updated the code per review comments, and I'll file an issue with ruby/mspec detailing the scoping problems of |
Thank you for the refactoring! |
This refactors my work on KeyError (#574) features into a shared spec to reduce the duplication.
There are two oddities that I should point out, both are limitations I've found with the implementation of
it_behaves_like
:it_behaves_like
calls must have an identical@method
and@object
calls within a given scope, or they will affect each others' state. To overcome this, you have to wrap the differing parameter in acontext
ordescribe
block.@method
has shared scope. To get around this here, I have saved the outer@method
into a new@base_method
inside abefore
and referred to it via@base_method
to solve the collision.I'm not sure if the two above issues are intentional side-effects of mspec's implementation or unintended bugs so I'm not sure if I should file an issue, but I thought I'd bring it up since it was relevant to my work on this.