要将第一个Cucumber测试添加到Rails应用程序,请按照以下步骤操作:
gem install cucumber-rails
rails generate cucumber:install
这将在您的Rails应用程序中创建一个名为“features”的目录,并在其中创建一个名为“support”的子目录。在“support”目录中,您将看到一个名为“env.rb”的文件,这是Cucumber测试的配置文件。
Feature: User registration
In order to access the application
As a new user
I want to be able to register
Scenario: Register with valid information
Given I am on the registration page
When I fill in "Username" with "testuser"
And I fill in "Password" with "password"
And I fill in "Confirm Password" with "password"
And I click "Register"
Then I should see "Registration successful"
Given /^I am on the registration page$/ do
visit '/register'
end
When /^I fill in "([^"]*)" with "([^"]*)"$/ do |field, value|
fill_in(field, :with => value)
end
When /^I click "([^"]*)"$/ do |button|
click_button(button)
end
Then /^I should see "([^"]*)"$/ do |text|
page.should have_content(text)
end
cucumber
如果一切正常,您应该会看到Cucumber测试通过的消息。
现在,您已经成功地将第一个Cucumber测试添加到了Rails应用程序中。您可以继续添加更多的Cucumber测试,以确保您的应用程序按预期工作。
领取专属 10元无门槛券
手把手带您无忧上云