【发布时间】:2014-02-21 10:53:04
【问题描述】:
我已经成功集成了 rspec gem.. 我的一些 tets 也与重定向传递有关。但是当我使用 have_tag or have_text or have_selector 时,它都不起作用...我在控制器规范文件的顶部添加了 render_views ,但我仍然收到错误:
没有达到水豚的期望!!!!
我应该怎么做才能断言/验证页面上的元素在我的测试中的某些操作后被重定向到导航到?
错误:
Failure/Error: response.body.should have_selector(:xpath, "//*[@id='header'
]/h2")
Capybara::ExpectationNotMet:
expected to find xpath "//*[@id='header']/h2" but there were no matches
# ./spec/controllers/account_controller_spec.rb:11:in `block (3 levels) in
<top (required)>'
测试:
describe AccountController do
render_views
describe "GET 'index'" do
it "should redirect to /users/sign_in" do
get 'welcome'
#response.should redirect_to("/users/sign_in")
response.body.should have_selector(:xpath, "//*[@id='header']/h2")
end
---- some more tests---
更新: 将此添加到 spec_helper.rb,仍然没有运气!
config.include Capybara::DSL
【问题讨论】:
标签: ruby-on-rails-3 rspec controller