thoughtbot/shoulda-matchers — Issue #63: have_sent_email add to model test?
Author: fourcolors
Created: 2012-03-03 04:44:04+00:00
State: open

Hi

I was wondering, would it be useful to add the ability to test if a models method sends an email? Here is my reasoning. I have an Invitation model and I would like to send out an invite which does two things. 1 sends an email 2. Updates my sent_at column so I thought it would make sense to have a public method on my invitation model called "send_invite!" that would send the invitation then update my sent_at column.

I want to create a test for that that would only send invites when the sent_at column is nil. Currently it seems like you can only test Mailers. (I keep getting this error)

```ruby
Failure/Error: it{ should have_sent_email( @invitation.email )}
NoMethodError:
undefined method `has_sent_email?' for #
# ./spec/models/invitation_spec.rb:29:in `block (4 levels) in '
```

which makes sense however because Im testing on a model.

Anyway, does that seem right or is my logic skewed?