Skip to content

trailblazer/trailblazer-test

Repository files navigation

Trailblazer::Test

Assertions and helpers for operation unit tests.

The comprehensive docs are here.

Read our introducing blog post for a better overview.

Installation

Add the following line to your project's Gemfile.

gem "trailblazer-test", ">= 1.0.0", "< 2.0.0"

Overview

This gem adds the following assertions and helpers:

  • #assert_pass to test an operation terminating with success.
  • #assert_fail to assert validation errors and the like.
  • #mock_step helping the replace steps with stubs.

Example

An example test case checking if an operation passed and created a model could look as follows.

# test/operation/memo_test.rb

require "test_helper"

class MemoOperationTest < Minitest::Spec
  Trailblazer::Test.module!(self) # install our helpers.

  it "passes with valid input" do
    # ...
    assert_pass Memo::Operation::Create, input,
      content:    "Stock up beer",
      persisted?: true,
      id:         ->(asserted:, **) { asserted.id > 0 }
  end
end

About

Super strong, non-verbose tests for your operations.

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages