1

用户登录后,我无法让 Cucumber / Capybara 在页面上找到“成功”闪存消息。如果我在浏览器中手动操作,我可以看到该消息,所以我想我在我的步骤中做错了什么。

user_login.feature

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)
4

1 回答 1

3

基本上,我做了一个DERP。我用来填写表单的凭据(密码)与我通过 FactoryGirl 创建的用户不同。这导致在我测试“成功”消息时出现“无效的电子邮件/密码”消息。

为了调试页面输出的内容,我page.should have_content "asdfsdfas"在我的规范中添加了一个。当测试失败时,Cucumber 会输出它在页面上获得的内容,并与您期望它接收的内容进行比较。

于 2012-07-21T14:49:47.730 回答