我仍在尝试了解BDD 循环中的cucumber
和的组合。rspec
我为一个非常简单的登录系统定义了以下场景:
Feature: Log in
In order to get access to the application
As a user
I want to log in
Scenario: User logs in successfully
Given I exist as a user
When I go to the login page
And I fill in "username" with "gabrielhilal"
And I fill in "password" with "secret"
And I press "Login"
Then I should see "Welcome gabrielhilal"
And I should be redirected to the home page
Scenario: User enters wrong email/password combination
Given I exist as a user
When I go to the login page
And I fill in "username" with "gabrielhilal"
And I fill in "password" with "wrongpassword"
And I press "Login"
Then I should see "Invalid username/password combination."
And I should see the login page again
然后,我开始定义steps
等待合适的时机跳入rspec
.
我通过了第一步模拟用户FactoryGirl
并定义了步骤:
Given(/^I exist as a user$/) do
@user = FactoryGirl.create(:user)
end
我为会话添加了路由、控制器和操作:
When(/^I go to the login page$/) do
visit login_path
end
我创建了登录表单:
When(/^I fill in "([^"]*)" with "([^"]*)"$/) do |field, value|
fill_in field, with: value
end
When(/^I press "([^"]*)"$/) do |button|
click_on(button)
end
我将 Flash 消息添加到我的布局中:
When(/^I should see "([^"]*)"$/) do |arg|
page.should have_content(arg)
end
我为主页添加了路由和控制器(static_pages):
When(/^I should be redirected to the home page$/) do
visit home_path
end
我解决了最后一步:
When(/^I should see the login page again$/) do
visit login_path
end
而且我全都绿了……我觉得不需要rspec
经历这些场景。我错过了什么?
我试图了解我应该用 rspec 测试什么。我觉得用 rspec 再次测试所有内容都不合适......