我无法让Cucumber / Capybara在用户登录后在页面上找到“成功”的Flash消息。如果我在浏览器中手动执行此操作,我就能看到该消息,所以我'我以为我在步骤中做错了什么。
Feature: User login
Scenario: A user successfully logs in from the homepage
Given A user is on the homepage
When the user clicks "Login"
And they fill out the form
Then they should see a success message
Given /^A user is on the homepage$/ do
@user = Factory.create(:user)
visit root_path
end
When /^the user clicks "(.*?)"$/ do |arg1|
click_link arg1
end
When /^they fill out the form$/ do
fill_in "email", with: @user.email
fill_in "password", with: "blahblah1"
click_button "Sign in"
end
Then /^they should see a success message$/ do
page.should have_selector ".alert", text: "Logged in!"
end
expected css ".alert" with text "Logged in!" to return something (RSpec::Expectations::ExpectationNotMetError)
答案 0 :(得分:3)
基本上,我做了一个 DERP 。我使用(密码)填写表单的凭据与我通过FactoryGirl创建的用户不同。这导致在我测试“成功”消息时出现“无效的电子邮件/密码”消息。
要调试页面输出的内容,我在规范中添加了page.should have_content "asdfsdfas"
。当测试失败时,Cucumber输出它在页面上获得的内容与您预期接收的内容相比。