Skip to content

Commit 7a28bce

Browse files
committed
respond_to?(method, include_private=false)
- Closes #282.
1 parent 7556316 commit 7a28bce

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

lib/rspec/rails/mocks.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def persisted?
1616
true
1717
end
1818

19-
def respond_to?(message)
19+
def respond_to?(message, include_private=false)
2020
message.to_s =~ /_before_type_cast$/ ? false : super
2121
end
2222
end
@@ -100,8 +100,8 @@ def @object.kind_of?(other)
100100
def @object.instance_of?(other)
101101
other == #{model_class}
102102
end
103-
def @object.respond_to?(method_name)
104-
#{model_class}.respond_to?(:column_names) && #{model_class}.column_names.include?(method_name.to_s) || super
103+
def @object.respond_to?(method_name, include_private=false)
104+
#{model_class}.respond_to?(:column_names, include_private) && #{model_class}.column_names.include?(method_name.to_s) || super
105105
end
106106
def @object.class
107107
#{model_class}

spec/rspec/rails/mocks/mock_model_spec.rb

+7
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,13 @@
144144
MockableModel.stub(:column_names).and_return(["column_a", "column_b"])
145145
@model = mock_model(MockableModel)
146146
end
147+
148+
it "accepts two arguments" do
149+
expect do
150+
@model.respond_to?("title_before_type_cast", false)
151+
end.to_not raise_exception
152+
end
153+
147154
context "without as_null_object" do
148155
it "says it will respond_to?(key) if RealModel has the attribute 'key'" do
149156
@model.respond_to?("column_a").should be(true)

0 commit comments

Comments
 (0)