Skip to content

Instantly share code, notes, and snippets.

@erithmetic
Created November 14, 2012 15:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erithmetic/4072673 to your computer and use it in GitHub Desktop.
Save erithmetic/4072673 to your computer and use it in GitHub Desktop.
Code for EU Cuke post
click 'add Widget'
page.should have_content('widget added')
find('a[rel~=create-form]').click
page.should have_selector('.status.success')
# Don't do this!
When %r{I try to add a widget with a missing type} do
step %{I go to the widget form}
step %{I fill in "name" with "test"}
step %{I fill in "color" with "red"}
step %{I choose "safe" from "safety_rating"}
step %{I submit the form}
end
When %r{I add a valid widget} do
visit '/widgets/new'
fill_in :name, with: 'test'
fill_in :type, with: 'alpha'
fill_in :color, with: 'red'
select 'safe', from: 'safety_rating'
find('input[type=submit]').click
end
When %r{I try to add a widget with a missing type} do
visit '/widgets/new'
fill_in :name, with: 'test'
fill_in :color, with: 'red'
select 'safe', from: 'safety_rating'
find('input[type=submit]').click
end
Then %r{the form submission should be successful} do
find('span.error')
end
Feature: Adding a widget
Scenario: Successful add
When I add a valid widget
Then the form submission should be successful
Scenario: Missing fields
When I try to add a widget with a missing type
Then the form submission should fail
Feature: Adding a widget
Scenario: Successful add
When I go to the widget form
And I fill in "name" with "test"
And I fill in "type" with "alpha"
And I fill in "color" with "red"
And I choose "safe" from "safety_rating"
And I submit the form
Then I should see "Widget added successfully"
Scenario: Missing fields
When I go to the widget form
And I fill in "name" with "test"
And I fill in "color" with "red"
And I choose "safe" from "safety_rating"
And I submit the form
Then I should see "Widget could not be added"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment