thoen
2012-Feb-17 16:06 UTC
[rspec-users] Rspec 2 expectations matching what is received, but failing
I noticed a couple of similar posts (such as http://groups.google.com/group/rspec/browse_thread/thread/81554bd8ad0b03a3/ed61a787c00dd601?lnk=gst&q=received+expected+is+the+same+as+got#ed61a787c00dd601), but they didn''t seem to have the same situation I have. Also, I apologize in advance for posting a question that is likely a simple syntax error or similar that I just don''t see. I am receiving the following error: Failures: 1) SignUpObserver#after_create callback for a volunteer with an email address delivers a ''new sign up'' email to the event owner Failure/Error: subject { sign_up_observer.after_create(sign_up) } <SignUpMailer (class)> received :new_sign_up_owner with unexpected arguments expected: (#<SignUp:0x83a54640 @name="SignUp_1005">, ) got: (#<SignUp:0x83a54640 @name="SignUp_1005">, ) # ./app/models/sign_up_observer.rb:4:in `after_create'' # ./spec/models/sign_up_observer_spec.rb:13:in `block (3 levels) in <top (required)>'' # ./spec/models/sign_up_observer_spec.rb:25:in `block (4 levels) in <top (required)>'' For this spec describe SignUpObserver do let(:event_owner) { mock_model(Person, :email => ''event_owner at test.host'').as_null_object } let(:event) { mock_model(Event, :owner => event_owner).as_null_object } let(:volunteer) { mock_model(Person, :email => volunteer_email).as_null_object } let(:volunteer_opportunity) { mock_model(VolunteerOpportunity, :event => event, :title => ''volunteer opportunity title'').as_null_object } let(:sign_up) { mock_model(SignUp, :assigner => event_owner, :person => volunteer, :volunteer_opportunity => volunteer_opportunity) } let(:sign_up_observer) { SignUpObserver.instance } describe ''#after_create callback'' do subject { sign_up_observer.after_create(sign_up) } context ''for a volunteer with an email address'' do let(:volunteer_email) { ''email at test.host'' } it "delivers a ''new sign up'' email to the event owner" do mock = mock(:emailer) SignUpMailer.should_receive(:new_sign_up_owner).with(sign_up, event_owner).and_return(mock) mock.should_receive(:deliver) subject end it "delivers a ''new sign up'' email to the person signing up" do should_send_kind_of_sign_up_email_to(:new_sign_up_signee, sign_up, volunteer) subject end end end end in SignUpObserver def after_create(sign_up) SignUpMailer.new_sign_up_signee(sign_up, sign_up.person).deliver if sign_up and sign_up.person and !sign_up.person.email.blank? SignUpMailer.new_sign_up_owner(sign_up, sign_up.volunteer_opportunity.event.owner) end So there are two things I can''t get my head around. The first is the expectation matching what I got. The second is the second parameter (event_owner) seems to be nil. I have checked it using debugger and it is not nil. I am upgrading from Rails 2.3.14 to rails 3.0.10. It passes in 2.3.14 I am using Rspec 2.8 Your gentle advice is greatly appreciated. Tom