Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

respond_to?(method, include_private=false)

- Closes #282.
  • Loading branch information...
commit 7a28bce2129f17ebfad55dc99534e5d670943e08 1 parent 7556316
David Chelimsky dchelimsky authored
6 lib/rspec/rails/mocks.rb
View
@@ -16,7 +16,7 @@ def persisted?
true
end
- def respond_to?(message)
+ def respond_to?(message, include_private=false)
message.to_s =~ /_before_type_cast$/ ? false : super
end
end
@@ -100,8 +100,8 @@ def @object.kind_of?(other)
def @object.instance_of?(other)
other == #{model_class}
end
- def @object.respond_to?(method_name)
- #{model_class}.respond_to?(:column_names) && #{model_class}.column_names.include?(method_name.to_s) || super
+ def @object.respond_to?(method_name, include_private=false)
+ #{model_class}.respond_to?(:column_names, include_private) && #{model_class}.column_names.include?(method_name.to_s) || super
end
def @object.class
#{model_class}
7 spec/rspec/rails/mocks/mock_model_spec.rb
View
@@ -144,6 +144,13 @@
MockableModel.stub(:column_names).and_return(["column_a", "column_b"])
@model = mock_model(MockableModel)
end
+
+ it "accepts two arguments" do
+ expect do
+ @model.respond_to?("title_before_type_cast", false)
+ end.to_not raise_exception
+ end
+
context "without as_null_object" do
it "says it will respond_to?(key) if RealModel has the attribute 'key'" do
@model.respond_to?("column_a").should be(true)

2 comments on commit 7a28bce

Randy Schmidt

This fixes the wrong number of arguments for me, thanks! However, I'm now noticing that whenever a mock comes before something that touches the database, for instance, running my controller specs and my model specs, in that order, that the process hangs and the memory footprint of the process keeps ballooning until I kill it.

I've been digging into this but can't seem to figure out why. Any ideas? Any suggestions for tracking it down? I'm seeing the behavior running something like:

rspec -f d spec/controllers/account_settings_controller_spec.rb spec/models/announcement_spec.rb

Randy Schmidt

Nevermind, I think. It had to do with setting the timezone on a request and having my mock user object use "as_null_object" which returned something Time.zone didn't like. I think this may be a bug somewhere, maybe in Rails? I would think something should fail instead of just blowing up in memory. Any ideas?

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