Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage in observer #104

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

Usage in observer #104

artur79 opened this issue Apr 24, 2012 · 0 comments

Comments

@artur79
Copy link

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant