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
Op vrijdag 12 december 2014 20:27:46 UTC+1 schreef Myron Marston:
>
> On Friday, December 12, 2014 5:24:40 AM UTC-8, Roelof Wobben wrote:
>>
>> Hello,
>>
>> I try to test my controller so I made this :"
>>
>> require "spec_helper"
>> describe ProductsController do
>>
>> describe "GET #index" do
>>
>> context "with params[:product]" do
>>
>> it "populates a array containing that product"
>> product = create(:product, title: "Book 1")
>> get :index , product: "Book 1"
>> expect(assigns(:product)).to match_array(["Book 1"])
>> end
>>
>> it "renders the :index view"
>> end
>>
>> end
>>
>> But as soon as I run rspec I see this error message ;
>>
>>
>> /home/codio/workspace/commerce-try/spec/controllers/products_controller_spec.rb:10:in
>> `block (3 levels) in <top (required)>': undefined method `create' for
>> #<Class:0x007
>> fa7da640148> (NoMethodError)
>>
>> Which I find wierd because on the model test spec I also use create and
>> there no error message
>>
>> Roelof
>>
>
> Where is the `create` method defined? It's not a method provided by rspec
> or rspec-rails, so there's something else in your environment defining it
> in model specs but not controller specs. If you want to see where the
> method comes from, in your model spec, before the call to `create`, add:
>
> puts method(:create).owner
> puts method(:create).source_location
>
> That should tell you what module has the definition of `create` and what
> the file and line number is where it is defined. Based on that, you can
> include that module in your controller example group to make it available
> there.
>
> Alternately, consider creating the product record using something like
> Product.create(...).
>
> HTH,
> Myron
>
--
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/74a8ce31-c078-4cb5-9805-33706581dcd9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.