黄瓜设计签到一步失败(铁路3.2,黄瓜,水豚,rspec)

时间:2013-06-03 19:03:25

标签: ruby-on-rails ruby-on-rails-3 rspec devise cucumber

每次我运行默认设计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'

正如您所看到的水豚/黄瓜试图连接但是“无效的电子邮件或密码

所以我使用了一个在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

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

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

1 个答案:

答案 0 :(得分:0)

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