Class: KnapsackPro::Adapters::RSpecAdapter

Inherits:
BaseAdapter
  • Object
show all
Defined in:
lib/knapsack_pro/adapters/rspec_adapter.rb

Direct Known Subclasses

RspecAdapter

Constant Summary collapse

TEST_DIR_PATTERN =
'spec/**{,/*/**}/*_spec.rb'

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseAdapter

bind, #bind

Class Method Details

.test_path(example_group) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/knapsack_pro/adapters/rspec_adapter.rb', line 6

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

Instance Method Details

#bind_save_queue_reportObject



53
54
55
56
57
58
59
# File 'lib/knapsack_pro/adapters/rspec_adapter.rb', line 53

def bind_save_queue_report
  ::RSpec.configure do |config|
    config.after(:suite) do
      KnapsackPro::Report.save_subset_queue_to_file
    end
  end
end

#bind_save_reportObject



45
46
47
48
49
50
51
# File 'lib/knapsack_pro/adapters/rspec_adapter.rb', line 45

def bind_save_report
  ::RSpec.configure do |config|
    config.after(:suite) do
      KnapsackPro::Report.save
    end
  end
end

#bind_time_trackerObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/knapsack_pro/adapters/rspec_adapter.rb', line 22

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
      KnapsackPro.tracker.current_test_path = KnapsackPro::Adapters::RSpecAdapter.test_path(current_example_group)
      KnapsackPro.tracker.start_timer
    end

    config.after(:each) do
      KnapsackPro.tracker.stop_timer
    end

    config.after(:suite) do
      KnapsackPro.logger.debug(KnapsackPro::Presenter.global_time)
    end
  end
end