Sha256: 9562d73cbfa56f88ff532657407a8e2c32221c450521153f155473a1790fd5a7

Contents?: true

Size: 1 KB

Versions: 1

Compression:

Stored size: 1 KB

Contents

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

require 'turnip/rspec'

module Turnip
  module RSpec
    class << self
      alias_method :original_run, :run

      def run(feature_file)
        original_run(feature_file)

        feature = Turnip::Builder.build(feature_file)
        example_group = ::RSpec.world.example_groups.last

        update_metadata(feature, example_group)
      end

      #
      # @param  [Turnip::Node::Feature]      feature
      # @param  [RSpec::Core::ExampleGroup]  example_group
      #
      def update_metadata(feature, example_group)
        background_steps = feature.backgrounds.map(&:steps).flatten
        examples = example_group.children

        feature.scenarios.zip(examples).each do |scenario, parent_example|
          example = parent_example.examples.first
          steps   = background_steps + scenario.steps
          tags    = (feature.tag_names + scenario.tag_names).uniq

          example.metadata[:turnip_formatter] = { steps: steps, tags: tags }
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
turnip_formatter-0.6.0.pre.beta.2 lib/turnip_formatter/ext/turnip/rspec.rb