Sha256: a3aecbb53481192a34b2d0ff28d26711073f38926c9b171f671adfe766d87622

Contents?: true

Size: 1.9 KB

Versions: 15

Compression:

Stored size: 1.9 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.log(
            Presenter.time_offset_log_level,
            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
          if object.respond_to?(:scenario_outline)
            if object.scenario_outline.respond_to?(:feature)
              # Cucumber < 1.3
              object.scenario_outline.feature.file
            else
              # Cucumber >= 1.3
              object.scenario_outline.file
            end
          else
            if object.respond_to?(:feature)
              # Cucumber < 1.3
              object.feature.file
            else
              # Cucumber >= 1.3
              object.file
            end
          end
        end
      end

      private

      def Around(*tag_expressions, &proc)
        if ::Cucumber::VERSION.to_i >= 3
          ::Cucumber::Glue::Dsl.register_rb_hook('around', tag_expressions, proc)
        else
          ::Cucumber::RbSupport::RbDsl.register_rb_hook('around', tag_expressions, proc)
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
knapsack-4.0.0 lib/knapsack/adapters/cucumber_adapter.rb
knapsack-3.1.0 lib/knapsack/adapters/cucumber_adapter.rb
knapsack-3.0.0 lib/knapsack/adapters/cucumber_adapter.rb
knapsack-2.0.0 lib/knapsack/adapters/cucumber_adapter.rb
knapsack-1.22.0 lib/knapsack/adapters/cucumber_adapter.rb
knapsack-1.21.1 lib/knapsack/adapters/cucumber_adapter.rb
knapsack-1.21.0 lib/knapsack/adapters/cucumber_adapter.rb
knapsack-1.20.0 lib/knapsack/adapters/cucumber_adapter.rb
knapsack-1.19.0 lib/knapsack/adapters/cucumber_adapter.rb
knapsack-1.18.0 lib/knapsack/adapters/cucumber_adapter.rb
knapsack-1.17.2 lib/knapsack/adapters/cucumber_adapter.rb
knapsack-1.17.1 lib/knapsack/adapters/cucumber_adapter.rb
knapsack-1.17.0 lib/knapsack/adapters/cucumber_adapter.rb
knapsack-1.16.0 lib/knapsack/adapters/cucumber_adapter.rb
knapsack-1.15.0 lib/knapsack/adapters/cucumber_adapter.rb