The project is in a healthy, maintained state
An xUnit-style test framework for Spinel.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

Runtime

>= 1.3, < 2.0
 Project Readme

SpinelTest::Unit

An xUnit-style test framework for Spinel.

Installation

Add it to your Gemfile:

gem "spinel_test-unit"

Spinel itself is found through, in order: the SPINEL environment variable, spinel on PATH, mise which spinel.

Usage

# test/calc_test.rb
require "spinel_test/unit"
require "calc"

class CalcTest < SpinelTest::Unit::TestCase
  def setup
    @calc = Calc.new
  end

  def test_add
    assert @calc.add(1, 2) == 3
  end

  def test_failure_message
    assert @calc.add(1, 1) == 2, "1 + 1 should be 2"
  end
end
$ bundle exec spinel_test-unit                 # test/**/*_test.rb and test/**/test_*.rb
$ bundle exec spinel_test-unit test/calc_test.rb
$ bundle exec spinel_test-unit -n test_add     # only tests whose "Class#method" name includes it

Output:

..F

Failure: CalcTest#test_failure_message
1 + 1 should be 2

3 tests, 3 assertions, 1 failures, 0 errors

Available assertions:

  • assert(test, message = nil)
  • assert_equal(expected, actual, message = nil)
  • assert_nil(value, message = nil)
  • assert_includes(collection, item, message = nil)
  • assert_raise(klass) { ... } (passes for klass or a subclass; returns the exception; assertion failures raised inside the block propagate)

setup and teardown hooks are supported.

Constraints (from Spinel)

  • Test code must be compilable by Spinel: no send with dynamic names, define_method, instance_methods, etc. in tests or in the code under test.
  • Test classes must be defined as literal class FooTest < SpinelTest::Unit::TestCase (or a literal subclass of another test class) with literal def test_*. Tests are never generated by metaprogramming.
  • A base test class may live in a library on an -I path: require / require_relative with string literals are followed transitively from the test files, and those files are scanned (not run) to resolve superclasses. Only classes in the target test files are run.
  • Files are loaded with require and the load paths lib, test and the project root; use require "..." / require_relative that Spinel resolves.
  • Test files under fixtures/ directories (relative to the project root) are skipped unless named explicitly or the given directory is itself inside fixtures/.
  • ScriptErrors (such as NotImplementedError) raised by a test are reported as errors; a teardown error after a failure is appended to its message.

Development

Run bin/setup (installs Spinel with mise and the gems), then bundle exec rake test. The tests use test-unit; the end-to-end tests are skipped when Spinel is not available. To use a Spinel checkout, set SPINEL in a git-ignored mise.local.toml.

License

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