Sha256: 07b5feab6ced1d0a37a81f6f34ee328a0a254b9e5ee2d802dc01618e34a946d5

Contents?: true

Size: 1.6 KB

Versions: 4

Compression:

Stored size: 1.6 KB

Contents

# -*- coding: utf-8 -*-

require 'turnip_formatter/step'

module TurnipFormatter
  module Scenario
    include RSpec::Core::BacktraceFormatter

    class NotExistStepsInformationError < ::StandardError; end
    class NoFeatureFileError < ::StandardError; end

    #
    # @param  [RSpec::Core::Example]  example
    #
    def initialize(example)
      @example = example
      clean_backtrace
    end

    def validation
      raise NotExistStepsInformationError unless example.metadata.member?(:turnip)
      raise NoFeatureFileError unless feature_file_path.end_with?('.feature')
    end

    def steps
      @steps ||= descriptions.map do |desc|
        TurnipFormatter::Step.new(example, desc)
      end
    end
    
    #
    # @return  [String] scenario name
    #
    def name
      example.example_group.description
    end

    #
    # @return  [String] scenario status ('passed', 'failed' or 'pending')
    #
    def status
      example.execution_result[:status]
    end

    def feature_name
      example.example_group.metadata[:example_group][:example_group][:description]
    end

    def feature_file_path
      example.metadata[:file_path]
    end

    def tags
      example.metadata[:turnip][:tags]
    end

    def example
      @example
    end

    private

    def descriptions
      example.metadata[:turnip][:steps]
    end

    def clean_backtrace
      return if example.exception.nil?
      formatted = format_backtrace(example.exception.backtrace, example.metadata)
      new_backtrace = formatted.map { |b| backtrace_line(b) }.compact
      example.exception.set_backtrace(new_backtrace)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
turnip_formatter-0.0.5 lib/turnip_formatter/scenario.rb
turnip_formatter-0.0.4 lib/turnip_formatter/scenario.rb
turnip_formatter-0.0.3 lib/turnip_formatter/scenario.rb
turnip_formatter-0.0.2 lib/turnip_formatter/scenario.rb