/  2
 
Notes on: Fixtures – Friend or Foegiven by Tom Preston-Werner1.Fixture help you make test data1.simple conceptually2.done in YAML (can be other formats)3.fixtures :users (simply and rails-y)2.Fixtures become a nightmare1.(shows code with lots of fixtures specified in top of test that represent 1/5 of tables)2.“Fixtures suck” 3.half the Rails core team did not use fixtures as of last RailsConf064.fixtures are a problem3.Why do they suck?1.swampy (shows photo of swamp with trees with bad smells with stink-lines)2.fixtures become an unmanageable mess3.hard to keep track of links between data4.things aren't easy to refactor5.no namespacing – i.e. you need to have lots of users in different states for good testing6.brittleness – one day you add a new column to a table, and half of your tests fail7.no validation – there is no automatic way for ActiveRecord validation for fixture data8.contamination – tests pass independently, but fail when running all at once9.performance – fixtures can be slow4.Lots and Lots of documentation1.you can maintain a lot of documentation in your fixture files2.you know where to use which fixtures in which tests3.helps with brittleness4.not ideal5.Use ActiveRecord1.create your objects using ActiveRecord to populate your database2.ActiveRecord keeps associations intact3.many people do this with helper methods to set up before running the tests4.still complexity of knowing when to use what5.lose out on transactional fixtures6.also not ideal6.Mocks and Stubs1.cuts off the database2.Mocha is a good mock plugin3.all you are interested in is that you are returning the right thing, you don't care if it'scoming from the database7.In-memory database1.different databases – seems bad (i.e. mysql on production, but sqlite in memory)2.helps for performance3.probably bad8.Transactional Fixtures1.each test method rollsback to pre-loaded state2.on by default, you are probably already using them9.Rails Edge – Preloads all Fixtures1.just load everything2.you have to be using transactional fixtures if you're doing this3.helps with fixture contamination4.removes the need to specify a bunch of fixtures for each test10.Fixtures are easy1.Tom's solution: FixtureScenarios2.http://code.google.com/p/fixture-scenarios3.organized fixtures ... like a palm tree, not a swamp

Share & Embed

More from this user

Add a Comment

Characters: ...