everydayrails / rails-4-1-rspec-3-0

Code samples for Everyday Rails Testing with RSpec, Rails 4.1/RSpec 3.0 edition
272 stars 229 forks source link

Chapter 5 Testing Controllers #75

Closed eaglerockdude closed 7 years ago

eaglerockdude commented 7 years ago

On testing the Get Index I am getting an error: Failures:

1) ContactsController GET #index with params[:letter] populates an array of contacts starting with params[:letter] Failure/Error: expect(assigns(:contacts)).to match_array(['smith']) **expected collection contained: ["smith"] 01:54:50">] the missing elements were: ["smith"] the extra elements were: [#<Contact id: 980190963, firstname: "Alexzander", lastname: "Smith", email: "rosie@weber.biz", created_at: "2016-12-18 01:54:50", updated_at: "2016-12-18 01:54:50">]

./spec/controllers/contacts_controller_spec.rb:13:in `block (4 levels) in <top (required)>'

My code is as in the book:

it 'populates an array of contacts starting with params[:letter]' do smith = create(:contact, lastname: 'Smith') jones = create(:contact, lastname: 'Jones') get :index, letter:'S' expect(assigns(:contacts)).to match_array(['smith']) end

eaglerockdude commented 7 years ago

expect(assigns(:contacts)).to match_array([smith])

Nevermind...i had (['smith']) with smith in quotes...took them out.