黄瓜登录不起作用

时间:2014-01-28 21:53:17

标签: ruby-on-rails devise cucumber

我可以使用浏览器登录,但Cucumbe无法登录。

我的用户/ sign_out路由接受GET。

特征/ step_denfinitions / home_page_steps.rb:

When(/^I am on the homepage$/) do
  visit root_path
end

Then (/^I should see "(.*?)"$/) do |t|
  assert page.has_content?(t)
end

Given (/^I am signed in$/) do
  visit ('/users/sign_out')
  email = 'game@maker.com'
  password = 'password'
  visit '/users/sign_in'
  fill_in "user_email", :with => email
  fill_in "user_password", :with => password
  click_button "Sign in"
end

And(/^I go to home page$/) do
  visit root_path 
end

特征/ home_page.feature:

Feature: Home page

  Scenario: Viewing home page
    Given I am on the homepage
    Then I should see "Hello"

  Scenario: Signed in can create a game
    Given I am signed in
    Then I should see "Create Game"

/app/views/welcome/index.html(我的根路径):

<h1>Welcome#index</h1>
"Hello"
<p>Find me in app/views/welcome/index.html.erb</p>

  <% if user_signed_in? %> <<< This works in my browser but not for cucumber
    <%= link_to "Create Game", new_game_path %>
  <% end %>

1 个答案:

答案 0 :(得分:0)

好的,Cucumber实际上并没有真正的用户登录..我必须动态创建用户。

Testing login with devise and cucumber