Jump to content

The ultimate community for Ruby on Rails developers.


Photo

Failure/Error: expect(flash[:notice]).to eq("Something")

rspec

  • Please log in to reply
2 replies to this topic

#1 dailammoc

dailammoc

    Dispatcher

  • Members
  • 38 posts
  • Location/

Posted 21 April 2014 - 08:25 AM

I have the rspec codes like this:

require "spec_helper"

describe ProductsController do
  describe "POST #import" do
    it "redirects to the home page" do
      allow(Hotel).to receive(:import).with("foo.txt")
      post :import, file: "foo.txt"
      expect(response).to redirect_to root_url
    end

    it "adds a flash notice" do
      allow(Hotel).to receive(:import).with("foo.txt")
      post :import, file: "foo.txt"
      expect(flash[:notice]).to eq "Product was successfully imported."
    end

    it "imports the hotel file" do
      expect(Hotel).to receive(:import).with("foo.txt")
      post :import, file: "foo.txt"
    end
  end
end

When I run test, I got the error here:

Failures:

  1) CrudsController POST import adds a flash notice
     Failure/Error: expect(flash[:notice]).to eq "Product was successfully imported."
       
       expected: "Product was successfully imported."
            got: "Product was successfully Imported."
       
       (compared using ==)
     # ./spec/controllers/cruds_controller_spec.rb:161:in `block (3 levels) in <top (required)>'

I searched google, but still didn't solve this problem, please help me.



#2 Ohm

Ohm

    Driver

  • Moderators
  • 398 posts
  • LocationCopenhagen

Posted 24 April 2014 - 10:48 AM

It might be a case of weird white-space characters. Can you try and delete every space in both strings and replace them with new spaces?


Blog: http://ohm.sh | Twitter: @madsohm

#3 dailammoc

dailammoc

    Dispatcher

  • Members
  • 38 posts
  • Location/

Posted 02 May 2014 - 03:18 AM

It might be a case of weird white-space characters. Can you try and delete every space in both strings and replace them with new spaces?

I found the problem with the word "imported" instead of "Imported" (uper case), so they did match together.







Also tagged with one or more of these keywords: rspec

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users