Forum: Ruby on Rails Defining fixtures in Unit Tests necessary?

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.
yachtman (Guest)
on 2009-03-26 02:28
(Received via mailing list)
Just sinking my teeth into tests and the going is tough.

Is it necessary to define fixtures in my test file
('fixtures :users')?

My test are working with the definition, but I decided to debug and
checked for the fixtures existence even without the definition and all
of them had been loaded. So what's the purpose of the declaration?
Phlip (Guest)
on 2009-03-26 04:09
(Received via mailing list)
yachtman wrote:

> Just sinking my teeth into tests and the going is tough.

Not as tough as debugging all night before a release. Stick with TDD and
you
will never look back!

> Is it necessary to define fixtures in my test file
> ('fixtures :users')?
>
> My test are working with the definition, but I decided to debug and
> checked for the fixtures existence even without the definition and all
> of them had been loaded. So what's the purpose of the declaration?

Of course they are there - you loaded them. However, consider this test
suite:

class SomeTests ...

    def test_aardvark
      screw_users_table_up()
      assert{ users_table_is_screwed_up() }
    end

    def test_zebra
      deny{ users_table_is_screwed_up() }
    end

end

The test case names force [the current version of] test/unit to run
those cases
in that order.

The second test will fail because the first one screwed the table up.

The 'fixtures :users' line means "please un-screw-up the users table
between
each test case". Adding it to my hypothetical test suite would "fix" it.

The fixture system enables "Test Isolation". You could run any test
case, in any
order, or not at all, and each one should not add any noise to the
signal from
any other.

--
   Phlip
yachtman (Guest)
on 2009-03-26 14:41
(Received via mailing list)
Phlip,

Well said. Hadn't thought of that possibility, that by declaring the
fixtures, it would reload them. Smart and makes sense.

Thanks!!
Frederick C. (Guest)
on 2009-03-26 15:44
(Received via mailing list)
On Mar 26, 12:27 am, yachtman <removed_email_address@domain.invalid> wrote:
> Is it necessary to define fixtures in my test file
> ('fixtures :users')?
>
> My test are working with the definition, but I decided to debug and
> checked for the fixtures existence even without the definition and all
> of them had been loaded. So what's the purpose of the declaration?

For a while rails apps (by default) have fixtures :all in their
test_helper.rb, which does pretty much what you would imagine.

Fred
Greg D. (Guest)
on 2009-03-26 21:25
(Received via mailing list)
On Thu, Mar 26, 2009 at 8:43 AM, Frederick C.
<removed_email_address@domain.invalid> wrote:
> For a while rails apps (by default) have fixtures :all in their
> test_helper.rb, which does pretty much what you would imagine.

When I moved an app from 2.2.2 to 2.3.2 a couple days ago, I was
prompted to remove the fixtures :all from my test_helper.rb,
deprecation warning if I recall correctly.  And then removing it broke
all my tests.  I had to put explicit fixture entries back into in all
my tests to get them working again.


--
Greg D.
http://destiney.com/
This topic is locked and can not be replied to.