Skip to content
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

If key has not been defined, Hashie::Mash should raise NoMethodError instead of returning nil #17

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ rdoc
pkg
*.gem
.bundle
.buildpath
.project
2 changes: 1 addition & 1 deletion lib/hashie/mash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def method_missing(method_name, *args, &blk)
when "!"
initializing_reader(match[1])
else
default(method_name, *args, &blk)
raise NoMethodError
end
end

Expand Down
10 changes: 4 additions & 6 deletions spec/hashie/mash_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
@mash.to_s.should == @mash.inspect
end

it "should return nil instead of raising an error for attribute-esque method calls" do
@mash.abc.should be_nil
it "should raise an error for uninitialized attribute-esque method calls" do
lambda { @mash.abc}.should raise_error(NoMethodError)
end

it "should return a Hashie::Mash when passed a bang method to a non-existenct key" do
Expand Down Expand Up @@ -126,7 +126,6 @@

subject.first_name.should == "Michael"
subject.details.email.should == "michael@intridea.com"
subject.details.address.should be_nil
subject.details.city.should == "Imagineton"
end

Expand All @@ -139,20 +138,19 @@
duped = subject.shallow_merge(:details => {:address => "Fake street"})
duped.details.address.should == "Fake street"
subject.details.address.should == "Nowhere road"
duped.details.email.should be_nil
end
end

describe 'delete' do
it 'should delete with String key' do
subject.delete('details')
subject.details.should be_nil
lambda { subject.details}.should raise_error(NoMethodError)
subject.should_not be_respond_to :details
end

it 'should delete with Symbol key' do
subject.delete(:details)
subject.details.should be_nil
lambda { subject.details}.should raise_error(NoMethodError)
subject.should_not be_respond_to :details
end
end
Expand Down