Module: CodyRobbins::EmailTestHelpers::Matchers

Defined in:
lib/cody_robbins/email_test_helpers/matchers.rb

Instance Method Summary collapse

Instance Method Details

#be_sent_from(name, address) ⇒ RSpec::Matchers::Matcher

Verifies both the address and display name an email is sent from. This just combines the be_sent_from_address and be_sent_from_display_name matchers.

Examples:

last_email.should.be_sent_from 'Dagny Taggart', '[email protected]'

Parameters:

  • name (String)

    The display name.

  • address (String)

    The email address.

Returns:

  • (RSpec::Matchers::Matcher)


63
64
65
66
67
68
# File 'lib/cody_robbins/email_test_helpers/matchers.rb', line 63

RSpec::Matchers.define(:be_sent_from) do |name, address|
  match do |mail|
    mail.should be_sent_from_display_name name
    mail.should be_sent_from_address address
  end
end

#be_sent_from_address(address) ⇒ RSpec::Matchers::Matcher

Verifies the address an email is sent from.

Examples:

last_email.should.be_sent_from_address '[email protected]'

Parameters:

  • address (String)

    The email address.

Returns:

  • (RSpec::Matchers::Matcher)


30
31
32
33
34
# File 'lib/cody_robbins/email_test_helpers/matchers.rb', line 30

RSpec::Matchers.define(:be_sent_from_address) do |address|
  match do |mail|
    mail.from.should == [address]
  end
end

#be_sent_from_display_name(name) ⇒ RSpec::Matchers::Matcher

Verifies the display name an email is sent from. The display name is the optional text outside the angle brackets in a From header such as Dagny Taggart <[email protected]>.

Examples:

last_email.should.be_sent_from_display_name 'Dagny Taggart'

Parameters:

  • name (String)

    The display name.

Returns:

  • (RSpec::Matchers::Matcher)


46
47
48
49
50
# File 'lib/cody_robbins/email_test_helpers/matchers.rb', line 46

RSpec::Matchers.define(:be_sent_from_display_name) do |name|
  match do |mail|
    mail[:from].display_names.should == [name]
  end
end

#be_sent_to(address) ⇒ RSpec::Matchers::Matcher

Verifies the address an email is sent to.

Examples:

last_email.should.be_sent_to '[email protected]'

Parameters:

  • address (String)

    The email address.

Returns:

  • (RSpec::Matchers::Matcher)


14
15
16
17
18
# File 'lib/cody_robbins/email_test_helpers/matchers.rb', line 14

RSpec::Matchers.define(:be_sent_to) do |address|
  match do |mail|
    mail.to.should == [address]
  end
end