Class: Knapsack::Adapters::RspecAdapter

Inherits:
BaseAdapter show all
Defined in:
lib/knapsack/adapters/rspec_adapter.rb

Constant Summary collapse

TEST_DIR_PATTERN =
'spec/**/*_spec.rb'
REPORT_PATH =
'knapsack_rspec_report.json'

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseAdapter

bind, #bind

Class Method Details

.test_path(example_group) ⇒ Object



47
48
49
50
51
52
# File 'lib/knapsack/adapters/rspec_adapter.rb', line 47

def self.test_path(example_group)
  until example_group[:parent_example_group].nil?
    example_group = example_group[:parent_example_group]
  end
  example_group[:file_path]
end

Instance Method Details

#bind_report_generatorObject



30
31
32
33
34
35
36
37
# File 'lib/knapsack/adapters/rspec_adapter.rb', line 30

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

#bind_time_offset_warningObject



39
40
41
42
43
44
45
# File 'lib/knapsack/adapters/rspec_adapter.rb', line 39

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

#bind_time_trackerObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/knapsack/adapters/rspec_adapter.rb', line 7

def bind_time_tracker
  ::RSpec.configure do |config|
    config.before(:each) do
      current_example_group =
        if ::RSpec.respond_to?(:current_example)
          ::RSpec.current_example.[:example_group]
        else
          example.
        end
      Knapsack.tracker.test_path = RspecAdapter.test_path(current_example_group)
      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