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 itOutput:
..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 forklassor 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
sendwith 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 literaldef test_*. Tests are never generated by metaprogramming. - A base test class may live in a library on an
-Ipath:require/require_relativewith 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
requireand the load pathslib,testand the project root; userequire "..."/require_relativethat Spinel resolves. - Test files under
fixtures/directories (relative to the project root) are skipped unless named explicitly or the given directory is itself insidefixtures/. -
ScriptErrors (such asNotImplementedError) 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.