class GobstonesExpectationsHook

Public Instance Methods

run!(request) click to toggle source
# File lib/expectations_hook.rb, line 54
def run!(request)
  content = request[:content]
  expectations = request[:expectations]

  if content.strip.empty?
    return expectations.map { |exp| {'expectation' => exp, 'result' => false } }
  end

  ast = generate_ast! content
  all_expectations = expectations + (default_expectations_for parse_test request)

  all_expectations.map { |exp| {'expectation' => exp, 'result' => run_expectation!(exp, ast)} }
end

Private Instance Methods

default_expectations_for(test) click to toggle source
# File lib/expectations_hook.rb, line 70
def default_expectations_for(test)
  StonesSpec::Subject.from(test[:subject]).default_expectations
end
generate_ast!(source_code) click to toggle source
# File lib/expectations_hook.rb, line 78
def generate_ast!(source_code)
  %x"#{gobstones_command} #{write_tempfile(source_code, 'gbs').path} --print-ast --target parse --no-print-retvals --silent"
end
gobstones_command() click to toggle source
# File lib/expectations_hook.rb, line 82
def gobstones_command
  @config['gobstones_command']
end
run_expectation!(expectation, ast) click to toggle source
# File lib/expectations_hook.rb, line 74
def run_expectation!(expectation, ast)
  Mumukit::Inspection.parse(expectation['inspection']).eval_in_gobstones(expectation['binding'], ast)
end