ChiliProject is not maintained anymore. Please be advised that there will be no more updates.

We do not recommend that you setup new ChiliProject instances and we urge all existing users to migrate their data to a maintained system, e.g. Redmine. We will provide a migration script later. In the meantime, you can use the instructions by Christian Daehn.

Switch to rspec2+factory_girl with switch to rails 3.1

Added by Felix Schäfer at 2011-08-24 11:35 am

I'm aware I'm opening a can of worms here because of some strong feelings regarding tests suites, but I'd like to switch to rspec2 (+shoulda) and factory_girl instead of Test::Unit+shoulda and object_daddy.

  • To get that out the way: we use rspec2 and factory_girl at finnlabs. I know this is not an argument per se, but having parts of the contributors already (somewhat) accustomed to a framework should be considered too.
  • Regarding TU vs rspec: as shoulda is already in the background, it's mostly about the syntax. I like the rspec syntax better, because it's easier to read (and imho write) (context vs. describe, setup vs. before, it vs. nothing?) and brings some nice helpers (not sure how much of this is doable in TU though): the ability to the change the subject in a test block, compact syntax to test attributes/methods of the subject (its), differentiates between befores that should be run before each test and only once before all tests, has example groups, and so on. Last but not least: the memoized and lazy-loaded "let"s, which alleviates the need to put everything in instance variables, make sure you load only what you need, and so on.
  • Regarding OD vs FG: OD doesn't seem to be maintained anymore, and from the documentation I've seen we wouldn't lose anything going to FG, and I think even gain some flexibility.

I'd be willing to work on porting the current tests to rspec+FG, though that's nothing that would happen overnight.

Thoughts?


Replies (5)

RE: Switch to rspec2+factory_girl with switch to rails 3.1 - Added by Eric Davis at 2011-10-13 01:28 am

switching to rspec

I'm not interested at all. Even if we set aside syntax opinions, I don't see any benefits to rspec. Most of the problems in the current tests are because of bad testing practices, not because of T::U.

switching to factory_girl

I'm okay with that as long as there are wrappers for the existing methods (Model.generate). I like object_daddy because it's very simple and did a lot more than factory_girl when I evaluated it. factory_girl has since matured a lot but we should make sure the extra features are really worth switching.

shoulda

Over the past few years (or so) I've found a lot of edge case bugs and odd behavior. Frankly, I'm fine with removing it as long as we add in another context library. The macros will have to be ported but those can be converted into assertions easily.


In my opinion I would really like to try to use minitest. Test::Unit in 1.9 is actually built on top of it, it's pretty simple while having most of what we need, and has a bunch of new assertions we could really use to really clean things up (assert_output for SCM tests). It also has an optional spec syntax if you wanted to use that in plugins, thus getting the benefit of reusing core test helpers in your plugin. Or switch to T::U 2.0.

Eric Davis

RE: Switch to rspec2+factory_girl with switch to rails 3.1 - Added by Felix Schäfer at 2011-10-28 06:58 am

Eric Davis wrote:

switching to rspec

I'm not interested at all. Even if we set aside syntax opinions, I don't see any benefits to rspec. Most of the problems in the current tests are because of bad testing practices, not because of T::U.

It is a syntax opinion (to 98,5%) as rspec mostly is just a wrapper around T::U. I've not said anywhere either that it would solve any problems we have with the current tests: it clearly won't. The only thing we'd gain in the regard of the brokenness of the currents tests is that switching to rspec would mean rewriting them all, so we might be able to make them better in the process, but that's something we could do by "upgrading" everything to a consistent syntax too, so that's not my (main) point.

My main point still is: I think the expressiveness and syntax of rspec is better. If that's not something we should talk about, we could just scrap AR and go with plain SQL too.

switching to factory_girl

I'm okay with that as long as there are wrappers for the existing methods (Model.generate). I like object_daddy because it's very simple and did a lot more than factory_girl when I evaluated it. factory_girl has since matured a lot but we should make sure the extra features are really worth switching.

Again, the main point is not "factory_girl has more features" but "object_daddy seems pretty dead at the rails 3 game", and we shouldn't try to emulate it if we scrap it but scrap it good and convert what needs to be converted in the tests to adapt for the change. We can't be bitching about tying in external dependencies so deeply that vendored gems can't easily be unvendored and be afraid to take consequent (to not say drastic) action.

shoulda

Over the past few years (or so) I've found a lot of edge case bugs and odd behavior. Frankly, I'm fine with removing it as long as we add in another context library. The macros will have to be ported but those can be converted into assertions easily.

I don't think I've written I wanted to get rid of shoulda. If I did: I don't want to.

RE: Switch to rspec2+factory_girl with switch to rails 3.1 - Added by Eric Davis at 2011-10-28 05:28 pm

Felix Schäfer wrote:

The only thing we'd gain in the regard of the brokenness of the currents tests is that switching to rspec would mean rewriting them all, so we might be able to make them better in the process, but that's something we could do by "upgrading" everything to a consistent syntax too, so that's not my (main) point.

I agree with that point. The tests are poor quality and switching wouldn't fix that.

My main point still is: I think the expressiveness and syntax of rspec is better.

That's what I meant by a "syntax opinion." I find rspec's syntax worse than T::U. There isn't anything that can be done to change this, it's a personal opinion just like vi vs emacs.

If that's not something we should talk about, we could just scrap AR and go with plain SQL too.

Straw man argument. AR serves a different purpose than SQL. Rspec and T::U serve the same purpose.

Again, the main point is not "factory_girl has more features" but "object_daddy seems pretty dead at the rails 3 game", and we shouldn't try to emulate it if we scrap it but scrap it good and convert what needs to be converted in the tests to adapt for the change.

Are there any results or proof that object daddy doesn't work with Rails 3? It looks like it's not maintained because for most of Rails 2.x it just worked. It is simple code.

I don't think I've written I wanted to get rid of shoulda. If I did: I don't want to.

Your first post had "(+shoulda)" so I wanted to address it so it didn't feel left out. If you don't care then it's a moot point and we can agree to leave it alone for this discussion.

Eric Davis

RE: Switch to rspec2+factory_girl with switch to rails 3.1 - Added by Felix Schäfer at 2011-11-29 08:42 am

Just a quick note on this: I took a (fleeting) look at MiniTest and I could probably live with it (at least the spec syntax). In fact, the 1-to-1 relationship from "specs" to "actual generated methods" (sounds more awful than it is…) might make it easier to override/deactivate core tests from within plugins (wrt. rspec, T::U probably isn't such a pita to override…).

More on this once I've had the chance to play around with MiniTest.

RE: Switch to rspec2+factory_girl with switch to rails 3.1 - Added by Robert Mitwicki at 2012-03-27 09:50 am

There is also one thing which we should also consider: test speed.

There is a lot of tools which are faster then standard solutions and we could also use this one argument to choose which one to use.
I hope that You will consider also that ;)

(1-5/5)