Skip to content

Commit

Permalink
TestUnit adapter works.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArturT committed Oct 2, 2017
1 parent 4d9d603 commit 0803311
Showing 1 changed file with 36 additions and 27 deletions.
63 changes: 36 additions & 27 deletions lib/knapsack_pro/adapters/test_unit_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,47 @@ module KnapsackPro
module Adapters
class TestUnitAdapter < BaseAdapter
TEST_DIR_PATTERN = 'test/**{,/*/**}/*_test.rb'
@@parent_of_test_dir = nil

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]
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

# FIXME
# Overrides the method from unit-test gem
# https://github.com/test-unit/test-unit/blob/master/lib/test/unit/testsuite.rb
module BindTimeTrackerTestUnitPlugin
def setup
super
puts '/'*10
puts 'SETUP plugin'
#KnapsackPro.tracker.current_test_path = KnapsackPro::Adapters::TestUnitAdapter.test_path(self)
#KnapsackPro.tracker.start_timer
def run_startup(result)
return if @test_case.nil?
KnapsackPro.tracker.current_test_path = KnapsackPro::Adapters::TestUnitAdapter.test_path(self)
KnapsackPro.tracker.start_timer
return if !@test_case.respond_to?(:startup)
begin
@test_case.startup
rescue Exception
raise unless handle_exception($!, result)
end
end

def teardown
#KnapsackPro.tracker.stop_timer
puts '/'*10
puts 'SETUP teardown'
super
def run_shutdown(result)
return if @test_case.nil?
KnapsackPro.tracker.stop_timer
return if !@test_case.respond_to?(:shutdown)
begin
@test_case.shutdown
rescue Exception
raise unless handle_exception($!, result)
end
end
end

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

Test::Unit.at_exit do
KnapsackPro.logger.debug(KnapsackPro::Presenter.global_time)
Expand All @@ -50,6 +54,11 @@ def bind_save_report
KnapsackPro::Report.save
end
end

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
end
end
end

0 comments on commit 0803311

Please sign in to comment.