On Tuesday, December 16, 2014 5:27:59 AM UTC-8, Roelof Wobben wrote: > > > Thanks, > > I have now this : > > require "spec_helper" > describe ProductsController do > > describe "GET #index" do > > context "with params[:product]", :type => :controller do > > it "populates a array containing that product" do > product = create(:product, title: "Book 1") > get :index , product: "Book 1" > expect(assigns(:product)).to match_array(["Book 1"]) > end > > > end > end > end > > But I see this error message : > > > 1) ProductsController GET #index with params[:product] populates a array > containing that product > > Failure/Error: expect(assigns(:product)).to match_array(["Book 1"]) > > > > expected a collection that can be converted to an array with `#to_ary` or > `#to_a`, but got nil > > > # ./spec/controllers/products_controller_spec.rb:12:in `block (4 levels) in > <top (required)>' > > > > Roelof >
The failure message indicates that `assigns(:product)` returned `nil`, and thus can't be converted to an array for comparison with `["Book 1"]`. We're happy to help here on the mailing list with general questions about how RSpec works and how to use it well, but we don't have the capacity to help you through each step of building and testing your application. If you need more in-depth help with your application, I'm available on code mentor for paid sessions: https://www.codementor.io/myronmarston -- You received this message because you are subscribed to the Google Groups "rspec" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/a5e8836d-6e31-405b-87da-b24594fb6821%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
