This document discusses using Cucumber and Webrat for integration testing a web application. Cucumber is a behavior-driven development tool that allows writing tests in a plain language format. Webrat is a tool that provides a domain-specific language for controlling and interacting with a web browser. The document shows examples of Cucumber feature and step definitions for testing updating a Twitter status, and how Webrat can be used to programmatically fill out and submit a form and assert the response.
14. Webrat Core API
? visit, click_link
? get + assert_response :success
? click_button
? submit form + assert_response :success
? submit form default values if any
15. Webrat + RSpec
describe "tweeting" do
it "should show my tweets" do
visit "/home"
fill_in "status", :with => "lorem ipsum"
click_button "update"
response.body.should =~ /lorem ipsum/
end
end
19. Feature: Update my status
In order to keep friends posted
As a friendly person
I post my status to twitter
Scenario: Update my status
Given I go to /home
When I fill in status with lorem ipsum
And I click send
Then I should see lorem ipsum
20. Feature: Update my status
In order to keep friends posted
As a friendly person
I post my status to twitter
Scenario: Update my status
Given I go to /home
When I fill in status with lorem ipsum
And I click send
Then I should see lorem ipsum
21. Feature: Update my status
In order to keep friends posted
As a friendly person
I post my status to twitter
Scenario: Update my status
Given I go to /home
When I fill in status with lorem ipsum
And I click send
Then I should see lorem ipsum
22. Scenario: Update my status
Given I go to /home
When I fill in status with lorem ipsum
And I click send
Then I should see lorem ipsum
Given C
When C
Then C
23. Given /^I go to "(.*)"$/ do |url|
visit url
end
When /^I fill in "(.*)" with "(.*)"$/ do |field,value|
fill_in field, :with => value
end
When /^I click "(.*)"$/ do |link|
click_link(link)
end
Then /^I should see "(.*)"$/ do |text|
response.body.should =~ /#{text}/m
end
27. Scenario: Update my status
Given I go to /home
When I fill in status with lorem ipsum
And I click send
Then I should see lorem ipsum
28. describe "tweeting" do
it "should show my tweets" do
visit "/home"
fill_in "status", :with => "lorem ipsum"
click_button "update"
response.body.should =~ /lorem ipsum/
end
end