hi.
the #create is related to Factory Girl.
Try to explicitly call FactoryGirl.create(:plan)
bye,
enricostn
On Monday, November 12, 2012, ishi soichi wrote:
>
> my environment:
>
> Rails 3.1.3
> rspec-rails (2.11.4)
> rspec 2.11.1
>
>
> I have generated a scaffold named Plan. And I have not done RSpec tests
> for controllers at all.
>
>
> schema.rb
>
> create_table "plans", :force => true do |t|
> t.integer "give_take"
> t.integer "weight"
> t.boolean "check_in"
> t.datetime "created_at"
> t.datetime "updated_at"
> t.integer "flight_name_id"
> end
>
> plans_controller.rb
>
> def index
> @plans = Plan.all
>
> respond_to do |format|
> format.html # index.html.erb
> format.json { render json: @plans }
> end
> end
>
> spec/factories/plans.rb
>
> FactoryGirl.define do
> factory :plan do
> give_take 1
> weight 1
> check_in false
> flight_name_id 11
> end
> end
>
>
> plans_controller_spec.rb
>
> describe "GET index" do
> it "populates an array of plans" do
> plan = create(:plan) #######HERE!!!!!
> get :index
> assigns(:plans).should eq [plan]
> end
>
> it "renders the :index view" do
> get :index
> response.should render_template :index
> end
> end
>
>
> It raises a failure for index
>
> 2) PlansController GET index populates an array of plans
> Failure/Error: plan = create(:plan)
> NoMethodError:
> undefined method `create' for
> #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x000001037a8e70>
> # ./spec/controllers/plans_controller_spec.rb:45:in `block (3
> levels) in <top (required)>'
>
>
> Certainly I haven't defined method "create" anywhere except the one
> generated by scaffold, which is not shown here.
>
> How can I CREATE an instance here?
>
>
--
· Enrico Stano
·
· twitter @enricostano
· skype ocirneonats
_______________________________________________
rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users