Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 4: using MiniTest AND Rspec

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.

like image 445
kjs3 Avatar asked Jan 21 '14 22:01

kjs3


People also ask

Is Minitest better than RSpec?

RSpec has the same goals as Minitest but focuses on readable specifications describing how the application is supposed to behave with a close match to English. Minitest purports that if you know Ruby well, it should be enough. The RSpec project focuses on behavior-driven development (BDD) and specification writing.

What is Minitest in Ruby on rails?

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.

Is RSpec used for integration testing?

Stability can become an issue as web applications evolve and grow – integration tests provide a great way to perform end-to-end tests that validate the application is performing as expected.


1 Answers

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
like image 86
kjs3 Avatar answered Oct 22 '22 23:10

kjs3