0

当我在设计上执行黄瓜测试时遇到了问题。

失败的测试只是您安装设计时提供的默认测试(我只是在我的网站上修改了一些“登录”字样,变成了“登录”,但我认为这不是问题的原因)。

由于我是初学者,我什至不明白什么是错的或黄瓜告诉我什么。为什么在这里提到 rspec ?我应该添加 rspec-expectations gem 吗?

运行 cucumber 时出现在控制台上的错误:

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 I see a successful sign in message # features/step_definitions/user_steps.rb:152
  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 About Contact Help" (RSpec::Expectations::ExpectationNotMetError)
  ./features/step_definitions/user_steps.rb:153:in `/^I see a successful sign in message$/'
  features/users/sign_in.feature:16:in `Then I see a successful sign in message'
When I return to the site               # features/step_definitions/user_steps.rb:110
Then I should be signed in              # features/step_definitions/user_steps.rb:136

错误所指的文件:

/features/step_definitions/user_steps.rb

### UTILITY METHODS ###

def create_visitor
@visitor ||= { :name => "xxx", :email => "xxx@gmail.com",
:password => "xxx", :password_confirmation => "xxx" }
end

def find_user
@user ||= User.first conditions: {:email => @visitor[:email]}
end

def create_unconfirmed_user
create_visitor
delete_user
sign_up
visit '/users/sign_out'
end

def create_user
create_visitor
delete_user
@user = FactoryGirl.create(:user, email: @visitor[:email])
end

def delete_user
@user ||= User.first conditions: {:email => @visitor[:email]}
@user.destroy unless @user.nil?
end

def sign_up
delete_user
visit '/users/sign_up'
fill_in "Name", :with => @visitor[:name]
fill_in "Email", :with => @visitor[:email]
fill_in "user_password", :with => @visitor[:password]
fill_in "user_password_confirmation", :with => @visitor[:password_confirmation]
click_button "Sign up"
find_user
end

def sign_in
visit '/users/sign_in'
fill_in "Email", :with => @visitor[:email]
fill_in "Password", :with => @visitor[:password]
click_button "Login"
end

(....) and more below:

Then /^I see a successful sign in message$/ do
page.should have_content "Signed in successfully."
end

和 /features/users/sign_in.feature

    Scenario: User signs in successfully
  Given I exist as a user
    And I am not logged in
  When I sign in with valid credentials
  Then I see a successful sign in message
  When I return to the site
  Then I should be signed in

当我手动进入我的网站时,它确实显示“登录成功”。当我登录时,有什么问题?我真的不明白。

4

2 回答 2

1

添加以下步骤进行调试:

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

并将显示页面添加到功能中:

Given I exist as a user                 
And I am not logged in                  
When I sign in with valid credentials
Then show me the page
And I see a successful sign in message

它将帮助您调试错误。

于 2013-06-03T10:57:54.573 回答
0

将其放入 spec_helper 或 support/devise.rb

  config.include Devise::TestHelpers, :type => [:feature, :controller]
于 2013-12-03T10:35:29.633 回答