【发布时间】:2015-02-22 17:50:08
【问题描述】:
我在 Rails 应用程序中编写 RSpec 测试以确保来自我的应用程序主页的简单链接重定向到 about 页面时遇到困难。我的功能测试文件中有以下内容:
scenario "Have links redirect to the correct paths" do
visit '/'
click_link('about')
expect(response).to redirect_to('about_index_path')
end
该链接的 id: 'about' 并且可以从浏览器进行测试,但我希望通过测试驱动开发做得更好。有什么建议么?我已经尝试了预期结果的多种变体,但我不断得到类似
NameError:
undefined local variable or method `response'
或
NoMethodError:
undefined method `assert_redirect_to'
当我把它放在控制器规范中时,我会得到类似
NoMethodError:
undefined method `click_link'
如有必要,我可以提供更多信息,但我认为这应该是一个非常简单的解决方案(例如测试链接是否重定向到'http://www.google.com'),我只是没有找到。任何其他建议的方法表示赞赏。谢谢!
【问题讨论】:
标签: ruby-on-rails rspec tdd capybara response.redirect