2
votes

EDIT: The problem was that we were still using rspec, and you cannot use the spec DSL in minitest while still using rspec.

I'm using minitest 4.7 with rails 4.0 and autotest-rails 4.2.1, and it has been great with tests that resemble test::unit. However, I've been trying to get it to run specs in the style of rspec, and neither autotest nor rake test:models has detected any of the specs.

Here's the output (with gratuitous warnings removed) when I update rating_test.rb:

/opt/boxen/rbenv/versions/2.0.0-p247/bin/ruby -I.:lib:test -rubygems -e "%w[minitest/autorun test/models/rating_test.rb].each { |f| require f }"
Run options: --seed 28285

# Running tests:



Finished tests in 0.003822s, 0.0000 tests/s, 0.0000 assertions/s.

0 tests, 0 assertions, 0 failures, 0 errors, 0 skips

It says that there is nothing. Here is rating_test.rb:

require 'test_helper'

describe Rating do
  let(:rating) {Rating.new(score: score, category: category)}
  let(:score) { 100 }
  let(:category) {Rating.categories[0]}

  describe "score" do
    it "can be 100" do
      puts "this doesn't show up"
      rating.valid?.should == true
      assert_equal true, rating.valid?
    end
  end
end

As you can see, I tried both a simple puts (which doesn't show up) as well as both styles of assertions (neither of which are detected by autorun).

The only thing I'm not sure of is if my test_helper is correct. I created mine by cobbling together the Readme instructions and this article, which weirdly conflict since they are written by the same author.

Here's my test_helper.rb file.

ENV["RAILS_ENV"] = "test"
require File.expand_path("../../config/environment", __FILE__)
require "rails/test_help"
require "minitest/spec"

require "minitest-matchers"
require "email_spec"

class ActiveSupport::TestCase
  fixtures :all

  extend MiniTest::Spec::DSL
  register_spec_type self do |desc|
    desc < ActiveRecord::Base if desc.is_a? Class
  end
end
1

1 Answers

1
votes

The problem was that we were still using rspec, and you cannot use the spec DSL in minitest while still using rspec.