Niupiao / niupiao-market

1 stars 0 forks source link

Factories vs Fixtures #26

Open kevinmichaelchen opened 9 years ago

kevinmichaelchen commented 9 years ago

I've come to think that fixtures are evil. I normally git rm test/fixtures/*.yml since I tend to use Factory Girl or Fabrication. When you write tests, I find it nice to initialize test objects and their associations in the actual test file, usually in the setup method. Additionally, when you run a migration and change the columns in a table, for some reason, I've found that you immediately update your factory initialization, whereas fixtures go stale without you knowing until some time later.

However, take what I'm saying with a grain of salt, as fixtures have been known to be the choice for more complex applications, e.g., the Rails core team. This is because as an app grows, it becomes tougher to test various edge cases, since you have to construct various scenarios with objects that have all sorts of crazy associations. To see this, just look at the dozens of lines of object initialization in tickets_test.

rynkwn commented 9 years ago

Hmm. I'll read up on this Kevin!

kevinmichaelchen commented 9 years ago

@rynkwn If the Rails core team uses fixtures, then in my mind that definitely legitimizes fixtures. Maybe I was too harsh on fixtures...