1

每次我运行默认设计 user_step 测试“登录”它都会失败。

奇怪的是我得到的错误

Scenario: User signs in successfully     # features/users/sign_in.feature:12
    Given I exist as a user                # features/step_definitions/user_steps.rb:58
    And I am not logged in                 # features/step_definitions/user_steps.rb:49
    When I sign in with valid credentials  # features/step_definitions/user_steps.rb:72
    Then show me the page                  # features/step_definitions/user_steps.rb:152
And I see a successful sign in message # features/step_definitions/user_steps.rb:156
      expected to find text "Signed in successfully." in "Mywebsite Follow us How it works More Login × **Invalid email or password**. Login * Email Password Remember me Not a member yet? Sign Up Now!Forgot your password?Didn't receive confirmation instructions? Rails Tutorial " (RSpec::Expectations::ExpectationNotMetError)
      ./features/step_definitions/user_steps.rb:157:in `/^I see a successful sign in message$/'
      features/users/sign_in.feature:17:in `And I see a successful sign in message'

如您所见,capybara/cucumber 尝试连接但得到“无效的电子邮件或密码

所以我使用了一个在 SO 上看到的技巧,并添加了看看 capybara 真正得到了什么

 Then /^show me the page$/ do
  save_and_open_page
end

它尝试使用我放在文件 user_steps.rb 顶部的凭据:

 def create_visitor
  @visitor ||= { :name => "Testy McUserton", :email => "example@example.com",
    :password => "please", :password_confirmation => "please" }
end

但这让我“无效”(我可以在 capyabra 页面的电子邮件字段中看到 example@example.com,因此它知道我希望这是电子邮件。

我迷路了。为什么它不起作用?

4

1 回答 1

0

您需要先在数据库中创建用户。User.create(name: "Testy McUserton", email: "example@example.com", password: "please", :password_confirmation: "please"). 然后您可以使用凭据登录。您也可以使用 factorygirl链接

于 2013-06-03T21:32:20.173 回答