Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8069177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:56:15+00:00 2026-06-05T12:56:15+00:00

Currently in my controller spec I have: require ‘spec_helper’ describe CustomerTicketsController do login_user describe

  • 0

Currently in my controller spec I have:

require 'spec_helper'

describe CustomerTicketsController do
  login_user

  describe "POST /create (#create)" do
    # include EmailSpec::Helpers
    # include EmailSpec::Matchers
    it "should deliver the sales alert email" do
      # expect
      customer_ticket_attributes = FactoryGirl.attributes_for(:customer_ticket)
      customer_mailer = mock(CustomerMailer)
      customer_mailer.should_receive(:deliver).
        with(CustomerTicket.new(customer_ticket_attributes))
      # when
      post :create, :customer_ticket => customer_ticket_attributes
    end
  end
end

In my controller I have:

  # POST /customer_tickets
  # POST /customer_tickets.xml
  def create
    respond_to do |format|
      if @customer_ticket.save
        CustomerMailer.sales_alert(@customer_ticket).deliver
        format.html { redirect_to @customer_ticket, notice: 'Customer ticket was successfully created.' }
        format.xml { render xml: @customer_ticket, status: :created, location: @customer_ticket }
      else
        format.html { render action: "new" }
        format.xml { render xml: @customer_ticket.errors, status: :unprocessable_entity }
      end
    end
  end

My test currently produces the following output:

Failures:

  1) CustomerTicketsController POST /create (#create) should deliver the sales alert email
     Failure/Error: customer_mailer.should_receive(:deliver).
       (Mock CustomerMailer).deliver(#<CustomerTicket id: nil, first_name: "firstname1", last_name: "lastname1", company: nil, referral: nil, email: "firstname1@example.com", phone: "555-5555", fax: nil, country: nil, address1: "555 Rodeo Dr.", address2: nil, city: "Beverly Hills", state: "CA", postcode: "90210", question: "The answer to the universe is 4.", type: nil, status: nil, priority: nil, number: nil, cs_rep_id: nil, created_at: nil, updated_at: nil>)
           expected: 1 time
           received: 0 times
     # ./spec/controllers/customer_ticket_controller_spec.rb:13:in `block (3 levels) in <top (required)>'

Finished in 0.52133 seconds
1 example, 1 failure

Failed examples:

rspec ./spec/controllers/customer_ticket_controller_spec.rb:9 # CustomerTicketsController POST /create (#create) should deliver the sales alert email

Thank you for looking.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T12:56:17+00:00Added an answer on June 5, 2026 at 12:56 pm

    You could check the ActionMailer::Base.deliveries.count to ensure it has incremented by 1.

    Something like this (untested)

    expect {custom_mailer.deliver}.to change { ActionMailer::Base.deliveries.count }.by(1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why is it that this request spec works as it should: require spec_helper describe
currently in my update controller method I have: @group.attributes = { :title => params[:group][:title],
I currently have the following controller method in a Rails app: def index @entries
I'm currently trying to post a JSON object from my view to my controller
I currently have url like localhost/zend_practice/countries/index?data=1 where countries is the name of my controller
Here is my current users_controller_spec.rb file require 'spec_helper' describe UsersController do render_views . .
I currently have a controller method that returns a JsonResult: public JsonResult EditField(int FieldID,
I have an mvc intranet application using windows authentication. It currently has one controller
I believe I have some problem with scoping. I have a controller spec file
Currently my controller lets a user submit muliple links at a time. It collects

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.