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/cc64b14e-7be9-44a9-8a20-5efaa92c830e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to