require_relative 'step' module Sweet module Format module Cucumber class Scenario class << self def from_output(data) data = JSON.parse(data, symbolize_names: true) if data.is_a? String tags = if data[:tags] data[:tags].map do |tag| tag[:name] end end if data[:steps] steps = data[:steps].map { |step| Step.from_output step } end new keyword: data[:keyword], name: data[:name], description: data[:description], line_number: data[:line], tags: tags, file_path: data[:file_path], steps: steps, screenshot: data[:screenshot] end end attr_accessor :keyword, :name, :description, :line_number, :tags, :steps, :status, :file_path, :screenshot attr_writer :duration def initialize(opts = {}) @keyword = opts[:keyword] @name = opts[:name] @description = opts[:description] @line_number = opts[:line_number] @tags = opts[:tags] || [] @file_path = opts[:file_path] @steps = opts[:steps] || [] @steps.map! do |step| if step.is_a? Hash Step.new step else step end end @screenshot = opts[:screenshot] determine_status end def is_background? @keyword == 'Background' end def failed? @status == :failed end def duration @steps.inject(0.0) do |sum, step| sum += step.duration || 0.0 end end private def determine_status @steps.each do |step| case step.status when :failed @status = :failed when :pending @status = :pending when :skipped @status = :skipped end break if @status end @status = :passed if @status.nil? end end end end end