【发布时间】: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
我希望现在可以通过测试。但似乎在登录页面上出现“您需要先登录或注册才能继续”。
【问题讨论】:
-
不清楚确切的场景,但在黄瓜中检查
background,您可以在其中对用户进行身份验证。或者你可以使用before钩子。 -
@supputuri 我添加了功能文件。使用背景时我遇到了同样的问题
标签: ruby-on-rails cucumber bdd