Permalink
Browse files

Better documentation

  • Loading branch information...
1 parent 432e17b commit f5e1152ccad675906b45c519c6b852d4f1cafc1b @bcardarella bcardarella committed Mar 4, 2012
Showing with 44 additions and 1 deletion.
  1. +2 −0 .yardopts
  2. +5 −0 README.md
  3. +24 −1 lib/capybara/email/rspec/helpers.rb
  4. +13 −0 lib/capybara/node/email.rb
View
@@ -0,0 +1,2 @@
+--markup-provider=redcarpet
+--markup=markdown
View
@@ -39,6 +39,11 @@ feature 'Emailer' do
scenario 'testing for content' do
current_email.should have_content 'Hello Joe!'
end
+
+ scenario 'view the email body in your browser' do
+ # the `launchy` gem is required
+ current_email.save_and_open
+ end
end
```
@@ -1,26 +1,49 @@
module Capybara::Email::RSpecHelpers
- attr_accessor :current_email, :current_emails
+ # Returns the currently set email.
+ # If no email set will return nil.
+ #
+ # @return [Mail::Message, nil]
+ attr_accessor :current_email
+ attr_accessor :current_emails
+
+ # Access all emails
+ #
+ # @return [Array]
def all_emails
Mail::TestMailer.deliveries
end
+ # Access all emails for a recipient.
+ #
+ # @param [String]
+ #
+ # @return [Array<Mail::Message>]
def emails_sent_to(recipient)
self.current_emails = all_emails.select { |email| email.to.include?(recipient) }.map do |email|
driver = Capybara::Email::Driver.new(email)
Capybara::Node::Email.new(Capybara.current_session, driver)
end
end
+ # Access the first email for a recipient and set it to.
+ #
+ # @param [String]
+ #
+ # @return [Mail::Message]
def first_email_sent_to(recipient)
self.current_email = emails_sent_to(recipient).first
end
alias :open_email :first_email_sent_to
+ # Returns a collection of all current emails retrieved
+ #
+ # @return [Array<Mail::Message>]
def current_emails
@current_emails || []
end
+ # Clear the email queue
def clear_emails
all_emails.clear
self.current_emails = nil
View
@@ -1,21 +1,34 @@
class Capybara::Node::Email < Capybara::Node::Document
+ # Delgate to the email body
+ #
+ # @return [Mail::Message#body]
def body
base.raw
end
+ # Delgate to the email subject
+ #
+ # @return [Mail::Message#subject]
def subject
base.subject
end
+ # Delgate to the email to
+ #
+ # @return [Mail::Message#to]
def to
base.to
end
+ # Delgate to the email from
+ #
+ # @return [Mail::Message#from]
def from
base.from
end
+ # Will open the email body in your browser
def save_and_open
require 'capybara/util/save_and_open_page'
::Capybara.save_and_open_page(body)

0 comments on commit f5e1152

Please sign in to comment.