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
Op dinsdag 16 december 2014 10:50:05 UTC+1 schreef Ester Ytterbrink:
> You miss a do after it "populates a array containing that
> product", it that just a copy-paste error or the code you are running?
> /Ester
>
> On Tuesday, December 16, 2014 10:20:12 AM UTC+1, Roelof Wobben wrote:
>>
>> Yep
>>
>> Op dinsdag 16 december 2014 09:20:57 UTC+1 schreef Myron Marston:
>>>
>>> On Friday, December 12, 2014 11:53:19 AM UTC-8, Roelof Wobben wrote:
>>>>
>>>> The create command is from FactoryGirl.
>>>>
>>>> And on the spec_helper.rb I have this :
>>>>
>>>> config.include FactoryGirl::Syntax::Methods
>>>>
>>>> and on the model testing that was enough.
>>>>
>>>> There I used it like this :
>>>>
>>>> it "is valid with a productname, description and a image_url " do
>>>> expect(create(:product)).to be_valid
>>>> end
>>>>
>>>> Roelof
>>>>
>>>
>>> Are you requiring `spec_helper.rb` from your controller spec?
>>>
>>
>
>
--
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/1415ee7e-a77d-4aaa-916a-8fe74b7f810c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.