Created
June 14, 2013 07:41
-
-
Save knwang/5780146 to your computer and use it in GitHub Desktop.
Rspec feature spec with rspec-given
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
require 'spec_helper' | |
feature 'User invites a friend' do | |
context 'User successfully invites friend to join' do | |
Given(:alice) { Fabricate(:user) } | |
When do | |
sign_in(alice) | |
invite_a_friend | |
friend_accepts_invitation | |
friend_signs_in | |
end | |
Then { friend_should_follow(alice) } | |
And { inviter_should_follow_friend(alice) } | |
end | |
def invite_a_friend | |
visit new_invitation_path | |
fill_in "Friend's Name", with: "John Doe" | |
fill_in "Friend's Email Address", with: "joe@example.com" | |
fill_in "Message", with: "Hello please join this!" | |
click_button "Send Invitation" | |
visit sign_out_path | |
end | |
def friend_accept_invitation | |
open_email "joe@example.com" | |
current_email.click_link "Accept this invitation" | |
fill_in "Password", with: "password" | |
fill_in "Full Name", with: "John Doe" | |
click_button "Sign Up" | |
end | |
def friend_signs_in | |
fill_in "Email Address", with: "joe@example.com" | |
fill_in "Password", with: "password" | |
click_button "Sign in" | |
end | |
def friend_should_follow(user) | |
click_link "People" | |
expect(page).to have_content user.full_name | |
visit sign_out_path | |
end | |
def inviter_should_follow_friend(inviter) | |
sign_in(inviter) | |
click_link "People" | |
expect(page).to have_content "John Doe" | |
clear_email | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment