Rails Tutorial ch. 10 Test 10.20 failure

I have problem with test 10.20 in Rails Tutorial. After using command:

bundle exec rake test:mailers

I've received error:

Run options: --seed 6131 # Running: F Finished in 0.559132s, 1.7885 runs/s, 5.3655 assertions/s. 1) Failure: UserMailerTest#test_account_activation [/home/adam/workspace/sample_app /test/mailers/user_mailer_test.rb:11]: Expected: ["noreply@example.com"] Actual: nil 1 runs, 3 assertions, 1 failures, 0 errors, 0 skips

I've thoroughly checked my code and can't find the impropriety but I'm obviously doing it wrong.

Here's my user_mailer:

class UserMailer < ActionMailer::Base def account_activation(user) @user = user mail to: user.email, subject: "Account activation" end def password_reset @greeting = "Hi" mail to: "to@example.org" end end


require 'test_helper' class UserMailerTest < ActionMailer::TestCase test "account_activation" do user = users(:michael) user.activation_token = User.new_token mail = UserMailer.account_activation(user) assert_equal "Account activation", mail.subject assert_equal [user.email], mail.to assert_equal ["noreply@example.com"], mail.from assert_match user.name, mail.body.encoded assert_match user.activation_token, mail.body.encoded assert_match CGI::escape(user.email), mail.body.encoded end end

I've added this line to config/environments/test.rb:

config.action_mailer.default_url_options = { host: 'example.com' }

Can I have some advise?


You need to add :from to this line

mail to: user.email, subject: "Account activation"

like this

mail to: user.email, from: "noreply@example.com", subject: "Account activation"


All references to the User mailer should start with

class UserMailer < ApplicationMailer

This is due to recent changes in Rails 4.2. I missed a couple of references when I updated the tutorial last week, but these have now been corrected. Be sure you also include the Application mailer as shown in Listing 10.8. In fact, it's probably a good idea to remove the mailers and regenerate them from scratch to make sure your code conforms to the structure expected by Rails 4.2.


Simply edit the <strong>user_mailer.rb</strong> file from this:

class UserMailer < ActionMailer::Base

to this:

class UserMailer < ApplicationMailer

The reason being is that the default from: address is in the <strong>application_mailer.rb</strong> file and it pulls from ActionMailer::Base


  • PHPMailer - Unable to load MsgHTML
  • Render Different View (template) for ActionMailer
  • How to prevent mail from going to spam? [duplicate]
  • PHP OOXML Libraries? [closed]
  • How to capture enclosing scope in Runnable
  • Convert unix time to week day
  • Oracle ListaGG, Top 3 most frequent values, given in one column, grouped by ID
  • Rails AREL .where statement
  • Why I can't use uniform1f instead of uniform4f for setting a vec4 uniform?
  • Is there any way to use wpdb prepare statements for array implode(' OR ', $myArray)?
  • Regex for Specific Tag
  • Is there a way to set up a fallback for the formAction attribute in HTML5?
  • Vuejs: Lifecycle hooks of child routerview components using keep alive
  • Facebook iOS SDK Not Calling Completion Handler
  • Error in installing package: fatal error: stdlib.h: no such file or directory
  • CXF JAXB JAXBEncoderDecoder unmarshalling error : unexpected element when having qualified elements
  • How to make R's read_csv2() recognise the text characters properly
  • Trying to get the char code of ENTER key
  • Execute scripts AJAX returns
  • MySQL Order by column = x, column asc?
  • PHP buffered output depending on server setting?
  • Functions in global context
  • Deselecting radio buttons while keeping the View Model in synch
  • Nant, Vault & Windows Integrated Authentication
  • Is possible to count alias result on mysql
  • Check if a string to interpolate provides expected placeholders
  • Where to put my custom functions in Wordpress?
  • RestKit - RKRequestDelegate does not exist
  • WPF Applying a trigger on binding failure
  • Benchmarking RAM performance - UWP and C#
  • Acquiring multiple attributes from .xml file in c#
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • How can I remove ASP.NET Designer.cs files?
  • python draw pie shapes with colour filled
  • unknown Exception android
  • Is there any way to bind data to data.frame by some index?
  • Observable and ngFor in Angular 2
  • How can i traverse a binary tree from right to left in java?
  • Unable to use reactive element in my shiny app
  • java string with new operator and a literal