当通过“rake spec”调用时,RSpec 规范失败;通过“spec spec”调用时,RSpec 规范通过。

发布于 2024-08-23 03:27:12 字数 721 浏览 4 评论 0原文

当我通过“rake spec”运行它时,我的其中一项规格失败,但当我使用 RSpec 可执行文件“spec”时,它通过了。 当我在 ActionMailer 视图中使用 url 帮助器时,规范失败。错误消息是:

auction_url failed to generate from {:action=>"show", :state=>"asd", :slug=>"asd", :controller=>"auctions"}, expected: {:action=>"show", :controller=>"auctions"}, diff: {:state=>"asd", :slug=>"asd"}

:state 和 :slug 是 url 的必需属性。 路线如下所示:

map.auction ':state/:slug', :controller => 'auctions', :action => 'show'

我在环境文件中设置了在 ActionMailer 视图中使用 url 帮助程序所需的主机:

ActionMailer::Base.default_url_options[:host] = 'myhost.com'

可能是什么问题? 为什么“rakespec”的行为与“specspec”不同? 使用其中之一时是否加载/未加载任何内容?

One of my specs fails when I run it via "rake spec" but passes when I use the RSpec executable "spec".
The spec fails when I use a url helper in a ActionMailer view. The error message is:

auction_url failed to generate from {:action=>"show", :state=>"asd", :slug=>"asd", :controller=>"auctions"}, expected: {:action=>"show", :controller=>"auctions"}, diff: {:state=>"asd", :slug=>"asd"}

:state and :slug are required attributes for the url, though.
The route looks like this:

map.auction ':state/:slug', :controller => 'auctions', :action => 'show'

I set the host, which is needed to use the url helpers in ActionMailer views, in the environment files:

ActionMailer::Base.default_url_options[:host] = 'myhost.com'

What could be the problem?
Why is "rake spec" behaving differently from "spec spec"?
Anything that is loaded/not loaded when using one or the other?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

独守阴晴ぅ圆缺 2024-08-30 03:27:12

我意识到这有点老了,但无论如何 - 我刚刚遇到了同样的问题,也不是第一次了。然后,当我开始将调试语句插入失败的规范以找出发生了什么时 - rake 规范再次工作。所以我怀疑当规范涉及 rake 时会发生某种缓存。如果再次发生这种情况,也许可以尝试运行

rake tmp:cache:clear

,甚至

rake tmp:clear

I realize this is a bit old, but anyway - I just ran into the same problem, not for the first time either. Then, when I started inserting debug statements into the failing spec to figure out what was going on - rake spec worked again. So I suspect some sort of caching going on when spec is involved with rake. If this occurs again, maybe try running

rake tmp:cache:clear

or even

rake tmp:clear
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文