class Cucumber::Pro::Formatter

Public Class Methods

new(session, working_copy) click to toggle source
# File lib/cucumber/pro/formatter.rb, line 9
def initialize(session, working_copy)
  @session = session
  @working_copy = working_copy
  send_header
end

Public Instance Methods

after_examples(*args) click to toggle source
# File lib/cucumber/pro/formatter.rb, line 37
def after_examples(*args)
  @in_examples = false
end
after_feature_element(feature_element) click to toggle source
# File lib/cucumber/pro/formatter.rb, line 25
def after_feature_element(feature_element)
  return if Cucumber::Ast::ScenarioOutline === feature_element
  scenario = feature_element
  path, line = *scenario.file_colon_line.split(':')
  send_test_case_result(path, line, scenario.status)
end
after_features(*args) click to toggle source
# File lib/cucumber/pro/formatter.rb, line 50
def after_features(*args)
  @session.close
end
after_table_row(table_row) click to toggle source
# File lib/cucumber/pro/formatter.rb, line 41
def after_table_row(table_row)
  return unless @in_examples and Cucumber::Ast::OutlineTable::ExampleRow === table_row
  if @header_row
    @header_row = false
    return
  end
  send_test_case_result(@path, table_row.line, table_row.status)
end
before_examples(*args) click to toggle source
# File lib/cucumber/pro/formatter.rb, line 32
def before_examples(*args)
  @header_row = true
  @in_examples = true
end
before_feature(feature) click to toggle source
# File lib/cucumber/pro/formatter.rb, line 15
def before_feature(feature)
  @path = feature.file # we need this because table_row doens't have a file_colon_line
end
before_step_result(*args) click to toggle source
# File lib/cucumber/pro/formatter.rb, line 19
def before_step_result(*args)
  keyword, step_match, multiline_arg, status, exception, source_indent, background, file_colon_line = *args
  path, line = *file_colon_line.split(':')
  send_step_result(path, line, status)
end

Private Instance Methods

forward_slashify(path) click to toggle source
# File lib/cucumber/pro/formatter.rb, line 84
def forward_slashify(path)
  Cucumber::WINDOWS ? path.gsub(/\\/, '/') : path
end
get_build_number() click to toggle source
# File lib/cucumber/pro/formatter.rb, line 88
def get_build_number
  Pro.config.build_number || SecureRandom.hex
end
send_header() click to toggle source
# File lib/cucumber/pro/formatter.rb, line 56
def send_header
  @session.send_message({
    repo_url: @working_copy.repo_url,
    branch: @working_copy.branch,
    rev: @working_copy.rev,
    build_id: get_build_number,
    info: Info.new.to_h
  })
end
send_step_result(path, line, status) click to toggle source
# File lib/cucumber/pro/formatter.rb, line 66
def send_step_result(path, line, status)
  @session.send_message({
    path: forward_slashify(path),
    location: line.to_i,
    mime_type: 'application/vnd.cucumber.test-step-result+json',
    body: { status: status }
  })
end
send_test_case_result(path, line, status) click to toggle source
# File lib/cucumber/pro/formatter.rb, line 75
def send_test_case_result(path, line, status)
  @session.send_message({
    path: forward_slashify(path),
    location: line.to_i,
    mime_type: 'application/vnd.cucumber-pro.test-case-result+json',
    body: { status: status }
  })
end