3

How can I write this so it passes without hardcoding 1. Chicken and the egg.

@sender = Factory(:user)
@receiver = Factory(:user)

mailer = double
mailer.should_receive(:deliver)
Mailer.should_receive(:email).with(1, @sender.id, @receiver.id).and_return(mailer)

# This will create an object with id #1 to make this test pass
@object = Object.create(:sender => @sender, :receiver => @receiver)
maletor
  • 7,072
  • 7
  • 42
  • 63
  • i think rspec uses should-matchers to verify the expected arguments on 'should_receive', otherwise things like anything() could not work? my idea would be to write an own argument matcher, which matches to the first id in the database. – Marian Theisen Sep 13 '11 at 07:22
  • 1
    While this is still a problem in the abstract here, I resolved it in my specific problem. I turned deliveries on in `test.rb` and am using `ActionMailer::Base.deliveries` to test mailing. – maletor Sep 13 '11 at 18:10

1 Answers1

4

How about this?

Mailer.should_receive(:email).with(an_instance_of(Fixnum), @sender.id, @receiver.id).and_return(mailer)
Paulo Casaretto
  • 967
  • 10
  • 33