Module: Cybertrain::Test

Defined in:
cybertrain/test.rb,
cybertrain/test/client.rb

Overview

The test harness for applications (and the framework’s own tests). minitest and RSpec cannot run under Spinel, so a test file is a plain program: it registers cases with the top-level test "name" do ... end, asserts with the top-level assert* methods (see the overview), and ends with Cybertrain::Test.run!. For requests, see Client.

cybertrain spin test compiles each test/*.rb (not test/support/) into its own program and compares its output with test/<name>.rb.expected. There is no setup/teardown and no isolation between cases: reset what you need at the top of a case (e.g. Article.all.delete_all).

Examples:

test/articles.rb

require_relative "support/blog_test"   # boots the app as BLOG, see examples/blog

test "title must be present" do
  article = Article.new(body: "a body long enough to pass length")
  refute article.save
  assert_includes article.errors.full_messages, "Title can't be blank"
end

Cybertrain::Test.run!

Defined Under Namespace

Classes: AssertionFailed, Client

Class Method Summary collapse

Class Method Details

.run!

This method returns an undefined value.

Runs every registered case in registration order, prints one line per case plus a summary, and exits non-zero when anything failed.

The lines are ok <name>, FAIL <name>: <message> for a failed assertion, ERR <name>: <Class>: <message> for another exception, then <n> tests, <n> assertions, <n> failures. Call it at the end of every test file.



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'cybertrain/test.rb', line 67

def self.run!
  @@cases.each do |c|
    begin
      c.block.call
      puts "ok   #{c.name}"
    rescue AssertionFailed => e
      @@failures += 1
      puts "FAIL #{c.name}: #{e.message}"
    rescue StandardError => e
      @@failures += 1
      puts "ERR  #{c.name}: #{e.class.name}: #{e.message}"
    end
  end
  puts "#{@@cases.size} tests, #{@@assertions} assertions, #{@@failures} failures"
  exit(1) if @@failures > 0
end