Getting Started with MiniTest and Rails

Viewed 4421

I want to switch an existing rails application from rspec to minitest starting with the models. Therefore I created a folder test. Inside there I created a file named minitest_helper.rb with the following content:

require "minitest/autorun"

ENV["RAILS_ENV"] = "test"

and the folder models containing forum_spec.rb:

require "minitest_helper"

describe "one is really one" do
  before do
    @one = 1
  end

  it "must be one" do
    @one.must_equal 1
  end
end

Now I can run ruby -Itest test/models/forum_spec.rb with the following result:

Loaded suite test/models/forum_spec
Started
.
Finished in 0.000553 seconds.

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

Test run options: --seed 12523

That's nice. But now I want the environment to be loaded and I add the following line to minitest_helper.rb (copied from the equivalent file from rspec):

require File.expand_path("../../config/environment", __FILE__)

Now I run it again with the following result:

Loaded suite test/models/forum_spec
Started

Finished in 0.001257 seconds.

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

Test run options: --seed 57545

The Tests and assertions are gone. What could be the reason for that?

System Info:

  • ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.8.0]
  • Rails 3.1.0.rc4
1 Answers
Related