class Gobstones::Spec::Runner

Attributes

gobstones_path[R]

Public Class Methods

new(gobstones_path) click to toggle source
# File lib/gobstones/spec/runner.rb, line 8
def initialize(gobstones_path)
  @gobstones_path = gobstones_path
end

Public Instance Methods

run!(test_definition) click to toggle source
# File lib/gobstones/spec/runner.rb, line 12
def run!(test_definition)
  source_file = write_tempfile test_definition[:source], 'gbs'
  results = test_definition[:examples].map do |example_definition|
    example_definition[:check_head_position] = test_definition[:check_head_position]
    run_example!(example_definition, source_file)
  end
  aggregate_results(results)
ensure
  source_file.unlink
end

Private Instance Methods

aggregate_results(results) click to toggle source
# File lib/gobstones/spec/runner.rb, line 31
def aggregate_results(results)
  [results.map { |it| it[0] }.join("\n<hr>\n"), results.all? { |it| it[1] == :passed } ? :passed : :failed]
end
post_process(result, status) click to toggle source
# File lib/gobstones/spec/runner.rb, line 35
def post_process(result, status)
  if status == :passed
    @example.result
  else
    [@example.parse_error_message(result), status]
  end
ensure
  @example.stop!
end
run_example!(example_definition, source_file) click to toggle source
# File lib/gobstones/spec/runner.rb, line 25
def run_example!(example_definition, source_file)
  command = start_example(source_file, example_definition)
  result, status = run_command command
  post_process result, status
end
start_example(source, example_definition) click to toggle source
# File lib/gobstones/spec/runner.rb, line 45
def start_example(source, example_definition)
  @example = Gobstones::Spec::Example.new(gobstones_path, example_definition[:check_head_position])
  @example.start!(source, example_definition[:initial_board], example_definition[:final_board])
end