Sha256: 0bb6c76389b72a8003908239b853e5abef2a01aac51667dc5f0dfe7605bf6668

Contents?: true

Size: 1.86 KB

Versions: 22

Compression:

Stored size: 1.86 KB

Contents

module KnapsackPro
  module Adapters
    class CucumberAdapter < BaseAdapter
      TEST_DIR_PATTERN = 'features/**{,/*/**}/*.feature'

      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

      def bind_time_tracker
        Around do |object, block|
          KnapsackPro.tracker.current_test_path = KnapsackPro::Adapters::CucumberAdapter.test_path(object)
          KnapsackPro.tracker.start_timer
          block.call
          KnapsackPro.tracker.stop_timer
        end

        ::Kernel.at_exit do
          KnapsackPro.logger.debug(KnapsackPro::Presenter.global_time)
        end
      end

      def bind_save_report(latest_error = nil)
        ::Kernel.at_exit do
          # $! is latest error message
          latest_error = (latest_error || $!)
          exit_status = latest_error.status if latest_error.is_a?(SystemExit)
          # saving report makes API call which changes exit status
          # from cucumber so we need to preserve cucumber exit status
          KnapsackPro::Report.save
          ::Kernel.exit exit_status if exit_status
        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

22 entries across 22 versions & 1 rubygems

Version Path
knapsack_pro-0.51.0 lib/knapsack_pro/adapters/cucumber_adapter.rb
knapsack_pro-0.50.1 lib/knapsack_pro/adapters/cucumber_adapter.rb
knapsack_pro-0.50.0 lib/knapsack_pro/adapters/cucumber_adapter.rb
knapsack_pro-0.49.0 lib/knapsack_pro/adapters/cucumber_adapter.rb
knapsack_pro-0.48.0 lib/knapsack_pro/adapters/cucumber_adapter.rb
knapsack_pro-0.47.0 lib/knapsack_pro/adapters/cucumber_adapter.rb
knapsack_pro-0.46.0 lib/knapsack_pro/adapters/cucumber_adapter.rb
knapsack_pro-0.45.0 lib/knapsack_pro/adapters/cucumber_adapter.rb
knapsack_pro-0.44.0 lib/knapsack_pro/adapters/cucumber_adapter.rb
knapsack_pro-0.43.0 lib/knapsack_pro/adapters/cucumber_adapter.rb
knapsack_pro-0.42.0 lib/knapsack_pro/adapters/cucumber_adapter.rb
knapsack_pro-0.41.0 lib/knapsack_pro/adapters/cucumber_adapter.rb
knapsack_pro-0.40.0 lib/knapsack_pro/adapters/cucumber_adapter.rb
knapsack_pro-0.39.0 lib/knapsack_pro/adapters/cucumber_adapter.rb
knapsack_pro-0.38.0 lib/knapsack_pro/adapters/cucumber_adapter.rb
knapsack_pro-0.37.0 lib/knapsack_pro/adapters/cucumber_adapter.rb
knapsack_pro-0.36.0 lib/knapsack_pro/adapters/cucumber_adapter.rb
knapsack_pro-0.35.0 lib/knapsack_pro/adapters/cucumber_adapter.rb
knapsack_pro-0.34.0 lib/knapsack_pro/adapters/cucumber_adapter.rb
knapsack_pro-0.33.0 lib/knapsack_pro/adapters/cucumber_adapter.rb