Skip to content

Commit

Permalink
Merge pull request #183 from email-spec/fixes/decode-default-part-body
Browse files Browse the repository at this point in the history
Fixes/decode default part body
  • Loading branch information
Mauro Otonelli committed May 4, 2016
2 parents 25282f0 + a4cf99e commit de8ac15
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
18 changes: 12 additions & 6 deletions examples/rails4_root/spec/models/user_mailer_spec.rb
@@ -1,7 +1,7 @@
require File.dirname(__FILE__) + '/../spec_helper'

# These two example groups are specifying the exact same behavior. However, the documentation style is different
# and the value that each one provides is different with various trade-offs. Run these examples with the specdoc
# and the value that each one provides is different with various trade-offs. Run these examples with the specdoc
# formatter to get an idea of how they differ.
# Example of documenting the behaviour explicitly and expressing the intent in the example's sentence.
describe "Signup Email", :type => :model do
Expand All @@ -10,22 +10,20 @@
include ::Rails.application.routes.url_helpers

subject { UserMailer.signup("jojo@yahoo.com", "Jojo Binks") }

it "should be delivered to the email passed in" do
is_expected.to deliver_to("jojo@yahoo.com")
end

it "should contain the user's name in the mail body" do
is_expected.to have_body_text(/Jojo Binks/)
end

it "should contain a link to the confirmation page" do
is_expected.to have_body_text(/#{confirm_account_url(:host => 'example.com')}/)
end

it { is_expected.to have_subject(/Account confirmation/) }


end

# In this example group more of the documentation is placed in the context trying to allow for more concise specs.
Expand All @@ -44,4 +42,12 @@
it { is_expected.to deliver_to("jojo@yahoo.com") }
it { is_expected.to have_body_text(/Jojo Binks/) }
end

describe "sent with email address of 'jermain@yahoo.com', and users name 'Jermain O'Keefe'" do
let(:user_name) { "Jermain O'Keefe" }
subject { UserMailer.signup("jermain@yahoo.com", user_name) }

it { is_expected.to deliver_to("jermain@yahoo.com") }
it { is_expected.to have_body_text(user_name) }
end
end
2 changes: 1 addition & 1 deletion features/rails4_app.feature
Expand Up @@ -22,7 +22,7 @@ I want to verify that the example rails 4 app runs all of it's features as expec
When I run "bundle exec rake spec RAILS_ENV=test" in the rails4 app
Then I should see the following summary report:
"""
9 examples, 0 failures
11 examples, 0 failures
"""

When I run "bundle exec rake test RAILS_ENV=test" in the rails4 app
Expand Down
2 changes: 1 addition & 1 deletion lib/email_spec/mail_ext.rb
Expand Up @@ -4,7 +4,7 @@ def default_part
end

def default_part_body
default_part.body
HTMLEntities.new.decode(default_part.body)
end

def html
Expand Down
7 changes: 7 additions & 0 deletions spec/email_spec/matchers_spec.rb
Expand Up @@ -402,6 +402,13 @@ def match(object_to_test_match)
end

describe "when strings are used" do
it "should match when the body includes text with symbols" do
full_name = "Jermain O'Keefe"
email = Mail::Message.new(body: full_name)

expect(have_body_text(full_name)).to match(email)
end

it "should match when the body includes the text" do
email = Mail::Message.new(:body => 'foo bar baz')

Expand Down

0 comments on commit de8ac15

Please sign in to comment.