Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error when trying to run a minitest unit test

Tags:

ruby

minitest

I get the following error when trying to run a minitest unit test with ruby test/test_foo.rb:

Warning: you should require 'minitest/autorun' instead.
Warning: or add 'gem "minitest"' before 'require "minitest/autorun"'
From:
  /home/emile/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/minitest/autorun.rb:15:```

test_foo.rb looks like this:

require 'minitest/autorun'

class TestFoo < MiniTest::Test
 #stuf
end

My Gemfile does contain gem 'minitest' and test_foo.rb does contain require 'minitest/autorun', yet I still get the warning.

Is this a bug? Any ideas?

like image 941
emilesilvis Avatar asked Jul 25 '13 09:07

emilesilvis


People also ask

How to setup Minitest?

Setting Up Minitest. To run a Minitest test, the only setup you really need is to require the autorun file at the beginning of a test file: require 'minitest/autorun' . This is good if you'd like to keep the code small. A better way to get started with Minitest is to have Bundler create a template project for you.

What is Minitest in Rails?

What is Minitest? Minitest is a testing suite for Ruby. It provides a complete suite of testing facilities supporting test-driven development (TDD), behavior-driven development (BDD), mocking, and benchmarking. It's small, fast, and it aims to make tests clean and readable.

What is Minitest?

Minitest is a testing tool for Ruby that provides a complete suite of testing facilities. It also supports behaviour-driven development, mocking and benchmarking. With the release of Ruby 1.9, it was added to Ruby's standard library, which increased its popularity.


2 Answers

Run your test using bundle exec ruby test/test_foo.rb to make sure you use your bundled gems (in this case minitest).

Just running ruby test/test_foo.rb will use your globally installed Rubygems.

If you want to dig around a little more, try looking in /home/emile/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/minitest/autorun.rb, around line 15.

like image 145
Frost Avatar answered Oct 11 '22 05:10

Frost


I've interepreted the warning literally and added the line gem 'minitest' before the line require 'minitest/autorun', and that seems to work. Odd, or is this expected?

This is expected. It tells ruby to use the gem version and not the standard library version.

like image 39
blowmage Avatar answered Oct 11 '22 05:10

blowmage