Sha256: 5e0a5411b76c9f94945a153a771e8305aac578eab73891c7ee5b6368638b2670

Contents?: true

Size: 1.21 KB

Versions: 2

Compression:

Stored size: 1.21 KB

Contents

module Knapsack
  module Adapters
    class RspecAdapter < BaseAdapter
      def bind_time_tracker
        ::RSpec.configure do |config|
          config.before(:each) do
            Knapsack.tracker.spec_path = RspecAdapter.spec_path
            Knapsack.tracker.start_timer
          end

          config.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.warn(Presenter.time_offset_warning)
          end
        end
      end

      def self.spec_path
        example_group = ::RSpec.current_example.metadata[:example_group]
        until example_group[:parent_example_group].nil?
          example_group = example_group[:parent_example_group]
        end
        example_group[:file_path]
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
knapsack-0.3.0 lib/knapsack/adapters/rspec_adapter.rb
knapsack-0.2.0 lib/knapsack/adapters/rspec_adapter.rb