Sha256: f014fb5d3b0169ea26f90f2e56ef092f2dbe39d14ea2d4c57122c9a19ac0bf07

Contents?: true

Size: 1.4 KB

Versions: 3

Compression:

Stored size: 1.4 KB

Contents

module Knapsack
  module Adapters
    class CucumberAdapter < BaseAdapter
      TEST_DIR_PATTERN = 'features/**{,/*/**}/*.feature'
      REPORT_PATH = 'knapsack_cucumber_report.json'

      def bind_time_tracker
        Around do |object, block|
          Knapsack.tracker.test_path = CucumberAdapter.test_path(object)
          Knapsack.tracker.start_timer
          block.call
          Knapsack.tracker.stop_timer
        end

        ::Kernel.at_exit do
          Knapsack.logger.info(Presenter.global_time)
        end
      end

      def bind_report_generator
        ::Kernel.at_exit do
          Knapsack.report.save
          Knapsack.logger.info(Presenter.report_details)
        end
      end

      def bind_time_offset_warning
        ::Kernel.at_exit do
          Knapsack.logger.warn(Presenter.time_offset_warning)
        end
      end

      def self.test_path(object)
        if Cucumber::VERSION.to_i >= 2
          test_case = object
          test_case.location.file
        else
          scenario_or_outline_table = object
          if scenario_or_outline_table.respond_to?(:file)
            scenario_or_outline_table.file
          else
            scenario_or_outline_table.scenario_outline.file
          end
        end
      end

      private

      def Around(*tag_expressions, &proc)
        ::Cucumber::RbSupport::RbDsl.register_rb_hook('around', tag_expressions, proc)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
knapsack-1.7.0 lib/knapsack/adapters/cucumber_adapter.rb
knapsack-1.6.1 lib/knapsack/adapters/cucumber_adapter.rb
knapsack-1.6.0 lib/knapsack/adapters/cucumber_adapter.rb