Minitest::Trailblazer

Minitest base classes and assertion helpers for Trailblazer applications.

Trailblazer's own testing conventions (see trailblazer-test) write assertions actual-firstassert_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.

Installation

Add to your application's Gemfile (usually the :development, :test group):

gem "minitest-trailblazer"

Or install directly:

gem install minitest-trailblazer

Supports minitest 5.x and 6.x.

Usage

Base classes

require "minitest-trailblazer"

class Song::Operation::CreateTest < Minitest::TrailblazerTest
  def test_valid_input
    result = Song::Operation::Create.(params: { title: "Roxanne" })

    assert result.success?
  end
end

Spec-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
end

Both classes include Minitest::Trailblazer::Assertions, the extension point where Trailblazer-specific assertions land.

Actual-first assert_equal

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
end

It is deliberately opt-in per test class: include it where your suite follows Trailblazer conventions, leave the rest of your tests untouched.

Development

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.

Contributing

Bug reports and pull requests are welcome at https://github.com/seuros/minitest-trailblazer.

License

The gem is available as open source under the terms of the MIT License.