Created
January 9, 2016 17:52
-
-
Save lukemorton/6f56ef24dea0516803be to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
feature 'Thing' do | |
scenario 'Creating a thing' do | |
when_creating_thing | |
then_should_see_thing_created | |
end | |
scenario 'Updating a thing' do | |
when_updating_thing | |
then_should_see_thing_updated | |
end | |
scenario 'Updating a thing with already taken name' do | |
when_updating_thing_with_already_taken_name | |
then_should_see_already_taken_name_error | |
end | |
def when_creating_thing | |
visit new_thing_path | |
fill_in :name, with: thing_name | |
click_button 'create thing' | |
end | |
def then_should_see_thing_created | |
assert_thing_in_response | |
end | |
def when_updating_thing | |
update_things_name | |
end | |
def then_should_see_thing_updated | |
assert_thing_in_response | |
end | |
def when_updating_thing_with_already_taken_name | |
create(:thing, name: thing_name) | |
update_things_name | |
end | |
def then_should_see_already_taken_name_error | |
expect(page).to have_content('already taken') | |
end | |
private | |
let(:thing_name) { 'Thingy' } | |
def update_things_name | |
visit edit_thing_path(create(:thing)) | |
fill_in :name, with: thing_name | |
click_button 'update thing' | |
end | |
def assert_thing_in_response | |
expect(page).to have_content(thing_name) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment