Uh oh!
There was an error while loading. Please reload this page.
Moves KeyError into Shared spec - #576
Conversation
This refactors my work on KeyError features into a shared spec to reduce the duplication.
| -> { | ||
| @method.call(@object, 'foo') | ||
| }.should raise_error(KeyError) { |err| | ||
| err.receiver.should == @object |
There was a problem hiding this comment.
This could be should equal(@object) to make sure it's the same object.
| 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.
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.
It would be good to keep these examples which use different kinds of Hash.
There was a problem hiding this comment.
I've added 3 more it_behaves_like calls so it can test all the shared specs in each of the Hash creation methods.
eregon
commented
Jan 2, 2018
That seems unintended bugs. Could you file an issue on https://github.com/ruby/mspec ? |
cadwallion
commented
Jan 2, 2018
I've updated the code per review comments, and I'll file an issue with ruby/mspec detailing the scoping problems of |
eregon
commented
Jan 3, 2018
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_likecalls must have an identical@methodand@objectcalls within a given scope, or they will affect each others' state. To overcome this, you have to wrap the differing parameter in acontextordescribeblock.@methodhas shared scope. To get around this here, I have saved the outer@methodinto a new@base_methodinside abeforeand referred to it via@base_methodto 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.