开发者

Ruby on Rails stubbing method when working on the view

开发者 https://www.devze.com 2023-02-15 18:41 出处:网络
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.

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
0

精彩评论

暂无评论...
验证码 换一张
取 消