Sha256: 8345e1489cb6c7ed4f350cee3a58b218fc9208a032ca803ac84289d7fe01bce3

Contents?: true

Size: 1.96 KB

Versions: 9

Compression:

Stored size: 1.96 KB

Contents

module Knapsack
  module Adapters
    class RSpecAdapter < BaseAdapter
      TEST_DIR_PATTERN = 'spec/**{,/*/**}/*_spec.rb'
      REPORT_PATH = 'knapsack_rspec_report.json'

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

          config.append_after(:each) do
            Knapsack.tracker.stop_timer
          end

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

      def bind_report_generator
        ::RSpec.configure do |config|
          config.after(:suite) do
            Knapsack.report.save
            Knapsack.logger.info(Presenter.report_details)
          end
        end
      end

      def bind_time_offset_warning
        ::RSpec.configure do |config|
          config.after(:suite) do
            Knapsack.logger.log(
              Presenter.time_offset_log_level,
              Presenter.time_offset_warning
            )
          end
        end
      end

      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
    end

    # This is added to provide backwards compatibility
    class RspecAdapter < RSpecAdapter
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
knapsack-1.20.0 lib/knapsack/adapters/rspec_adapter.rb
knapsack-1.19.0 lib/knapsack/adapters/rspec_adapter.rb
knapsack-1.18.0 lib/knapsack/adapters/rspec_adapter.rb
knapsack-1.17.2 lib/knapsack/adapters/rspec_adapter.rb
knapsack-1.17.1 lib/knapsack/adapters/rspec_adapter.rb
knapsack-1.17.0 lib/knapsack/adapters/rspec_adapter.rb
knapsack-1.16.0 lib/knapsack/adapters/rspec_adapter.rb
knapsack-1.15.0 lib/knapsack/adapters/rspec_adapter.rb
knapsack-1.14.1 lib/knapsack/adapters/rspec_adapter.rb