Converting assert_sent_email to should have_sent_email

73 views
Skip to first unread message

Paul McMahon

unread,
Nov 17, 2010, 5:32:57 AM11/17/10
to shoulda
I'm in the process of upgrading shoulda, and I can't figure out how
best to resolve one deprecation.

Currently, I have code that looks like this:

should "create correct email" do
[@group.email_from] == email.from
end

If I was to change it to the should form, it would look something like

should have_sent_email.from(@group.email_from)

Which is invalid because @group is not defined within that scope.

Short of stubbing out the group's email_from, is there any other way I
can resolve this?

silent (e)

unread,
Dec 9, 2010, 1:26:19 AM12/9/10
to shoulda
I second the question. I've set up an instance variable in the setup
method of my context but it's not getting picked up.

matte

sant0sk1

unread,
Dec 9, 2010, 6:07:52 PM12/9/10
to shoulda
I just ran into this today as well. Instance variables created in the
setup block of a context are not available to the have_sent_email
matcher. An example:

context "Ticket Notifications" do
setup { @ticket = Factory(:ticket) }

should have_sent_email.to(@ticket.contact.email)
end

This raises an undefined method 'contact' for nil:NilClass error. This
is on 2.11.3 using Test::Unit.

Any ideas?
Reply all
Reply to author
Forward
0 new messages