7

Migrate from Rspec to Minitest with Rails

 3 years ago
source link: https://mednoter.com/migrate-from-rspec-to-minitest.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Migrate from Rspec to Minitest with Rails

New Rspec has released, with lots of DSL changes. Every rspecer is painfull. ^_^

Minitest is so lightweight, cute and simple. Why was I so stuip to choose Rspec?

This article will show you how to migrate from rspec to minitest.

Gemfile

Add ‘minitest_rails’ and ‘mocha’ to gemfile

# Rails4 use minitest as default testing framework, if your rails version is greater than 4.0, you can skip this step.
gem "minitest"
gem "minitest-rails"

MiniTest::Mock is not so power, we use Mocha instead.

gem "mocha", :require => false

Gem Turn is great way to view test results. you can see exact result of every test (Success, Faiure and Why).

gem "turn", :require => false

test_helper.rb

  1. After installed ‘minitest-rails’, you can run rails generate minitest:install to add test_helper.rb to the test directory.

  2. require

require "minitest/autorun"
require "minitest/rails"
require "mocha/setup"

FactoryGirl

Don’t worry. Factory can find all the factories under spec/. old factories will be load when you run rake test. But you’d better put new factories into test/.

Rakefile

Add pattern in you Rakefile, additional testing tasks defined in “test/*/_test.rb” will be evaluated when you run Rake test

Rake::TestTask.new do |t|
  t.libs << "test"
  t.test_files = FileList['test/**/*_test.rb']
  t.verbose = true
end

Bingo, it works

run rake test

吕小荣
24 September 2014

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK