Class: Knapsack::Adapters::RspecAdapter

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseAdapter

bind, #bind

Class Method Details

.spec_path(example_group) ⇒ Object



44
45
46
47
48
49
# File 'lib/knapsack/adapters/rspec_adapter.rb', line 44

def self.spec_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_generator ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/knapsack/adapters/rspec_adapter.rb', line 27

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_warning ⇒ Object



36
37
38
39
40
41
42
# File 'lib/knapsack/adapters/rspec_adapter.rb', line 36

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_tracker ⇒ Object



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

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.spec_path = RspecAdapter.spec_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