Skip to content

Commit

Permalink
mock_model(XXX).as_null_object.unknown_method returns self
Browse files Browse the repository at this point in the history
- Fixes #488.
  • Loading branch information
dchelimsky committed Jan 19, 2012
1 parent c9b47d6 commit 7fa15c4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
7 changes: 7 additions & 0 deletions Changelog.md
@@ -1,3 +1,10 @@
### dev

[full changelog](http://github.com/rspec/rspec-rails/compare/v2.8.1...master)

Bug fixes
* mock_model(XXX).as_null_object.unknown_method returns self again

### 2.8.1 / 2012-01-04 ### 2.8.1 / 2012-01-04


[full changelog](http://github.com/rspec/rspec-rails/compare/v2.8.0...v2.8.1) [full changelog](http://github.com/rspec/rspec-rails/compare/v2.8.0...v2.8.1)
Expand Down
2 changes: 1 addition & 1 deletion lib/rspec/rails/mocks.rb
Expand Up @@ -132,7 +132,7 @@ def @object.respond_to?(method_name, include_private=false)
end unless #{stubs.has_key?(:respond_to?)} end unless #{stubs.has_key?(:respond_to?)}
def @object.method_missing(m, *a, &b) def @object.method_missing(m, *a, &b)
respond_to?(m) ? nil : super respond_to?(m) ? null_object? ? self : nil : super
end end
def @object.class def @object.class
Expand Down
5 changes: 5 additions & 0 deletions spec/rspec/rails/mocks/mock_model_spec.rb
Expand Up @@ -234,6 +234,11 @@
it "says it will not respond_to?(xxx_before_type_cast)" do it "says it will not respond_to?(xxx_before_type_cast)" do
@model.as_null_object.respond_to?("title_before_type_cast").should be(false) @model.as_null_object.respond_to?("title_before_type_cast").should be(false)
end end
it "returns self for any unprepared message" do
@model.as_null_object.tap do |x|
x.non_existant_message.should be(@model)
end
end
end end
end end


Expand Down

3 comments on commit 7fa15c4

@pisaruk
Copy link

@pisaruk pisaruk commented on 7fa15c4 Feb 3, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello David,

Do you have plans to release a new version including this bug fix?
I will downgrade from 2.8.1 to 2.7 because my rspec has became unsable due to this small bug.
Tks.

@dchelimsky
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pisaruk not sure when the next release is going to be, but you can point your Gemfile at git in the mean time:

gem "rspec-rails", :git => "https://github.com/rspec/rspec-rails.git"

@pisaruk
Copy link

@pisaruk pisaruk commented on 7fa15c4 Feb 3, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. I appreciate your prompt reply.

Please sign in to comment.