【问题标题】:How do I Authenticate user before cucumber test?如何在黄瓜测试之前对用户进行身份验证?
【发布时间】:2019-06-16 20:07:52
【问题描述】:

我正在尝试使用 Cucumber(用于功能测试)和 RSpec(用于单元测试)围绕 BDD。

我在编写 Cucumber 的第一个测试时遇到问题。我需要先认证,但不知道怎么做。

Given(/^A logged in user$/) do
    visit new_user_session_path
    fill_in "Email Address", :with => "sebhastien@gibosse.com"
    fill_in "Password", :with => "123456"
    click_button "Log In"
end

When(/^I go to the teams page$/) do
    visit teams_path
end

Then(/^I should see a list of my teams$/) do
    expect(page).to have_content("Teams#index")
end

特点:

Feature: Hello Cucumber
    As a user
    I want to see a list of teams on the Teams page
    So that I can manage them

    Background: User is Authenticated
        Given A logged in user

    Scenario: User sees teams
        When I go to the teams page
        Then I should see a list of my teams

我希望现在可以通过测试。但似乎在登录页面上出现“您需要先登录或注册才能继续”。

【问题讨论】:

标签: ruby-on-rails cucumber bdd


【解决方案1】:

成功了

Given (/^I am not authenticated$/) do
    visit('/users/sign_out') # ensure that at least
end

Given (/^I am a new, authenticated user$/) do
    email = 'testing@man.net'
    password = 'secretpass'
    User.new(:email => email, :password => password, :password_confirmation => password).save!

    visit '/users/sign_in'
    fill_in "user_email", :with => email
    fill_in "user_password", :with => password
    click_button "Log In"

end

When(/^I go to the teams page$/) do
    visit teams_path
end

Then(/^I should see a list of my teams$/) do
    expect(page).to have_content("Teams#index")
end

特点:

Feature: Hello Cucumber
    As a user
    I want to see a list of teams on the Teams page
    So that I can manage them

    Background: User Authenticates
        Given I am not authenticated
        Given I am a new, authenticated user

    Scenario: User sees teams
        When I go to the teams page
        Then I should see a list of my teams

【讨论】:

    猜你喜欢
    • 2011-12-04
    • 1970-01-01
    • 2017-08-27
    • 2017-05-13
    • 1970-01-01
    • 1970-01-01
    • 2013-10-23
    • 1970-01-01
    • 2012-05-17
    相关资源
    最近更新 更多