我正致力于使用(RSpec
和Capybara
)编写测试用例。
capybara (2.7.1) and
rspec (3.4.0)
rspec-core (3.4.4)
rspec-expectations (3.4.0)
rspec-mocks (3.4.1)
rspec-rails (3.4.2)
rspec-support (3.4.1)
有很多答案可用,但没有运气!!!这些是我找到的结果:1,2和3
capybara.rb
Capybara.asset_host = 'http://localhost:3000'
Capybara.default_max_wait_time = 5
session_helpers.rb
module Features
module SessionHelpers
def sign_up_with(email, password, confirmation)
visit new_user_registration_path
fill_in 'Email', with: email
fill_in 'Password', with: password
fill_in 'Password confirmation', :with => confirmation
click_button 'Sign up'
end
def signin(email, password)
visit root_url
find(:xpath, "//a[@class='login_box_btn']").click
fill_in 'login_user_email', with: email
fill_in 'login_user_password', with: password
click_button "LOGIN"
end
end
end
功能/用户/ sign_in_spec.rb
feature 'Sign-In and Sign-Out', :devise do scenario 'user cannot sign in if not registered' do
signin('test@example.com', 'please123')
expect(page.find(:xpath, "//div[@id='login_message']")).to have_content("Email not found. Please provide a valid email.")
end
期待
find(:xpath, "//div[@id='login_message']") => ""
但它不应该是空的。
当我跟随RailsApps/rails-devise完成任务后,所有配置都根据此回购。
如果有人需要更多相关信息,请发表评论。
答案 0 :(得分:1)
尝试将js: true
添加到方案中,例如:
scenario 'user cannot sign in if not registered', js: true do