Ruby on Rails stubbing method when working on the view
I have an action that contains the following call:
parser = Parser.new(open(@urlsearch.url))
The problem is that this is an expensive call and also relies on me having internet connectivity.
When I am running this from a functional test, I can stub this call using mocha but I want to stub this when I am working on the view. I do not want to have to wait for this call to execute when refreshing the page while 开发者_开发知识库working on the UI.
Can anyone suggest a good way of doing this?
my first reaction is to simply wrap that with an if statement:
if Rails.env == "development"
parser = Parser.new(open(@urlsearch.url))
else
parser = #do your stub
end
精彩评论