Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Usage in observer #104

Open
artur79 opened this Issue Apr 24, 2012 · 0 comments

Comments

Projects
None yet
1 participant

artur79 commented Apr 24, 2012

Hi,
In my application emails is send inside observer. My spec looks like this

  it "should send email when something ..." do

    ActiveRecord::Observer.with_observers(:post_observer) do

      @post = FactoryGirl.build(:post)
      @post.save

      PostMailer.should_receive(:deliver_some_email) do |mail|
              mail.to.should == [ 'lala@gmail.com' ]
              mail.body.should =~ /congratulations/i
      end

    end
  end

I've checked with famous ruby debug tool called "puts" :) and observer is triggered when running a spec, but I'm getting failure:

 Failure/Error: PostMailer.should_receive(:deliver_some_email) do |mail|
   (<PostMailer (class)>).deliver_some_email(any args)
       expected: 1 time
       received: 0 times

But when checking traditional way, like ActionMailer::Base.deliveries.last.subject, it has expected value

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