Class: KnapsackPro::Adapters::MinitestAdapter

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

Defined Under Namespace

Modules: BindQueueModeMinitestPlugin, BindTimeTrackerMinitestPlugin

Constant Summary collapse

TEST_DIR_PATTERN =
'test/**{,/*/**}/*_test.rb'
@@parent_of_test_dir =
nil

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseAdapter

adapter_bind_method_called_file, bind, #bind, #bind_after_queue_hook, #bind_before_queue_hook, calculate_slow_id_paths, split_by_test_cases_enabled?, verify_bind_method_called

Class Method Details

.test_path(obj) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/knapsack_pro/adapters/minitest_adapter.rb', line 9

def self.test_path(obj)
  path, _line =
    begin
      Object.const_source_location(obj.class.to_s)
    rescue NameError # Dynamically defined class (Minitest::Spec `describe "more words"`)
      nil
    end

  if path.nil? # Dynamically defined class (Minitest::Spec `describe "oneword"`)
    test_method_name = obj.class.runnable_methods.first
    path, _line = obj.method(test_method_name).source_location
  end

  path.gsub(Regexp.new("^#{@@parent_of_test_dir}"), '.')
end

Instance Method Details

#bind_queue_modeObject



77
78
79
80
81
82
83
# File 'lib/knapsack_pro/adapters/minitest_adapter.rb', line 77

def bind_queue_mode
  ::Minitest::Test.send(:include, BindQueueModeMinitestPlugin)

  add_post_run_callback do
    KnapsackPro.logger.debug(KnapsackPro::Presenter.global_time)
  end
end

#bind_save_reportObject



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

def bind_save_report
  add_post_run_callback do
    KnapsackPro::Report.save
  end
end

#bind_time_trackerObject



38
39
40
41
42
43
44
# File 'lib/knapsack_pro/adapters/minitest_adapter.rb', line 38

def bind_time_tracker
  ::Minitest::Test.send(:include, BindTimeTrackerMinitestPlugin)

  add_post_run_callback do
    KnapsackPro.logger.debug(KnapsackPro::Presenter.global_time)
  end
end

#set_test_helper_path(file_path) ⇒ Object



52
53
54
55
# File 'lib/knapsack_pro/adapters/minitest_adapter.rb', line 52

def set_test_helper_path(file_path)
  test_dir_path = File.dirname(file_path)
  @@parent_of_test_dir = File.expand_path('../', test_dir_path)
end