Forum: Ruby on Rails error with test:functionals

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
989ede72360673185ee0fb04f507d65b?d=identicon&s=25 Luciano (Guest)
on 2009-04-30 16:19
(Received via mailing list)
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:in `each_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:in `each_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:in
`test_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:in
`run']:
<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
5f94b9b346c2aa648a80bc259978e5bc?d=identicon&s=25 Colin Law (Guest)
on 2009-04-30 18:08
(Received via mailing list)
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 <bonachela@gmail.com>
This topic is locked and can not be replied to.