Class: KnapsackPro::Adapters::TestUnitAdapter

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

Defined Under Namespace

Modules: BindTimeTrackerTestUnitPlugin

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

bind, #bind, #bind_before_queue_hook, #bind_save_queue_report, #bind_tracker_reset

Class Method Details

.test_path(obj) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/knapsack_pro/adapters/test_unit_adapter.rb', line 7

def self.test_path(obj)
  first_test = obj.tests.first
  method = first_test.method_name
  full_test_path = first_test.method(method).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

Instance Method Details

#bind_save_reportObject



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

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

#bind_time_trackerObject



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

def bind_time_tracker
  Test::Unit::TestSuite.send(:prepend, BindTimeTrackerTestUnitPlugin)

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

#set_test_helper_path(file_path) ⇒ Object



58
59
60
61
# File 'lib/knapsack_pro/adapters/test_unit_adapter.rb', line 58

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