Sha256: d02d2032d115e722589941337ceb1666c65c71b86dae5063f6fb14cfcd5c123c

Contents?: true

Size: 1.94 KB

Versions: 14

Compression:

Stored size: 1.94 KB

Contents

module KnapsackPro
  module Adapters
    class RSpecAdapter < BaseAdapter
      TEST_DIR_PATTERN = 'spec/**{,/*/**}/*_spec.rb'

      def self.test_path(example_group)
        if defined?(Turnip) && Turnip::VERSION.to_i < 2
          unless example_group[:turnip]
            until example_group[:parent_example_group].nil?
              example_group = example_group[:parent_example_group]
            end
          end
        else
          until example_group[:parent_example_group].nil?
            example_group = example_group[:parent_example_group]
          end
        end

        example_group[:file_path]
      end

      def bind_time_tracker
        ::RSpec.configure do |config|
          config.before(:each) do
            current_example_group =
              if ::RSpec.respond_to?(:current_example)
                ::RSpec.current_example.metadata[:example_group]
              else
                example.metadata
              end
            KnapsackPro.tracker.current_test_path = KnapsackPro::Adapters::RSpecAdapter.test_path(current_example_group)
            KnapsackPro.tracker.start_timer
          end

          config.after(:each) do
            KnapsackPro.tracker.stop_timer
          end

          config.after(:suite) do
            KnapsackPro.logger.info(KnapsackPro::Presenter.global_time)
          end
        end
      end

      def bind_save_report
        ::RSpec.configure do |config|
          config.after(:suite) do
            KnapsackPro::Report.save
          end
        end
      end

      def bind_save_queue_report
        ::RSpec.configure do |config|
          config.after(:suite) do
            KnapsackPro::Report.save_subset_queue_to_file
          end
        end
      end
    end

    # This is added to provide backwards compatibility
    # In case someone is doing switch from knapsack gem to the knapsack_pro gem
    # and didn't notice the class name changed
    class RspecAdapter < RSpecAdapter
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
knapsack_pro-0.30.0 lib/knapsack_pro/adapters/rspec_adapter.rb
knapsack_pro-0.29.0 lib/knapsack_pro/adapters/rspec_adapter.rb
knapsack_pro-0.28.1 lib/knapsack_pro/adapters/rspec_adapter.rb
knapsack_pro-0.28.0 lib/knapsack_pro/adapters/rspec_adapter.rb
knapsack_pro-0.27.0 lib/knapsack_pro/adapters/rspec_adapter.rb
knapsack_pro-0.26.0 lib/knapsack_pro/adapters/rspec_adapter.rb
knapsack_pro-0.25.0 lib/knapsack_pro/adapters/rspec_adapter.rb
knapsack_pro-0.24.0 lib/knapsack_pro/adapters/rspec_adapter.rb
knapsack_pro-0.23.0 lib/knapsack_pro/adapters/rspec_adapter.rb
knapsack_pro-0.22.0 lib/knapsack_pro/adapters/rspec_adapter.rb
knapsack_pro-0.21.0 lib/knapsack_pro/adapters/rspec_adapter.rb
knapsack_pro-0.20.0 lib/knapsack_pro/adapters/rspec_adapter.rb
knapsack_pro-0.19.0 lib/knapsack_pro/adapters/rspec_adapter.rb
knapsack_pro-0.18.0 lib/knapsack_pro/adapters/rspec_adapter.rb