These are the scripts that I used to migrate from RSpec to Minitest in a Rails aplication.
It is expected for the test suite to be in RSpec 3.x sintax.
- Install
rename
library from Homebrew - Remove RSpec/TestUnit from Gemfile
- Add
minitest-rails
gem - Rename
spec
forder totest
- Add a
test_helper.rb
file
ENV["RAILS_ENV"] = "test"
require File.expand_path("../../config/environment", __FILE__)
require "rails/test_help"
require "minitest/rails"
# To add Capybara feature tests add `gem "minitest-rails-capybara"`
# to the test group in the Gemfile and uncomment the following:
# require "minitest/rails/capybara"
# Uncomment for awesome colorful output
# require "minitest/pride"
Dir[Rails.root.join("test/support/**/*.rb")].each { |file| require file }
module ActiveSupport
class TestCase
# Setup all fixtures in test/fixtures/*.yml for all tests in
# alphabetical order.
fixtures :all
# Add more helper methods to be used by all tests here...
end
end
- Rename all
spec
files with
find . -name *_spec.rb -exec rename 's|_spec|_test|' {} \;
- Change sintax to Minitest
find . -name '*_test.rb' -exec sed -ie 's/context/describe/g' {} \;
find . -name '*_test.rb' -exec sed -ie 's/stub(/stubs(/g' {} \;
find . -name '*_test.rb' -exec sed -ie 's/double/stub/g' {} \;
find . -name '*_test.rb' -exec sed -ie 's/should_receive/expects/g' {} \;
find . -name '*_test.rb' -exec sed -ie 's/and_return/returns/g' {} \;
find . -name '*_test.rb' -exec sed -ie 's/expect(//g' {} \;
find . -name '*_test.rb' -exec sed -ie 's/).to be ==/.must_equal/g' {} \;
find . -name '*_test.rb' -exec sed -ie 's/).to eq/.must_equal/g' {} \;
find . -name '*_test.rb' -exec sed -ie 's/).to be_empty/.must_be_empty/g' {} \;
find . -name '*_test.rb' -exec sed -ie 's/).to_not be_empty/.wont_be_empty/g' {} \;
find . -name '*_test.rb' -exec sed -ie 's/).to be_kind_of/.must_be_kind_of/g' {} \;
find . -name '*_test.rb' -exec sed -ie ’s/(response).to have_http_status/.must_respond_with/g’ {} \;
find . -name '*_test.rb' -exec sed -ie 's/).to redirect_to/.must_redirect_to/g' {} \;
find . -name '*_test.rb' -exec sed -ie 's/RSpec.//g' {} \;
find . -name '*_test.rb' -exec sed -ie 's/).to match/.must_match/g' {} \;
- Integration tests name muest end with
Integration Test