lundi 30 novembre 2015

rails 3 functional test create error

I am new to functional testing in Rails and I cannot figure out why the test of a controller create method that I describe below fails.

I am getting the following error:

ruby -Itest test/functional/sellers_controller_test.rb 
Run options: 

# Running tests:

F.....F

Finished tests in 3.689409s, 1.8973 tests/s, 2.4394 assertions/s.

  1) Failure:
test_should_create_seller(SellersControllerTest) [test/functional/sellers_controller_test.rb:20]:
"Seller.count" didn't change by 1.
<3> expected but was
<2>.

  2) Failure:
test_should_update_seller(SellersControllerTest) [test/functional/sellers_controller_test.rb:39]:
Expected response to be a <:redirect>, but was <200>

7 tests, 9 assertions, 2 failures, 0 errors, 0 skips

I am testing "sellers_controller.rb". Here is my create method:

  def create
    @seller = Seller.new(params[:seller])
    respond_to do |format|
      if @seller.save
        format.html { redirect_to(@seller, :notice => 'Seller was successfully created.') }
        format.xml  { render :xml => @seller, :status => :created, :location => @seller }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @seller.errors, :status => :unprocessable_entity }
      end
    end
  end

in my test file "sellers_controller_test.rb" I have the following:

  setup do
    @seller = sellers(:one)
  end

and

  test "should create seller" do
    assert_difference('Seller.count') do
      post :create, :seller => @seller.attributes
    end

    assert_redirected_to seller_path(assigns(:seller))
  end

Here is my fixture file sellers.yml

one:
  name: MyString1
  website: MyString1
  email: Email1

two:
  name: MyString
  website: MyString
  email: Email2

Aucun commentaire:

Enregistrer un commentaire