Sha256: 4c620f08e37dfbade7fa2e38c6475b001f98bdf4a50e3c66d5d8a531874360df

Contents?: true

Size: 1.39 KB

Versions: 1

Compression:

Stored size: 1.39 KB

Contents

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

require 'turnip_formatter/step'

module TurnipFormatter
  module Scenario
    class NotExistStepsInformationError < ::StandardError; end
    class NoFeatureFileError < ::StandardError; end

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

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

    def steps
      descriptions.map { |desc| TurnipFormatter::Step.new(desc) }
    end

    def method_missing(name, *args, &block)
      if scenario.execution_result.member?(name.to_sym)
        scenario.execution_result[name.to_sym]
      else
        super
      end
    end

    def name
      scenario.example_group.description
    end

    def feature_name
      @scenario.example_group.metadata[:example_group][:example_group][:description]
    end

    def feature_file_path
      scenario.metadata[:file_path]
    end

    def tags
      scenario.metadata[:steps][:tags]
    end

    private

    def scenario
      @scenario
    end

    def descriptions
      descriptions = scenario.metadata[:steps][:descriptions]
      keywords = scenario.metadata[:steps][:keywords]
      docstrings = scenario.metadata[:steps][:docstrings]
      descriptions.zip(keywords, docstrings)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
turnip_formatter-0.0.1 lib/turnip_formatter/scenario.rb