Skip to content

Instantly share code, notes, and snippets.

@knwang
Created June 14, 2013 07:41
Show Gist options
  • Save knwang/5780146 to your computer and use it in GitHub Desktop.
Save knwang/5780146 to your computer and use it in GitHub Desktop.
Rspec feature spec with rspec-given
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