Webrat 的 RoutingError 问题

发布于 2024-07-27 18:39:28 字数 874 浏览 7 评论 0原文

我目前正在用 Rails 重写一个网站。 我编写了一个模型,将旧的静态 URL 映射到新的静态 URL,并且在应用程序控制器中,我捕获 RoutingErrors 以调用一种方法来查找映射到旧 URL 的新 URL。 这在应用程序本身中运行得非常好; 如果我访问 http://localhost:3000/home.htm 它将重定向到 http://localhost:3000/home,但我无法让我编写的 Cucumber / Webrat 测试通过我总是收到这样的错误。

When I try to go to the old noticeboard          
  #features/step_definitions/redirection_steps.rb:7
  No route matches "/noticeboard.htm" with {:method=>:get} (ActionController::RoutingError)
  (eval):2:in `visit'
  ./features/step_definitions/redirection_steps.rb:8:in `/^I try to go to the old (.+)$/'
  features/old_urls.feature:26:in `When I try to go to the old noticeboard'

显然,最重要的是代码实际工作,并且它在浏览器中正确重定向,但我也希望测试能够通过。 有什么办法可以解决这个问题吗?

I'm currently rewriting a website in Rails. I've written a model that maps the old static URLs to the new ones and in the application controller I'm trapping RoutingErrors to call a method that looks for a new URL that maps to the old one. This works perfectly well in the applicaion itself; if I visit http://localhost:3000/home.htm it will redirect to http://localhost:3000/home, but I can't get the Cucumber / Webrat tests I've written to pass as I always get an error like this.

When I try to go to the old noticeboard          
  #features/step_definitions/redirection_steps.rb:7
  No route matches "/noticeboard.htm" with {:method=>:get} (ActionController::RoutingError)
  (eval):2:in `visit'
  ./features/step_definitions/redirection_steps.rb:8:in `/^I try to go to the old (.+)$/'
  features/old_urls.feature:26:in `When I try to go to the old noticeboard'

Obviously it's most important that the code actually works, and it does redirect correctly in the browser but I'd like the tests to pass too. Is there a way I can work around this?

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

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

发布评论

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

评论(1

夜清冷一曲。 2024-08-03 18:39:28

你解决过这个问题吗? 我在 webrat 中的访问方法上遇到了很多问题。 结果在我的环境中有 RAILS_ENV=development 。

Did you ever resolve this? I have been having a lot of issues with the visit method in webrat. This turned out to be having RAILS_ENV=development in my environment.

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