223seneca
223seneca

Reputation: 1176

RSpec 3.6 and Rails 5.0.1 - ArgumentError: wrong number of arguments (given 0, expected 1)

I'm trying to write a mailer test using RSpec. However, it is failing and I cannot figure out why. My failure notification is the following:

Failures:

  1) UserMailer welcome_email sends an email upon new user registration
     Failure/Error:
       def welcome_email(id)
         @user = User.find(id)
         mail(to: @user.email, subject: 'Welcome on board!')
       end

     ArgumentError:
       wrong number of arguments (given 0, expected 1)
     # ./app/mailers/user_mailer.rb:4:in `welcome_email'
     # ./spec/mailers/user_mailer_spec.rb:10:in `block (3 levels) in <top (required)>'

The relevant code in the file I'm testing is the following:

class UserMailer < ApplicationMailer
  default from: '[email protected]'

  def welcome_email(id)
    @user = User.find(id)
    mail(to: @user.email, subject: 'Welcome on board!')
  end
end

And this is my spec:

require "rails_helper"


RSpec.describe UserMailer, :type => :mailer do
  describe "welcome_email" do
    let(:mail) { UserMailer.welcome_email }

    it 'sends an email upon new user registration' do
      expect(mail.subject).to eq('Welcome on board!')
    end   
  end
end

I have tried all suggestions for this error I could find elsewhere to no avail. What am I doing wrong?

Upvotes: 0

Views: 1522

Answers (1)

Ursus
Ursus

Reputation: 30056

Your method welcome_email takes one parameter but you are not passing nothing here

let(:mail) { UserMailer.welcome_email }

Upvotes: 2

Related Questions