Minitest base classes and assertion helpers for Trailblazer applications.
Trailblazer's own testing conventions (see trailblazer-test) write assertions actual-first — assert_equal result[:model].title, "Roxanne" — while stock Minitest expects expected-first. Mixing the two styles in one suite is a reliable source of confusing failure diffs. This gem gives you dedicated base classes to build your operation tests on, and an opt-in override that makes assert_equal read actual-first everywhere you choose to use it.
Add to your application's Gemfile (usually the :development, :test group):
gem "minitest-trailblazer"Or install directly:
gem install minitest-trailblazerSupports minitest 5.x and 6.x.
require "minitest-trailblazer"
class Song::Operation::CreateTest < Minitest::TrailblazerTest
def test_valid_input
result = Song::Operation::Create.(params: { title: "Roxanne" })
assert result.success?
end
endSpec-style is available too:
class Song::Operation::CreateSpec < Minitest::TrailblazerSpec
it "persists the model" do
result = Song::Operation::Create.(params: { title: "Roxanne" })
_(result[:model]).must_be :persisted?
end
endBoth classes include Minitest::Trailblazer::Assertions, the extension point where Trailblazer-specific assertions land.
Minitest::Trailblazer::AssertionsOverride flips assert_equal's argument order to (actual, expected):
class Song::Operation::CreateTest < Minitest::TrailblazerTest
include Minitest::Trailblazer::AssertionsOverride
def test_title
result = Song::Operation::Create.(params: { title: "Roxanne" })
assert_equal result[:model].title, "Roxanne" # actual first, Trailblazer-style
end
endIt is deliberately opt-in per test class: include it where your suite follows Trailblazer conventions, leave the rest of your tests untouched.
After checking out the repo, run bundle install, then bundle exec rake test.
Releases are cut by release-please from conventional commit messages (fix:, feat:) on master.
Bug reports and pull requests are welcome at https://github.com/seuros/minitest-trailblazer.
The gem is available as open source under the terms of the MIT License.