Posts Tagged ‘testing’

Migration support almost there.

Thursday, April 10th, 2008

Now that I’m back on track with DataMapper, I’ve got migration support for both it and ActiveRecord just about done. In addition to the actual rake task, db:migrate (btw), I had to set up a good way to test rake tasks, something I’ll share at a later date, but needless to say it’s included with Mack. I also had to deal with the pain in the ass-ness of dealing with two VERY different ORMs, in the same test system! Let me tell you, that sucked!

Good news is that things seem to be working, at least going in the ‘up’ direction anyway. I still need to write the ‘down’ direction revert stuff. Hopefully, that shouldn’t take too long now that I have a good way of testing the task and the migration stuff.

Unfortunately, I feel as though as soon as I release this stuff, which should be by the end of this weekend, DataMapper 0.9.0 will be out, and I’ll have to re-write most of the DataMapper stuff because the API is changing so radically. I guess I’ll just have to deal with that when the time comes.

In the meantime I’ll let y’all know when migrations are done and out there in the wild.

My thoughts on spec tests

Wednesday, April 9th, 2008

I’ve been asked by people why I’m not using spec tests to test Mack. I’m currently using just plain old regular unit tests for my tests. It’s a good question, but not really a valid one, I think. Should it matter what type of tests I’m using as long as I’m testing? Tests are tests. The framework you use to do your tests is moot as long as the tests you write are good, solid tests.

I jumped on the spec test bandwagon about a year or so ago. I forced my whole team to start writing in nothing but spec tests. The team, is still not impressed. If I were to tell them we weren’t using spec tests anymore, they would be EXTREMELY happy with that.Spec tests are certainly prettier than ‘regular’ tests. I’ll give you that. They are more ‘human readable’. With that said I find assert_equal to be fairly easy to read.

So why do I use regular tests, and not spec tests? A couple of reasons. First, they’re there and built right in to Ruby, ready to go, no new gems or syntax to learn. They’re fast. They are faster than spec tests. I see it everyday at work. I can also, and this one is HUGE, run just a single test or a regex’d series of tests. I really love that last bit. I have yet to find a way to do that, easily, with spec tests.

Again, how people write tests doesn’t really matter so much to me, it’s just that they write them. Testing is too easy in Ruby, there’s just no reason for not writing them.

Release 0.4.1

Thursday, March 27th, 2008

On the heels of yesterdays release of 0.4.0, there is a new release today, 0.4.1. Although this is not a sexy release, as 0.4.0 was, this is an important release.

What makes this release so important is that it fixes, adds, or improves testing support for Mack applications.

The implementation of some of the testing stuff has changed under the covers, but it’s the new stuff that is really important. let’s take a look at some of the stuff:

  • assigns(key) – This one should be familiar to all you Rails folks out there. This allows you to get an instance variable that was set in a controller, and access it in your test.
    def test_something
      get foo_index_url
      assert_not_nil assigns(:foo_list)
    end
  • in_session – This methods allows you to wrap a block in the context of a session. This is great if you’re trying to do integration testing.
  • set_cookie, remove_cookie – These methods allow you to either set or a remove a cookie in your tests. Great if you want to test an action that reads a cookie, or test to see what happens if you set a cookie, then remove the cookie and call something else. Also great to use with the in_session method.

There are a few other hidden treats in there, but those are some of the highlights. These things help bring Mack testing to a usable level.

The Mack Demo Blog application has been updated to demonstrate some these things. You can pull the demo using Git here: git://github.com/markbates/mack_blog_demo.git

Changelog:

  • Improved testing support.
  • Added assigns support to testing. This is allows for pulling instance variables that were set in a controller to tests.
  • Added ability to do ’session’ based tests.
  • Added assert_difference method.
  • Added ability to set/remove cookies before requests are made.
  • gem: mack_ruby_core_extensions 0.1.4
$ sudo gem install mack