سؤال

Is it possible and does anyone have experience using minitest and rspec? I'm just wondering if it's possible to slowly migrate from one to the other and have both get along in the mean time.

I tried setting up some minitest tests in an rspec project and it's just failing silently at this point. I've even removed the rspec-rails gem but still

rake test my/test/file.rb

just silently returns.

هل كانت مفيدة؟

المحلول

I just revisited this and it seems like Rspec and Minitest work fine together "out of the box" without needing minitest-rails.

I'm not however using minitest/spec so I don't know about how that would integrate.

My issue was that the project in question was explicitly setting up individual railties in config/application.rb just to exclude "rails/test_unit/railtie" which is great if you just want rspec.

I put it back to the default

require 'rails/all'

and now both rspec specs run with

rake spec

and minitest tests run with

rake test

I wanted both to run buy default with just

rake

So I put this in my Rakefile

Rake::Task["default"].clear if Rake::Task.task_defined?("default")
task :default do
  puts "Starting specs"
  system('bundle exec rake spec')

  puts "Starting Minitest tests"
  system('bundle exec rake test')
end

نصائح أخرى

require 'rake/testtask'
require 'rspec/core/rake_task'

Rake::TestTask.new(:test) do |t| 
  t.pattern = 'test/**/*_test.rb'
end

RSpec::Core::RakeTask.new(:spec) do |t| 
  t.pattern = Dir.glob('spec/**/*_spec.rb')
  # t.rspec_opts = '--format documentation'
end

task default: [:test, :spec]

It should be possible to do that. Minitest is part of the standard library, so there should not be any conflicts.

If you want rake test to execute minitest, you will have to configure rails to use it. This might be useful for doing it: https://github.com/blowmage/minitest-rails

Otherwise you could just execute a test directly ruby -Itest test/unit/whatever_test.rb

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top