class KnapsackPro::Adapters::MinitestAdapter

Constants

TEST_DIR_PATTERN

Public Class Methods

test_path(obj) click to toggle source
# File lib/knapsack_pro/adapters/minitest_adapter.rb, line 9
def self.test_path(obj)
  # Pick the first public method in the class itself, that starts with "test_"
  test_method_name = obj.public_methods(false).select{|m| m =~ /^test_/ }.first
  if test_method_name.nil?
    # case for shared examples
    method_object = obj.method(obj.location.sub(/.*?test_/, 'test_'))
  else
    method_object = obj.method(test_method_name)
  end
  full_test_path = method_object.source_location.first
  parent_of_test_dir_regexp = Regexp.new("^#{@@parent_of_test_dir}")
  test_path = full_test_path.gsub(parent_of_test_dir_regexp, '.')
  # test_path will look like ./test/dir/unit_test.rb
  test_path
end

Public Instance Methods

bind_queue_mode() click to toggle source
# File lib/knapsack_pro/adapters/minitest_adapter.rb, line 79
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_report() click to toggle source
# File lib/knapsack_pro/adapters/minitest_adapter.rb, line 48
def bind_save_report
  add_post_run_callback do
    KnapsackPro::Report.save
  end
end
bind_time_tracker() click to toggle source
# File lib/knapsack_pro/adapters/minitest_adapter.rb, line 40
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) click to toggle source
# File lib/knapsack_pro/adapters/minitest_adapter.rb, line 54
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

Private Instance Methods

add_post_run_callback(&block) click to toggle source
# File lib/knapsack_pro/adapters/minitest_adapter.rb, line 89
def add_post_run_callback(&block)
  if ::Minitest.respond_to?(:after_run)
    ::Minitest.after_run { block.call }
  else
    ::Minitest::Unit.after_tests { block.call }
  end
end