- Add these gems to your
Gemfile
:
# frozen_string_literal: true
group :development, :test do
gem 'minitest'
gem 'rake'
gem 'simplecov'
end
-
Run
bundle install
to install them. -
Create a
test/test_helper.rb
file containing:
# frozen_string_literal: true
require 'simplecov'
SimpleCov.start do
enable_coverage :branch
end
$LOAD_PATH.unshift File.expand_path('../lib', __dir__)
require 'minitest/autorun'
- Add the following lines to your
Rakefile
:
# frozen_string_literal: true
require 'rake/testtask'
Rake::TestTask.new(:test) do |t|
t.libs << 'test'
t.libs << 'lib'
t.test_files = FileList['test/**/*_test.rb']
end
- Create a sample test at
test/unit/trial_test.rb
to try it out:
# frozen_string_literal: true
require 'test_helper'
describe 'trial' do
it 'is worthy' do
assert(true)
end
end
-
Run the tests with
bundle exec rake test
-
Learn to use the tools:
Name | Link |
---|---|
Minitest | https://github.com/seattlerb/minitest |
Rake | https://github.com/ruby/rake |
Simplecov | https://github.com/simplecov-ruby/simplecov |