Error with test:functionals


#1

Hello there,

I working on my tests but I getting this strange errror:

I can see on the database that the object was created but I still got
an failure on my test.

this is my test code:

test “should create artist” do
assert_difference(‘Artist.count’, difference = 1) do
post :create, :artist => { }
end
assert_redirected_to artist_path(assigns(:artist))
end

and this is my failure message:

  1. Failure:
    test_should_create_artist(ArtistsControllerTest)
    [/Users/bonacode/Desktop/arteacesso-br/arteacesso/vendor/rails/
    activesupport/lib/active_support/testing/core_ext/test/unit/
    assertions.rb:51:in assert_difference' (eval):3:ineach_with_index’
    /Users/bonacode/Desktop/arteacesso-br/arteacesso/vendor/rails/
    activesupport/lib/active_support/testing/core_ext/test/unit/
    assertions.rb:47:in each' /Users/bonacode/Desktop/arteacesso-br/arteacesso/vendor/rails/ activesupport/lib/active_support/testing/core_ext/test/unit/ assertions.rb:47:ineach_with_index’
    /Users/bonacode/Desktop/arteacesso-br/arteacesso/vendor/rails/
    activesupport/lib/active_support/testing/core_ext/test/unit/
    assertions.rb:47:in assert_difference' ./test/functional/artists_controller_test.rb:16:intest_should_create_artist’
    /Users/bonacode/Desktop/arteacesso-br/arteacesso/vendor/rails/
    activesupport/lib/active_support/testing/setup_and_teardown.rb:60:in
    __send__' /Users/bonacode/Desktop/arteacesso-br/arteacesso/vendor/rails/ activesupport/lib/active_support/testing/setup_and_teardown.rb:60:inrun’]:
    <Artist.count> was the expression that failed.
    <2> expected but was
    <1>.

I checking the database and my use was created, I just dont’t
understand why is it expecting 2 if there’s only one on my fixture…

thanks for any help!

Luciano


#2

I think that the message is saying that the value of Artist.count after
the
create is 1 when it should be 2, rather than the expected difference
being
2, though I am not sure whether this is what you are confused about or
not.

By the way,
assert_difference(‘Artist.count’, 1) do
may be what you want, though I don’t think that will make any difference
to
the result.

2009/4/30 Luciano removed_email_address@domain.invalid