I ended up looking at the pony spec file, and stealing code from it to write my specs =)
This is what I have:
./spec/spec_helper.rb
def do_not_send_email
Pony.stub!(:deliver) # Hijack deliver method to not send email
end
RSpec.configure do |conf|
conf.include Rack::Test::Methods
conf.mock_with :rspec
# ...
conf.before(:each) do
do_not_send_email
end
end
./spec/integration/invite_user_spec.rb
require_relative '../spec_helper'
feature "Invite user" do
scenario "should send an invitation email" do
visit "/"
click_link "start-btn"
within_fieldset("Invite new user") do
fill_in 'new_user_email', :with => 'franz@gmail.com'
Pony.should_receive(:mail) { |params|
params[:to].should == "franz@gmail.com"
params[:subject].should include("You are invited to blah")
params[:body].should include("You've been invited to blah")
params[:body].should include("/#{@account_id}/new-user/register")
}
click_button 'new_user'
end
page.should have_content("Invitation email has been sent")
end
end