Skip to content

Instantly share code, notes, and snippets.

@kirkbushell
Created January 30, 2012 03:25
Show Gist options
  • Save kirkbushell/1702294 to your computer and use it in GitHub Desktop.
Save kirkbushell/1702294 to your computer and use it in GitHub Desktop.
rspec mock issue
require "spec_helper"
describe UserMailer do
describe "registration_email" do
@user = mock_model(User, :email => 'some@email.com', :first_name => 'john')
let(:mail) { UserMailer.registration_email(@user) }
it "renders the headers" do
mail.subject.should eq("Welcome to ScreenZone!")
mail.to.should eq([@user.email])
mail.from.should eq(["support@screenzone.com"])
end
it "renders the body" do
mail.body.encoded.should match("<p>Welcome to Screenzone, #{@user.first_name}</p>")
end
end
end
@mipearson
Copy link

@user = mock_model(User, :email => 'some@email.com', :first_name => 'john')

should be:

before :each do
  @user = mock_model(User, :email => 'some@email.com', :first_name => 'john')
end

@mipearson
Copy link

or,

let(:user) { mock_model(User, :email => 'some@email.com', :first_name => 'john') }

and change instances of @user to user

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment