Skip to content
Browse files

Stub attribute accessor after respond_to? call on mocked model. Fixes #…

  • Loading branch information...
1 parent 9bf3e32 commit 9a23ba17d80f2081c3d4169a2fa6d0f79838f298 @iafonov iafonov committed with dchelimsky Dec 7, 2011
Showing with 11 additions and 1 deletion.
  1. +6 −1 lib/rspec/rails/mocks.rb
  2. +5 −0 spec/rspec/rails/mocks/mock_model_spec.rb
View
7 lib/rspec/rails/mocks.rb
@@ -121,7 +121,12 @@ def @object.instance_of?(other)
end unless #{stubs.has_key?(:instance_of?)}
def @object.respond_to?(method_name, include_private=false)
- #{model_class}.respond_to?(:column_names) && #{model_class}.column_names.include?(method_name.to_s) || super
+ if #{model_class}.respond_to?(:column_names) && #{model_class}.column_names.include?(method_name.to_s)
+ stub!(method_name) unless [#{stubs.keys.map{|stub| ":#{stub}"}.join(',')}].include?(method_name)
+ true
+ else
+ super
+ end
end unless #{stubs.has_key?(:respond_to?)}
def @object.class
View
5 spec/rspec/rails/mocks/mock_model_spec.rb
@@ -188,6 +188,11 @@
it "says it will respond_to?(key) if RealModel has the attribute 'key'" do
@model.respond_to?("column_a").should be(true)
end
+ it "stubs column accessor method after respond_to call" do
+ lambda { @model.column_a }.should raise_error
+ @model.respond_to?("column_a").should be(true)
+ lambda { @model.column_a }.should_not raise_error
+ end
it "says it will not respond_to?(key) if RealModel does not have the attribute 'key'" do
@model.respond_to?("column_c").should be(false)
end

0 comments on commit 9a23ba1

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