class DataMiner::Step::Test

A step that runs tests and stops the data miner on failures.

Create these by calling test inside a data_miner block.

@see DataMiner::ActiveRecordClassMethods#data_miner Overview of how to define data miner scripts inside of ActiveRecord models. @see DataMiner::Script#test Creating a test step by calling DataMiner::Script#test from inside a data miner script

Attributes

after[R]

After how many rows of the previous step to run the tests. @return [Numeric]

blk[R]

The block of arbitrary code to be run. @return [Proc]

block_description[R]

A description of what the block does. Doesn’t exist when a single class method is specified using a Symbol. @return [String]

description[R]

A description of what the block does. Doesn’t exist when a single class method is specified using a Symbol. @return [String]

every[R]

Every how many rows to run tests @return [Numeric]

Public Class Methods

new(script, description, settings, &blk) click to toggle source

@private

# File lib/data_miner/step/test.rb, line 34
def initialize(script, description, settings, &blk)
  settings = settings.stringify_keys
  @script = script
  @description = description
  @blk = blk
  @after = settings['after']
  @every = settings['every']
  raise "can't do both after and every" if after and every
end

Public Instance Methods

notify(step, count) click to toggle source
# File lib/data_miner/step/test.rb, line 56
def notify(step, count)
  if count % (after || every) == 0
    eval_catching_errors
    !after # if it's an after, return false, so that we stop getting informed
  else
    true
  end
end
start() click to toggle source

@private

# File lib/data_miner/step/test.rb, line 45
def start
  if inline?
    eval_catching_errors
  end
  nil
end
target?(step) click to toggle source
# File lib/data_miner/step/test.rb, line 52
def target?(step)
  !inline? and (step.pos == pos - 1)
end

Private Instance Methods

eval_catching_errors() click to toggle source
# File lib/data_miner/step/test.rb, line 71
def eval_catching_errors
  DataMiner::Script.uniq { instance_eval(&blk) }
rescue ::RSpec::Expectations::ExpectationNotMetError
  raise RuntimeError, "FAILED: #{description} (#{$!.inspect})"
end
inline?() click to toggle source
# File lib/data_miner/step/test.rb, line 67
def inline?
  not (after or every)
end