Nei*_*ton 5 integration-testing ruby-on-rails capybara
我有两个水豚测试,第一个测试用户,第二个用于测试仅供登录用户使用的功能.
但是,我无法让第二个测试工作,因为会话不是跨测试维护的(显然,它应该是).
require 'integration_test_helper'
class SignupTest < ActionController::IntegrationTest
test 'sign up' do
visit '/'
click_link 'Sign Up!'
fill_in 'Email', :with => 'bob@wagonlabs.com'
click_button 'Sign up'
assert page.has_content?("Password can't be blank")
fill_in 'Email', :with => 'bob@wagonlabs.com'
fill_in 'Password', :with => 'password'
fill_in 'Password confirmation', :with => 'password'
click_button 'Sign up'
assert page.has_content?("You have signed up successfully.")
end
test 'create a product' do
visit '/admin'
save_and_open_page
end
end
Run Code Online (Sandbox Code Playgroud)
save_and_open_page调用生成的页面是全局登录屏幕,而不是我期望的管理主页(注册登录).我在这做错了什么?
发生这种情况的原因是测试是事务性的,所以你会在测试之间失去状态.要解决此问题,您需要在函数中复制登录功能,然后再次调用它:
def login
visit '/'
fill_in 'Email', :with => 'bob@wagonlabs.com'
fill_in 'Password', :with => 'password'
fill_in 'Password confirmation', :with => 'password'
click_button 'Sign up'
end
test 'sign up' do
...
login
assert page.has_content?("You have signed up successfully.")
end
test 'create a product' do
login
visit '/admin'
save_and_open_page
end
| 归档时间: |
|
| 查看次数: |
2292 次 |
| 最近记录: |