class ATMCreateTestFormatter

Public Instance Methods

example_started(notification) click to toggle source
# File lib/atm_create_test_formatter.rb, line 6
def example_started(notification)
  if (notification.example.metadata.key?(:test_id) && !notification.example.metadata[:test_id].strip.empty?) || !notification.example.metadata.key?(:test_id)
    return
  end

  response = @client.TestCase.create(process_example(notification.example))
  if response.code != 201
    puts ATM::TestCaseError.new(response).message
    exit
  end

  update_local_test(notification.example, response['key'])
end

Private Instance Methods

line_number(example) click to toggle source
# File lib/atm_create_test_formatter.rb, line 28
def line_number(example)
  example.metadata[:line_number] - 1
end
update_local_test(example, test_key) click to toggle source
# File lib/atm_create_test_formatter.rb, line 22
def update_local_test(example, test_key)
  lines = File.readlines(example.metadata[:file_path])
  lines[line_number(example)].gsub!(/test_id:(\s+)?('|")(\s+)?('|")/, "test_id: '#{test_key}'")
  File.open(example.metadata[:file_path], 'w') { |f| f.write(lines.join) }
end