Getting Started
This guide creates a small test scaffold and runs it with Smartest.
Requirements
Smartest is a Ruby test runner. The current development version is tested with Ruby 3.3.
Installation
Add Smartest to your application's Gemfile:
gem "smartest"
Then install it:
bundle install
Or install it directly:
gem install smartest
Create a Test File
Initialize a test scaffold:
bundle exec smartest --init
This creates smartest/test_helper.rb, smartest/fixtures/,
smartest/matchers/, and smartest/matchers/predicate_matcher.rb:
require "smartest/autorun"
Dir[File.join(__dir__, "fixtures", "**", "*.rb")].sort.each do |fixture_file|
require fixture_file
end
Dir[File.join(__dir__, "matchers", "**", "*.rb")].sort.each do |matcher_file|
require matcher_file
end
around_suite do |suite|
use_matcher PredicateMatcher
suite.run
end
It also creates smartest/example_test.rb:
require "test_helper"
test("example") do
expect(1 + 1).to eq(2)
end
The smartest CLI adds smartest/ to Ruby's load path before loading test files,
so require "test_helper" works directly.
The generated helper loads every Ruby file under smartest/fixtures/ and
smartest/matchers/ in sorted order, so test files do not need individual
fixture or matcher file requires.
smartest/autorun in the helper does two things:
- makes the top-level
test,around_suite, andaround_testDSL available - runs the registered tests when Ruby exits
use_fixture and use_matcher are available inside around_suite and
around_test blocks, not as top-level methods.
Run the Test
bundle exec smartest
Expected output:
Running 1 test
✓ example
1 test, 1 passed, 0 failed
Next Steps
Continue with Writing Tests to learn how to structure tests and assertions, then read Fixtures when a test needs setup data or external resources.