Skip to content
Browse files

refactor tests

  • Loading branch information...
1 parent 7aec80e commit 9612a2b56058265e9cc85b440475cdeeebbd9980 @maryschmidt maryschmidt committed
View
23 spec/acceptance/visitor_adds_new_friend_spec.rb
@@ -1,24 +1,17 @@
require 'spec_helper'
feature 'visitor adds a new friend' do
- scenario 'add friend with image' do
- visit root_path
- click_link 'New Friend'
- fill_in 'Name', with: 'Mona Lisa'
- attach_file 'Avatar', 'spec/support/mona_lisa.jpg'
- click_button 'Make a friend'
+ scenario 'with image' do
+ add_friend_with_image('Mona Lisa', 'spec/support/mona_lisa.jpg')
- page.should have_css('h2', text: 'Mona Lisa')
- page.should have_xpath("//img[contains(@src, 'mona_lisa.jpg')]")
+ expect(page).to have_css('h2', text: 'Mona Lisa')
+ expect(page).to have_xpath("//img[contains(@src, 'mona_lisa.jpg')]")
end
- scenario 'add friend without image' do
- visit root_path
- click_link 'New Friend'
- fill_in 'Name', with: 'Mona Lisa'
- click_button 'Make a friend'
+ scenario 'without image' do
+ add_friend_without_image('Mona Lisa')
- page.should have_css('h2', text: 'Mona Lisa')
- page.should have_xpath("//img[contains(@src, 'missing.png')]")
+ expect(page).to have_css('h2', text: 'Mona Lisa')
+ expect(page).to have_xpath("//img[contains(@src, 'missing.png')]")
end
end
View
17 spec/acceptance/visitor_edits_friend_spec.rb
@@ -0,0 +1,17 @@
+require 'spec_helper'
+
+feature 'visitor edits a friend' do
+ scenario 'successful edit' do
+ add_friend_with_image('Mona Lisa', 'spec/support/mona_lisa.jpg')
+ edit_friend
+
+ expect(page).to have_text('Friend was successfully updated.')
+ end
+
+ def edit_friend
+ visit friends_path
+ click_link 'Edit'
+ fill_in 'Name', with: 'Mary Lisa'
+ click_button 'Make a friend'
+ end
+end
View
14 spec/support/friend_helper.rb
@@ -0,0 +1,14 @@
+def add_friend_with_image(name, image)
+ visit root_path
+ click_link 'New Friend'
+ fill_in 'Name', with: name
+ attach_file 'Avatar', image
+ click_button 'Make a friend'
+end
+
+def add_friend_without_image(name)
+ visit root_path
+ click_link 'New Friend'
+ fill_in 'Name', with: name
+ click_button 'Make a friend'
+end

0 comments on commit 9612a2b

Please sign in to comment.
Something went wrong with that request. Please try again.