Class: Strut::ReportBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/strut/report_builder.rb

Instance Method Summary collapse

Instance Method Details

#build(responses, document) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/strut/report_builder.rb', line 5

def build(responses, document)
  report = Report.new

  scenario_results = Hash.new { |h, k| h[k] = ScenarioResult.new }
  responses.each do |response|
    handle_response(response, document, report, scenario_results)
  end

  scenario_results.each_pair do |_, result|
    report.add_scenario_result(result)
  end

  report
end

#exceptional_result?(result) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/strut/report_builder.rb', line 48

def exceptional_result?(result)
  result =~ /^__EXCEPTION__:message:(.+)/ ? $1 : nil
end

#failed_result?(result, metadata) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/strut/report_builder.rb', line 52

def failed_result?(result, )
  .expected_value && .expected_value.to_s != result.to_s
end

#handle_response(response, document, report, scenario_results) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/strut/report_builder.rb', line 20

def handle_response(response, document, report, scenario_results)
  command_id, command_result = *response
  if command_id == "error"
    report.add_error(command_result.to_s)
  else
     = document.(command_id)
    if 
      process_result(command_result, , report, scenario_results)
    else
      report.add_error("Unexpected response from Slim: #{response.inspect}")
    end
  end
end

#process_result(result, metadata, report, scenario_results) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/strut/report_builder.rb', line 34

def process_result(result, , report, scenario_results)
  scenario_result = scenario_results[.scenario_number]
  scenario_result.name = "Scenario #{metadata.scenario_number}, line #{metadata.line}"

  if exception_message = exceptional_result?(result)
    scenario_result.add_exception_for_line(.line, exception_message)
  elsif failed_result?(result, )
    fail_message = "Expected #{metadata.expected_value} but got #{result}"
    scenario_result.add_fail_for_line(.line, fail_message)
  else
    scenario_result.add_ok_for_line(.line)
  end
end