黄瓜设计登录步骤失败(rails 3.2, Cucumber, capybara, rspec)



每次我运行默认的设计user_step测试" sign in"都失败。

奇怪的是我得到的错误

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上看到的技巧,并添加了看看水豚到底得到了什么

 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

但是它让我"无效(我可以看到example@example.com写在capyabra页面上的电子邮件字段,所以它明白我想要这是电子邮件。

我迷路了。

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

最新更新