Environment:
rails -v
Rails 4.2.5
ruby -v
ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-linux-gnu]
bundle list trailblazer
trailblazer-1.1.0
I am working through the examples in the Trailblazer book and I have run into a situation that I do not understand. Following the set up given in the book, when I run a specific test using bundle rake test/concerns/ar_invoice/crud_test.rb
it runs as expected. However, if I simply run bundle rake test
then I see this instead:
bundle rake test
rake aborted!
NameError: uninitialized constant MiniTest
./test/concepts/ar_invoice/crud_test.rb:1:in `<top (required)>'
./bundle/lib/gems/railties-4.2.5/lib/rails/test_unit/sub_test_task.rb:114:in `block (3 levels) in define'
./bundle /lib/gems/railties-4.2.5/lib/rails/test_unit/sub_test_task.rb:114:in `each'
./bundle/lib/gems/railties-4.2.5/lib/rails/test_unit/sub_test_task.rb:114:in `block (2 levels) in define'
./bundle/lib/gems/railties-4.2.5/lib/rails/test_unit/sub_test_task.rb:113:in `each'
./bundle/lib/gems/railties-4.2.5/lib/rails/test_unit/sub_test_task.rb:113:in `block in define'
./bundle/lib/gems/railties-4.2.5/lib/rails/test_unit/sub_test_task.rb:20:in `invoke_rake_task'
./bundle/lib/gems/railties-4.2.5/lib/rails/test_unit/testing.rake:8:in `block in <top (required)>'
Tasks: TOP => test:run
(See full trace by running task with --trace)
The file crud_test.rb contains this:
cat test/concepts/ar_invoice/crud_test.rb
class ARInvoiceCrudTest < MiniTest::Spec
describe( "Create" ) do
it( "persists valid" ) do
ar_invoice = ARInvoice::Create.(
:ar_invoice => { :invoice_number => 101,
:client_number => 1234
}
).model
ar_invoice.persisted?.must_equal( true )
ar_invoice.invoice_number.must_equal( 102 )
ar_invoice.client_number.must_equal( 5678 )
end
end
end
And .test/test_helper.rb looks like this:
cat test/test_helper.rb
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
require 'minitest/spec'
require "minitest/autorun"
require "trailblazer/rails/test/integration"
And env | grep RAILS_ENV
produces no output.
What else am I missing in the set-up? Should not running bundle rake test
simply pick up the crud_test.rb file and run the test identically to when the file is explicitly named on the command line?
This is the answer:
And of course, add require 'test_helper'
on top of every test file!