Skip to content
Browse files

convenience method for associating your stubs with other stubs in mod…

…el definitions
  • Loading branch information...
1 parent 287558d commit ccc4392893a0f3c75e21fc6ba66825a8b4f9f43f @technoweenie committed Jul 31, 2008
Showing with 14 additions and 0 deletions.
  1. +14 −0 lib/model_stubbing/model.rb
View
14 lib/model_stubbing/model.rb
@@ -104,5 +104,19 @@ def purge
def connection
@connection ||= model_class.respond_to?(:connection) && model_class.connection
end
+
+ protected
+ def method_missing(model_name, stub_name, *args)
+ named_model = @definition.models[model_name]
+ if named_model.nil?
+ raise "No #{model_name.inspect} model found when calling #{model_name}(#{stub_name})"
+ end
+ stub = named_model.stubs[stub_name]
+ if stub.nil?
+ raise "No #{stub_name.inspect} stub found in the #{model_name.inspect} model when calling #{model_name}(#{stub_name})"
+ else
+ stub
+ end
+ end
end
end

0 comments on commit ccc4392

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