Sha256: 8ca1dc63032aa74cb91d167d3f8cacdd02038db862dceef27161760159cabd08

Contents?: true

Size: 2 KB

Versions: 6

Compression:

Stored size: 2 KB

Contents

require 'forwardable'
require 'turnip_formatter/resource/step/step'
require 'turnip_formatter/resource/step/hook'

module TurnipFormatter
  module Resource
    module Scenario
      class Base
        attr_reader :example

        extend Forwardable
        def_delegators :raw, :line, :keyword, :name, :steps

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

        def id
          'scenario_' + object_id.to_s
        end

        #
        # @return  [Symbol] scenario status (:passed | :failed | :pending)
        #
        def status
          execution_result.status.to_sym
        end

        #
        # @return  [Float] scenario run time (sec)
        #
        def run_time
          execution_result.run_time
        end

        def feature_info
          path = RSpec::Core::Metadata.relative_path(feature_file_path)
          "\"#{feature.name}\" in #{path}"
        end

        def backgrounds
          feature.backgrounds
        end

        def tags
          @tags ||= (feature.tag_names + raw.tag_names).sort.uniq
        end

        def feature
          example.metadata[:turnip_formatter][:feature]
        end

        def steps
          return @steps if @steps

          @steps = raw_steps.map do |step|
            TurnipFormatter::Resource::Step::Step.new(example, step)
          end

          mark_status

          @steps
        end

        def mark_status
          raise NotImplementedError
        end

        private

        def raw
          @raw = example.metadata[:turnip_formatter][:scenario]
        end

        def raw_steps
          backgrounds.map(&:steps).flatten + raw.steps
        end

        def feature_file_path
          example.metadata[:file_path]
        end

        #
        # @return  [OpenStruct or ::RSpec::Core::Example::ExecutionResult]
        #
        def execution_result
          @execution_result ||= example.execution_result
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
turnip_formatter-0.8.0 lib/turnip_formatter/resource/scenario/base.rb
turnip_formatter-0.7.2 lib/turnip_formatter/resource/scenario/base.rb
turnip_formatter-0.7.1 lib/turnip_formatter/resource/scenario/base.rb
turnip_formatter-0.7.0 lib/turnip_formatter/resource/scenario/base.rb
turnip_formatter-0.6.1 lib/turnip_formatter/resource/scenario/base.rb
turnip_formatter-0.6.0 lib/turnip_formatter/resource/scenario/base.rb