Class: Knapsack::Adapters::RSpecAdapter

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

Direct Known Subclasses

RspecAdapter

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



50
51
52
53
54
55
56
57
58
# File 'lib/knapsack/adapters/rspec_adapter.rb', line 50

def self.test_path(example_group)
  unless example_group[:turnip]
    until example_group[:parent_example_group].nil?
      example_group = example_group[:parent_example_group]
    end
  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
46
47
48
# File 'lib/knapsack/adapters/rspec_adapter.rb', line 39

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

#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