Hi, welcome to Word of Mike, my little corner of the internet. I am a Software/Web Developer working in North Yorkshire. I mainly write about programming but my other passion is politics so beware. (click to hide)

2014-05-07 11:30:34 UTC

Unusual Error with ActiveSupport::TestCase

I spent a significant amount of time trying to work out why I couldn't use the declarative style for defining tests in Rails and MiniTest. Given the following test definition (with default test_helper.rb):

require 'test_helper'

class FooTest < ActiveSupport::TestCase
  test "foo" do

I kept getting:

mbp4:myapp mike.campbell$ rake test:models
rake aborted!
unknown command 'f'
/Users/mike.campbell/projects/myapp/test/models/student_test.rb:4:in `test'

The letter was whatever the first letter of my test description was. It was clear the `test` method wasn't being defined correctly, but I couldn't figure out why, until I looked at the method definition:

unless defined?(Spec)
  def test(name, &block)
    # ...

Ack, the method wasn't being defined because Spec was defined. Indeed, I had rspec-rails in my bundle. I find it kind of odd that Rails would make such a check, but never-the-less, mystery solved.