class Dbtap::Tapper

The Tapper class provides the DSL for Dbtap#define_tests

It also drives the evaluation of all the tests via run

Attributes

tests[R]

Public Class Methods

new() click to toggle source
# File lib/dbtap/tapper.rb, line 11
def initialize
  @tests = []
  db.extension :error_sql
end

Public Instance Methods

run() click to toggle source

Drives the evaluation of each test, emitting TAP-compliant messages for each test

# File lib/dbtap/tapper.rb, line 18
def run
  puts (1..tests.length).to_s
  tests.each_with_index do |test, i|
    begin
      if test.is_ok?
        ok(test, i)
      else
        not_ok(test, i)
      end
    rescue Sequel::DatabaseError
      puts $!.sql
      raise $!
    end
  end
end

Private Instance Methods

base_dir() click to toggle source

When we install dbtap as a gem, it will need to refer to the testers directory, so we’ll first find where the gem lives

# File lib/dbtap/tapper.rb, line 59
def base_dir
  Pathname.new(__FILE__).dirname
end
local_require(file) click to toggle source

When dbtap is gem, this will require testers from the proper relative path

# File lib/dbtap/tapper.rb, line 52
def local_require(file)
  path = base_dir + 'testers' + file.to_s
  require_relative path
end
not_ok(test, i) click to toggle source

Emits a TAP-compliant NOT OK message

# File lib/dbtap/tapper.rb, line 43
def not_ok(test, i)
  message = "not ok #{i + 1}"
  message += ' - ' + test.name if test.name
  message += "\n  " + test.errors.join("\n  ") if test.errors
  puts message
end
ok(test, i) click to toggle source

Emits a TAP-compliant OK message

# File lib/dbtap/tapper.rb, line 36
def ok(test, i)
  message = "ok #{i + 1}"
  message += ' - ' + test.name if test.name
  puts message
end
performs_within(*args) click to toggle source
# File lib/dbtap/tapper.rb, line 72
def performs_within(*args)
  local_require(:performs_within)
  tests << PerformsWithin.new(*args)
end
set_eq(*args) click to toggle source

The following methods are hard-coded, and used to instantiate each type of test. I imagine I can do some sort of thing where each Tester class can register with Tapper to get dynamically create a set of methods for Tapper to use, but for now, this is my approach

# File lib/dbtap/tapper.rb, line 67
def set_eq(*args)
  local_require(:set_eq)
  tests << SetEq.new(*args)
end