我可能会做一些非常简单的错误,但我不太确定它是什么.我正在将rails 2应用程序移植到rails 3.此应用程序使用webmock进行一系列测试.
如果我包括
gem 'webmock'
Run Code Online (Sandbox Code Playgroud)
在我的Gemfile中,测试通过,但是当我启动服务器并在本地运行应用程序时,点击应该进行Web调用的控制器会引发错误:
WebMock::NetConnectNotAllowedError
Run Code Online (Sandbox Code Playgroud)
如果我不在我的Gemfile中包含该行,那么当我在本地运行应用程序时,它工作正常,但测试错误:
`require': no such file to load -- webmock (LoadError)
Run Code Online (Sandbox Code Playgroud)
在我的test_helper.rb中命中这一行时
require 'webmock'
Run Code Online (Sandbox Code Playgroud)
我猜我有一些配置错误,但我还没有找到正确的谷歌咒语,以便对它有所了解.我在哪里,我误入歧途?
谢谢.
我有一些代码基本上显示了给定表中的最后一个x(变量,但是假设x在这里是20).在其中一个单元测试中,我有这个片段:
EditedItem.push_to_queue(hiddennow)
#create some new entries and save them
20.times{ EditedItem.push_to_queue(random_item) }
Queue.get_entries.each{|entry| assert_not_equal too_far_down, entry}
Run Code Online (Sandbox Code Playgroud)
可能是也可能不是很漂亮,但它有意图.hiddennow对象已在队列中被推下太远,并且在调用get_entries时不应再返回.
#this works
SearchObject.find(:all, :order => "id desc")
#this does not, unless the 20.times loop has sleep(1) or something
SearchObject.find(:all, :order => "created_at desc")
Run Code Online (Sandbox Code Playgroud)
这简化了一点,但看起来像20次循环添加的东西足够快,以至于created_at上的order by子句无法区分.我的问题是,我做了一些根本错误的事情吗?如果没有,沿着这些方向编写测试的更好方法是什么?