1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
module Knapsack
module Adapters
class RSpecAdapter < BaseAdapter
TEST_DIR_PATTERN = 'spec/**{,/*/**}/*_spec.rb'
REPORT_PATH = 'knapsack_rspec_report.json'
def bind_time_tracker
::RSpec.configure do |config|
config.prepend_before(:each) do
current_example_group =
if ::RSpec.respond_to?(:current_example)
::RSpec.current_example.metadata[:example_group]
else
example.metadata
end
Knapsack.tracker.test_path = RSpecAdapter.test_path(current_example_group)
Knapsack.tracker.start_timer
end
config.append_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.log(
Presenter.time_offset_log_level,
Presenter.time_offset_warning
)
end
end
end
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
end
# This is added to provide backwards compatibility
class RspecAdapter < RSpecAdapter
end
end
end
|