From dce08c9ae0cad327b0daaeac7e55dd90f07f9670 Mon Sep 17 00:00:00 2001 From: ArturT Date: Sat, 9 Sep 2017 11:11:18 +0200 Subject: [PATCH 01/20] Add test-unit to development dependencies --- knapsack_pro.gemspec | 1 + 1 file changed, 1 insertion(+) diff --git a/knapsack_pro.gemspec b/knapsack_pro.gemspec index 0ef09e5d..7a3f4078 100644 --- a/knapsack_pro.gemspec +++ b/knapsack_pro.gemspec @@ -26,6 +26,7 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'cucumber', '>= 0' spec.add_development_dependency 'spinach', '>= 0.8' spec.add_development_dependency 'minitest', '>= 5.0.0' + spec.add_development_dependency 'test-unit', '>= 3.0.0' spec.add_development_dependency 'codeclimate-test-reporter', '~> 0' spec.add_development_dependency 'pry', '~> 0' spec.add_development_dependency 'vcr', '~> 2.9' From 3da775234d751e0b16c789d282b79e779fdca3d4 Mon Sep 17 00:00:00 2001 From: ArturT Date: Sat, 9 Sep 2017 11:14:27 +0200 Subject: [PATCH 02/20] Update changelog --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b32d24d4..0e759658 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ * TODO +### 0.51.0 + +* Add support for test-unit test runner. + + https://github.com/KnapsackPro/knapsack_pro-ruby/pull/53 + +https://github.com/KnapsackPro/knapsack_pro-ruby/compare/v0.50.1...v0.51.0 + ### 0.50.1 * Update RSpec timing adapter to be more resilient. From 61ff8e643715e9846c1078e2f969e8181c3c8468 Mon Sep 17 00:00:00 2001 From: ArturT Date: Mon, 11 Sep 2017 21:24:47 +0200 Subject: [PATCH 03/20] Remove unnecessary line --- Rakefile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Rakefile b/Rakefile index d4dbb81e..d05fa720 100644 --- a/Rakefile +++ b/Rakefile @@ -1,4 +1,2 @@ require 'bundler/gem_tasks' require 'knapsack_pro' - -#KnapsackPro.load_tasks From 36773f14882ce0bfa845d6fd72f0fea68a04e77e Mon Sep 17 00:00:00 2001 From: ArturT Date: Mon, 11 Sep 2017 21:28:47 +0200 Subject: [PATCH 04/20] Add KNAPSACK_PRO_TEST_SUITE_TOKEN_TEST_UNIT to env --- lib/knapsack_pro/config/env.rb | 4 ++++ spec/knapsack_pro/config/env_spec.rb | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/knapsack_pro/config/env.rb b/lib/knapsack_pro/config/env.rb index 2d5fae5b..1fe6373c 100644 --- a/lib/knapsack_pro/config/env.rb +++ b/lib/knapsack_pro/config/env.rb @@ -136,6 +136,10 @@ def test_suite_token_minitest ENV['KNAPSACK_PRO_TEST_SUITE_TOKEN_MINITEST'] end + def test_suite_token_test_unit + ENV['KNAPSACK_PRO_TEST_SUITE_TOKEN_TEST_UNIT'] + end + def test_suite_token_cucumber ENV['KNAPSACK_PRO_TEST_SUITE_TOKEN_CUCUMBER'] end diff --git a/spec/knapsack_pro/config/env_spec.rb b/spec/knapsack_pro/config/env_spec.rb index e8653ab3..020b51a9 100644 --- a/spec/knapsack_pro/config/env_spec.rb +++ b/spec/knapsack_pro/config/env_spec.rb @@ -513,6 +513,20 @@ end end + describe '.test_suite_token_test_unit' do + subject { described_class.test_suite_token_test_unit } + + context 'when ENV exists' do + let(:test_suite_token_test_unit) { 'test-unit-token' } + before { stub_const("ENV", { 'KNAPSACK_PRO_TEST_SUITE_TOKEN_TEST_UNIT' => test_suite_token_test_unit }) } + it { should eq test_suite_token_test_unit } + end + + context "when ENV doesn't exist" do + it { should be_nil } + end + end + describe '.test_suite_token_cucumber' do subject { described_class.test_suite_token_cucumber } From 9c169d64b39a7ad7f51f0647be63840c5085148e Mon Sep 17 00:00:00 2001 From: ArturT Date: Mon, 11 Sep 2017 21:41:58 +0200 Subject: [PATCH 05/20] [WIP] Create example files for test unit runner, adapter and rake task. --- lib/knapsack_pro.rb | 2 + .../adapters/test_unit_adapter.rb | 81 ++++++++++ lib/knapsack_pro/runners/test_unit_runner.rb | 27 ++++ lib/tasks/test_unit.rake | 7 + .../adapters/test_unit_adapter_spec.rb | 147 ++++++++++++++++++ .../runners/test_unit_runner_spec.rb | 83 ++++++++++ 6 files changed, 347 insertions(+) create mode 100644 lib/knapsack_pro/adapters/test_unit_adapter.rb create mode 100644 lib/knapsack_pro/runners/test_unit_runner.rb create mode 100644 lib/tasks/test_unit.rake create mode 100644 spec/knapsack_pro/adapters/test_unit_adapter_spec.rb create mode 100644 spec/knapsack_pro/runners/test_unit_runner_spec.rb diff --git a/lib/knapsack_pro.rb b/lib/knapsack_pro.rb index 609871bb..c32db3f0 100644 --- a/lib/knapsack_pro.rb +++ b/lib/knapsack_pro.rb @@ -49,11 +49,13 @@ require_relative 'knapsack_pro/adapters/rspec_adapter' require_relative 'knapsack_pro/adapters/cucumber_adapter' require_relative 'knapsack_pro/adapters/minitest_adapter' +require_relative 'knapsack_pro/adapters/test_unit_adapter' require_relative 'knapsack_pro/adapters/spinach_adapter' require_relative 'knapsack_pro/runners/base_runner' require_relative 'knapsack_pro/runners/rspec_runner' require_relative 'knapsack_pro/runners/cucumber_runner' require_relative 'knapsack_pro/runners/minitest_runner' +require_relative 'knapsack_pro/runners/test_unit_runner' require_relative 'knapsack_pro/runners/spinach_runner' require_relative 'knapsack_pro/runners/queue/base_runner' require_relative 'knapsack_pro/runners/queue/rspec_runner' diff --git a/lib/knapsack_pro/adapters/test_unit_adapter.rb b/lib/knapsack_pro/adapters/test_unit_adapter.rb new file mode 100644 index 00000000..a5eb5f43 --- /dev/null +++ b/lib/knapsack_pro/adapters/test_unit_adapter.rb @@ -0,0 +1,81 @@ +module KnapsackPro + module Adapters + class TestUnitAdapter < BaseAdapter + TEST_DIR_PATTERN = 'spec/**{,/*/**}/*_spec.rb' + + 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 + + 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 + KnapsackPro.tracker.current_test_path = KnapsackPro::Adapters::RSpecAdapter.test_path(current_example_group) + KnapsackPro.tracker.start_timer + end + + config.append_after(:each) do + KnapsackPro.tracker.stop_timer + end + + config.after(:suite) do + KnapsackPro.logger.debug(KnapsackPro::Presenter.global_time) + end + end + end + + def bind_save_report + ::RSpec.configure do |config| + config.after(:suite) do + KnapsackPro::Report.save + end + end + end + + def bind_save_queue_report + ::RSpec.configure do |config| + config.after(:suite) do + KnapsackPro::Report.save_subset_queue_to_file + end + end + end + + def bind_tracker_reset + ::RSpec.configure do |config| + config.before(:suite) do + KnapsackPro.tracker.reset! + end + end + end + + def bind_before_queue_hook + ::RSpec.configure do |config| + config.before(:suite) do + unless ENV['KNAPSACK_PRO_BEFORE_QUEUE_HOOK_CALLED'] + KnapsackPro::Hooks::Queue.call_before_queue + ENV['KNAPSACK_PRO_BEFORE_QUEUE_HOOK_CALLED'] = 'true' + end + end + end + end + end + end +end diff --git a/lib/knapsack_pro/runners/test_unit_runner.rb b/lib/knapsack_pro/runners/test_unit_runner.rb new file mode 100644 index 00000000..c7a33437 --- /dev/null +++ b/lib/knapsack_pro/runners/test_unit_runner.rb @@ -0,0 +1,27 @@ +module KnapsackPro + module Runners + class TestUnitRunner < BaseRunner + def self.run(args) + ENV['KNAPSACK_PRO_TEST_SUITE_TOKEN'] = KnapsackPro::Config::Env.test_suite_token_test_unit + ENV['KNAPSACK_PRO_RECORDING_ENABLED'] = 'true' + + runner = new(KnapsackPro::Adapters::TestUnitAdapter) + + if runner.test_files_to_execute_exist? + #require 'rspec/core/rake_task' + + #task_name = 'knapsack_pro:test_unit_run' + #if Rake::Task.task_defined?(task_name) + #Rake::Task[task_name].clear + #end + + #RSpec::Core::RakeTask.new(task_name) do |t| + #t.rspec_opts = "#{args} --default-path #{runner.test_dir}" + #t.pattern = runner.test_file_paths + #end + #Rake::Task[task_name].invoke + end + end + end + end +end diff --git a/lib/tasks/test_unit.rake b/lib/tasks/test_unit.rake new file mode 100644 index 00000000..9a5b48da --- /dev/null +++ b/lib/tasks/test_unit.rake @@ -0,0 +1,7 @@ +require 'knapsack_pro' + +namespace :knapsack_pro do + task :test_unit, [:test_unit_args] do |_, args| + KnapsackPro::Runners::TestUnitRunner.run(args[:test_unit_args]) + end +end diff --git a/spec/knapsack_pro/adapters/test_unit_adapter_spec.rb b/spec/knapsack_pro/adapters/test_unit_adapter_spec.rb new file mode 100644 index 00000000..c319e0e0 --- /dev/null +++ b/spec/knapsack_pro/adapters/test_unit_adapter_spec.rb @@ -0,0 +1,147 @@ +describe KnapsackPro::Adapters::TestUnitAdapter do + it do + expect(described_class::TEST_DIR_PATTERN).to eq 'spec/**{,/*/**}/*_spec.rb' + end + + context do + before { expect(::RSpec).to receive(:configure) } + it_behaves_like 'adapter' + end + + describe '.test_path' do + let(:current_example_metadata) do + { + file_path: '1_shared_example.rb', + parent_example_group: { + file_path: '2_shared_example.rb', + parent_example_group: { + file_path: 'a_spec.rb' + } + } + } + end + + subject { described_class.test_path(current_example_metadata) } + + it { should eql 'a_spec.rb' } + + context 'with turnip features' do + describe 'when the turnip version is less than 2' do + let(:current_example_metadata) do + { + file_path: "./spec/features/logging_in.feature", + turnip: true, + parent_example_group: { + file_path: "gems/turnip-1.2.4/lib/turnip/rspec.rb" + } + } + end + + before { stub_const("Turnip::VERSION", '1.2.4') } + + it { should eql './spec/features/logging_in.feature' } + end + + describe 'when turnip is version 2 or greater' do + let(:current_example_metadata) do + { + file_path: "gems/turnip-2.0.0/lib/turnip/rspec.rb", + turnip: true, + parent_example_group: { + file_path: "./spec/features/logging_in.feature", + } + } + end + + before { stub_const("Turnip::VERSION", '2.0.0') } + + it { should eql './spec/features/logging_in.feature' } + end + end + end + + describe 'bind methods' do + let(:config) { double } + + describe '#bind_time_tracker' do + let(:tracker) { instance_double(KnapsackPro::Tracker) } + let(:logger) { instance_double(Logger) } + let(:test_path) { 'spec/a_spec.rb' } + let(:global_time) { 'Global time: 01m 05s' } + let(:example_group) { double } + let(:current_example) do + OpenStruct.new(metadata: { + example_group: example_group + }) + end + + it do + expect(config).to receive(:prepend_before).with(:each).and_yield + expect(config).to receive(:append_after).with(:each).and_yield + expect(config).to receive(:after).with(:suite).and_yield + expect(::RSpec).to receive(:configure).and_yield(config) + + expect(::RSpec).to receive(:current_example).twice.and_return(current_example) + expect(described_class).to receive(:test_path).with(example_group).and_return(test_path) + + allow(KnapsackPro).to receive(:tracker).and_return(tracker) + expect(tracker).to receive(:current_test_path=).with(test_path) + expect(tracker).to receive(:start_timer) + + expect(tracker).to receive(:stop_timer) + + expect(KnapsackPro::Presenter).to receive(:global_time).and_return(global_time) + expect(KnapsackPro).to receive(:logger).and_return(logger) + expect(logger).to receive(:debug).with(global_time) + + subject.bind_time_tracker + end + end + + describe '#bind_save_report' do + it do + expect(config).to receive(:after).with(:suite).and_yield + expect(::RSpec).to receive(:configure).and_yield(config) + + expect(KnapsackPro::Report).to receive(:save) + + subject.bind_save_report + end + end + + describe '#bind_save_queue_report' do + it do + expect(config).to receive(:after).with(:suite).and_yield + expect(::RSpec).to receive(:configure).and_yield(config) + + expect(KnapsackPro::Report).to receive(:save_subset_queue_to_file) + + subject.bind_save_queue_report + end + end + + describe '#bind_tracker_reset' do + it do + expect(config).to receive(:before).with(:suite).and_yield + expect(::RSpec).to receive(:configure).and_yield(config) + + tracker = instance_double(KnapsackPro::Tracker) + expect(KnapsackPro).to receive(:tracker).and_return(tracker) + expect(tracker).to receive(:reset!) + + subject.bind_tracker_reset + end + end + + describe '#bind_before_queue_hook' do + it do + expect(config).to receive(:before).with(:suite).and_yield + expect(::RSpec).to receive(:configure).and_yield(config) + + expect(KnapsackPro::Hooks::Queue).to receive(:call_before_queue) + + subject.bind_before_queue_hook + end + end + end +end diff --git a/spec/knapsack_pro/runners/test_unit_runner_spec.rb b/spec/knapsack_pro/runners/test_unit_runner_spec.rb new file mode 100644 index 00000000..49bbab83 --- /dev/null +++ b/spec/knapsack_pro/runners/test_unit_runner_spec.rb @@ -0,0 +1,83 @@ +require 'rspec/core/rake_task' + +describe KnapsackPro::Runners::TestUnitRunner do + subject { described_class.new(KnapsackPro::Adapters::TestUnitAdapter) } + + it { should be_kind_of KnapsackPro::Runners::BaseRunner } + + describe '.run' do + let(:args) { '--profile --color' } + + let(:test_suite_token_test_unit) { 'fake-token' } + + subject { described_class.run(args) } + + before do + expect(KnapsackPro::Config::Env).to receive(:test_suite_token_test_unit).and_return(test_suite_token_test_unit) + + expect(ENV).to receive(:[]=).with('KNAPSACK_PRO_TEST_SUITE_TOKEN_TEST_UNIT', test_suite_token_test_unit) + expect(ENV).to receive(:[]=).with('KNAPSACK_PRO_RECORDING_ENABLED', 'true') + + expect(described_class).to receive(:new) + .with(KnapsackPro::Adapters::TestUnitAdapter).and_return(runner) + end + + context 'when test files were returned by Knapsack Pro API' do + let(:test_dir) { 'fake-test-dir' } + let(:test_file_paths) { double(:test_file_paths) } + let(:runner) do + instance_double(described_class, + test_dir: test_dir, + test_file_paths: test_file_paths, + test_files_to_execute_exist?: true) + end + let(:task) { double } + + before do + #expect(Rake::Task).to receive(:[]).with('knapsack_pro:rspec_run').at_least(1).and_return(task) + + #t = double + #expect(RSpec::Core::RakeTask).to receive(:new).with('knapsack_pro:rspec_run').and_yield(t) + #expect(t).to receive(:rspec_opts=).with('--profile --color --default-path fake-test-dir') + #expect(t).to receive(:pattern=).with(test_file_paths) + end + + context 'when task already exists' do + before do + #expect(Rake::Task).to receive(:task_defined?).with('knapsack_pro:rspec_run').and_return(true) + #expect(task).to receive(:clear) + end + + it do + #result = double(:result) + #expect(task).to receive(:invoke).and_return(result) + #expect(subject).to eq result + end + end + + context "when task doesn't exist" do + before do + #expect(Rake::Task).to receive(:task_defined?).with('knapsack_pro:rspec_run').and_return(false) + #expect(task).not_to receive(:clear) + end + + it do + #result = double(:result) + #expect(task).to receive(:invoke).and_return(result) + #expect(subject).to eq result + end + end + end + + context 'when test files were not returned by Knapsack Pro API' do + let(:runner) do + instance_double(described_class, + test_files_to_execute_exist?: false) + end + + it "doesn't run tests" do + subject + end + end + end +end From 7ebff18214c32302d0fec08feadadb904c2852ae Mon Sep 17 00:00:00 2001 From: ArturT Date: Mon, 11 Sep 2017 22:51:56 +0200 Subject: [PATCH 06/20] Update test dir pattern --- lib/knapsack_pro/adapters/test_unit_adapter.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/knapsack_pro/adapters/test_unit_adapter.rb b/lib/knapsack_pro/adapters/test_unit_adapter.rb index a5eb5f43..a8bc6126 100644 --- a/lib/knapsack_pro/adapters/test_unit_adapter.rb +++ b/lib/knapsack_pro/adapters/test_unit_adapter.rb @@ -1,7 +1,7 @@ module KnapsackPro module Adapters class TestUnitAdapter < BaseAdapter - TEST_DIR_PATTERN = 'spec/**{,/*/**}/*_spec.rb' + TEST_DIR_PATTERN = 'test/**{,/*/**}/*_test.rb' def self.test_path(example_group) if defined?(Turnip) && Turnip::VERSION.to_i < 2 From 3f4e0dbe68925021f56398494b0ae38bb18c2aac Mon Sep 17 00:00:00 2001 From: ArturT Date: Mon, 11 Sep 2017 22:55:13 +0200 Subject: [PATCH 07/20] [wip] try to figure out how to run test-unit --- lib/knapsack_pro/runners/test_unit_runner.rb | 22 +++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/knapsack_pro/runners/test_unit_runner.rb b/lib/knapsack_pro/runners/test_unit_runner.rb index c7a33437..103b6af5 100644 --- a/lib/knapsack_pro/runners/test_unit_runner.rb +++ b/lib/knapsack_pro/runners/test_unit_runner.rb @@ -8,18 +8,20 @@ def self.run(args) runner = new(KnapsackPro::Adapters::TestUnitAdapter) if runner.test_files_to_execute_exist? - #require 'rspec/core/rake_task' + task_name = 'knapsack_pro:test_unit_run' - #task_name = 'knapsack_pro:test_unit_run' - #if Rake::Task.task_defined?(task_name) - #Rake::Task[task_name].clear - #end + if Rake::Task.task_defined?(task_name) + Rake::Task[task_name].clear + end - #RSpec::Core::RakeTask.new(task_name) do |t| - #t.rspec_opts = "#{args} --default-path #{runner.test_dir}" - #t.pattern = runner.test_file_paths - #end - #Rake::Task[task_name].invoke + Rake::TestTask.new(task_name) do |t| + t.warning = false + t.libs << runner.test_dir + t.test_files = runner.test_file_paths + t.options = args + end + + Rake::Task[task_name].invoke end end end From 3578b8fa2a560f2bb04af1fe2dc4c09e366eb555 Mon Sep 17 00:00:00 2001 From: ArturT Date: Sun, 17 Sep 2017 20:50:32 +0200 Subject: [PATCH 08/20] Test unit runner works. --- lib/knapsack_pro/runners/test_unit_runner.rb | 23 ++++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/lib/knapsack_pro/runners/test_unit_runner.rb b/lib/knapsack_pro/runners/test_unit_runner.rb index 103b6af5..39c95af0 100644 --- a/lib/knapsack_pro/runners/test_unit_runner.rb +++ b/lib/knapsack_pro/runners/test_unit_runner.rb @@ -8,20 +8,19 @@ def self.run(args) runner = new(KnapsackPro::Adapters::TestUnitAdapter) if runner.test_files_to_execute_exist? - task_name = 'knapsack_pro:test_unit_run' + require 'test/unit' - if Rake::Task.task_defined?(task_name) - Rake::Task[task_name].clear - end + cli_args = + (args || '').split + + runner.test_file_paths.map do |f| + File.expand_path(f) + end - Rake::TestTask.new(task_name) do |t| - t.warning = false - t.libs << runner.test_dir - t.test_files = runner.test_file_paths - t.options = args - end - - Rake::Task[task_name].invoke + exit Test::Unit::AutoRunner.run( + true, + runner.test_dir, + cli_args + ) end end end From 4be3f1211631ffe6494bd8b3b3c025175e0c2f64 Mon Sep 17 00:00:00 2001 From: ArturT Date: Sun, 17 Sep 2017 21:15:15 +0200 Subject: [PATCH 09/20] Remove unnecessary methods --- .../adapters/test_unit_adapter.rb | 27 ------------------- 1 file changed, 27 deletions(-) diff --git a/lib/knapsack_pro/adapters/test_unit_adapter.rb b/lib/knapsack_pro/adapters/test_unit_adapter.rb index a8bc6126..2bd7ba2b 100644 --- a/lib/knapsack_pro/adapters/test_unit_adapter.rb +++ b/lib/knapsack_pro/adapters/test_unit_adapter.rb @@ -49,33 +49,6 @@ def bind_save_report end end end - - def bind_save_queue_report - ::RSpec.configure do |config| - config.after(:suite) do - KnapsackPro::Report.save_subset_queue_to_file - end - end - end - - def bind_tracker_reset - ::RSpec.configure do |config| - config.before(:suite) do - KnapsackPro.tracker.reset! - end - end - end - - def bind_before_queue_hook - ::RSpec.configure do |config| - config.before(:suite) do - unless ENV['KNAPSACK_PRO_BEFORE_QUEUE_HOOK_CALLED'] - KnapsackPro::Hooks::Queue.call_before_queue - ENV['KNAPSACK_PRO_BEFORE_QUEUE_HOOK_CALLED'] = 'true' - end - end - end - end end end end From 66f3264eec0b78bc4f2a71d9c7046b4e9fa85a50 Mon Sep 17 00:00:00 2001 From: ArturT Date: Sun, 17 Sep 2017 22:06:02 +0200 Subject: [PATCH 10/20] Bind methods to show summary and save report for unit-test adapter. TODO: figure out how to track test files time execution --- .../adapters/test_unit_adapter.rb | 69 ++++++++++--------- 1 file changed, 36 insertions(+), 33 deletions(-) diff --git a/lib/knapsack_pro/adapters/test_unit_adapter.rb b/lib/knapsack_pro/adapters/test_unit_adapter.rb index 2bd7ba2b..7b4907ca 100644 --- a/lib/knapsack_pro/adapters/test_unit_adapter.rb +++ b/lib/knapsack_pro/adapters/test_unit_adapter.rb @@ -4,49 +4,52 @@ class TestUnitAdapter < BaseAdapter TEST_DIR_PATTERN = 'test/**{,/*/**}/*_test.rb' 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 + #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] + #example_group[:file_path] end 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 - KnapsackPro.tracker.current_test_path = KnapsackPro::Adapters::RSpecAdapter.test_path(current_example_group) - KnapsackPro.tracker.start_timer - end + #Test::Unit.at_start do |a, b| + #require 'pry'; binding.pry + ##KnapsackPro.tracker.current_test_path = KnapsackPro::Adapters::RSpecAdapter.test_path(current_example_group) + ##KnapsackPro.tracker.start_timer + #end + #::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 + #KnapsackPro.tracker.current_test_path = KnapsackPro::Adapters::RSpecAdapter.test_path(current_example_group) + #KnapsackPro.tracker.start_timer + #end - config.append_after(:each) do - KnapsackPro.tracker.stop_timer - end + #config.append_after(:each) do + #KnapsackPro.tracker.stop_timer + #end + #end - config.after(:suite) do - KnapsackPro.logger.debug(KnapsackPro::Presenter.global_time) - end + Test::Unit.at_exit do + KnapsackPro.logger.debug(KnapsackPro::Presenter.global_time) end end def bind_save_report - ::RSpec.configure do |config| - config.after(:suite) do - KnapsackPro::Report.save - end + Test::Unit.at_exit do + KnapsackPro::Report.save end end end From 4d9d603aee6878f693845b9a6c1a375f49ce431d Mon Sep 17 00:00:00 2001 From: ArturT Date: Sun, 17 Sep 2017 22:33:46 +0200 Subject: [PATCH 11/20] [wip] plugin to set global setup/teardown --- .../adapters/test_unit_adapter.rb | 40 +++++++++---------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/lib/knapsack_pro/adapters/test_unit_adapter.rb b/lib/knapsack_pro/adapters/test_unit_adapter.rb index 7b4907ca..588faffb 100644 --- a/lib/knapsack_pro/adapters/test_unit_adapter.rb +++ b/lib/knapsack_pro/adapters/test_unit_adapter.rb @@ -19,28 +19,26 @@ def self.test_path(example_group) #example_group[:file_path] end - def bind_time_tracker - #Test::Unit.at_start do |a, b| - #require 'pry'; binding.pry - ##KnapsackPro.tracker.current_test_path = KnapsackPro::Adapters::RSpecAdapter.test_path(current_example_group) - ##KnapsackPro.tracker.start_timer - #end - #::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 - #KnapsackPro.tracker.current_test_path = KnapsackPro::Adapters::RSpecAdapter.test_path(current_example_group) - #KnapsackPro.tracker.start_timer - #end + # FIXME + 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 + end - #config.append_after(:each) do - #KnapsackPro.tracker.stop_timer - #end - #end + def teardown + #KnapsackPro.tracker.stop_timer + puts '/'*10 + puts 'SETUP teardown' + super + end + end + + def bind_time_tracker + Test::Unit::TestCase.send(:include, BindTimeTrackerTestUnitPlugin) Test::Unit.at_exit do KnapsackPro.logger.debug(KnapsackPro::Presenter.global_time) From 0803311146c5e984788270e48c8d07218ef1f03f Mon Sep 17 00:00:00 2001 From: ArturT Date: Sun, 1 Oct 2017 19:22:29 +0200 Subject: [PATCH 12/20] TestUnit adapter works. --- .../adapters/test_unit_adapter.rb | 63 +++++++++++-------- 1 file changed, 36 insertions(+), 27 deletions(-) diff --git a/lib/knapsack_pro/adapters/test_unit_adapter.rb b/lib/knapsack_pro/adapters/test_unit_adapter.rb index 588faffb..b0b4ed75 100644 --- a/lib/knapsack_pro/adapters/test_unit_adapter.rb +++ b/lib/knapsack_pro/adapters/test_unit_adapter.rb @@ -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) @@ -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 From 305918a0d881348ebcf9fbfcbd345c59648b831c Mon Sep 17 00:00:00 2001 From: ArturT Date: Sun, 1 Oct 2017 21:15:18 +0200 Subject: [PATCH 13/20] Fix spec for TestUnitRunner --- .../runners/test_unit_runner_spec.rb | 88 +++++++------------ 1 file changed, 31 insertions(+), 57 deletions(-) diff --git a/spec/knapsack_pro/runners/test_unit_runner_spec.rb b/spec/knapsack_pro/runners/test_unit_runner_spec.rb index 49bbab83..653b3a25 100644 --- a/spec/knapsack_pro/runners/test_unit_runner_spec.rb +++ b/spec/knapsack_pro/runners/test_unit_runner_spec.rb @@ -1,4 +1,4 @@ -require 'rspec/core/rake_task' +require 'test/unit' describe KnapsackPro::Runners::TestUnitRunner do subject { described_class.new(KnapsackPro::Adapters::TestUnitAdapter) } @@ -6,76 +6,50 @@ it { should be_kind_of KnapsackPro::Runners::BaseRunner } describe '.run' do - let(:args) { '--profile --color' } - - let(:test_suite_token_test_unit) { 'fake-token' } + let(:args) { '--verbose --order=random' } subject { described_class.run(args) } before do - expect(KnapsackPro::Config::Env).to receive(:test_suite_token_test_unit).and_return(test_suite_token_test_unit) - - expect(ENV).to receive(:[]=).with('KNAPSACK_PRO_TEST_SUITE_TOKEN_TEST_UNIT', test_suite_token_test_unit) - expect(ENV).to receive(:[]=).with('KNAPSACK_PRO_RECORDING_ENABLED', 'true') - - expect(described_class).to receive(:new) - .with(KnapsackPro::Adapters::TestUnitAdapter).and_return(runner) + stub_const("ENV", { 'KNAPSACK_PRO_TEST_SUITE_TOKEN_TEST_UNIT' => 'test-unit-token' }) end context 'when test files were returned by Knapsack Pro API' do - let(:test_dir) { 'fake-test-dir' } - let(:test_file_paths) { double(:test_file_paths) } - let(:runner) do - instance_double(described_class, - test_dir: test_dir, - test_file_paths: test_file_paths, - test_files_to_execute_exist?: true) - end - let(:task) { double } - - before do - #expect(Rake::Task).to receive(:[]).with('knapsack_pro:rspec_run').at_least(1).and_return(task) - - #t = double - #expect(RSpec::Core::RakeTask).to receive(:new).with('knapsack_pro:rspec_run').and_yield(t) - #expect(t).to receive(:rspec_opts=).with('--profile --color --default-path fake-test-dir') - #expect(t).to receive(:pattern=).with(test_file_paths) - end + it 'runs tests' do + test_file_paths = ['test-unit_fake/a_test.rb', 'test-unit_fake/b_test.rb'] + runner = instance_double(described_class, + test_dir: 'test-unit_fake', + test_file_paths: test_file_paths, + test_files_to_execute_exist?: true) + expect(described_class).to receive(:new) + .with(KnapsackPro::Adapters::TestUnitAdapter).and_return(runner) + + auto_runner_exit_code = 0 + expect(Test::Unit::AutoRunner).to receive(:run) do |flag, test_dir, cli_args| + expect(flag).to be true + expect(test_dir).to eq 'test-unit_fake' + expect(cli_args.size).to eq 4 + expect(cli_args[0]).to eq '--verbose' + expect(cli_args[1]).to eq '--order=random' + expect(cli_args[2]).to end_with 'test-unit_fake/a_test.rb' + expect(cli_args[3]).to end_with 'test-unit_fake/b_test.rb' + end.and_return(auto_runner_exit_code) + expect(described_class).to receive(:exit).with(auto_runner_exit_code) - context 'when task already exists' do - before do - #expect(Rake::Task).to receive(:task_defined?).with('knapsack_pro:rspec_run').and_return(true) - #expect(task).to receive(:clear) - end - - it do - #result = double(:result) - #expect(task).to receive(:invoke).and_return(result) - #expect(subject).to eq result - end - end - - context "when task doesn't exist" do - before do - #expect(Rake::Task).to receive(:task_defined?).with('knapsack_pro:rspec_run').and_return(false) - #expect(task).not_to receive(:clear) - end + subject - it do - #result = double(:result) - #expect(task).to receive(:invoke).and_return(result) - #expect(subject).to eq result - end + expect(ENV['KNAPSACK_PRO_TEST_SUITE_TOKEN']).to eq 'test-unit-token' + expect(ENV['KNAPSACK_PRO_RECORDING_ENABLED']).to eq 'true' end end context 'when test files were not returned by Knapsack Pro API' do - let(:runner) do - instance_double(described_class, - test_files_to_execute_exist?: false) - end - it "doesn't run tests" do + runner = instance_double(described_class, + test_files_to_execute_exist?: false) + expect(described_class).to receive(:new) + .with(KnapsackPro::Adapters::TestUnitAdapter).and_return(runner) + subject end end From 60a98776071aab9bcd9d9c1e0ee65727ff47dc4d Mon Sep 17 00:00:00 2001 From: ArturT Date: Sun, 1 Oct 2017 22:00:54 +0200 Subject: [PATCH 14/20] Fix tests for TestUnitAdapter --- .../adapters/test_unit_adapter.rb | 12 +- .../adapters/test_unit_adapter_spec.rb | 131 +++++------------- 2 files changed, 42 insertions(+), 101 deletions(-) diff --git a/lib/knapsack_pro/adapters/test_unit_adapter.rb b/lib/knapsack_pro/adapters/test_unit_adapter.rb index b0b4ed75..0ad2aac5 100644 --- a/lib/knapsack_pro/adapters/test_unit_adapter.rb +++ b/lib/knapsack_pro/adapters/test_unit_adapter.rb @@ -44,13 +44,13 @@ def run_shutdown(result) def bind_time_tracker Test::Unit::TestSuite.send(:prepend, BindTimeTrackerTestUnitPlugin) - Test::Unit.at_exit do + add_post_run_callback do KnapsackPro.logger.debug(KnapsackPro::Presenter.global_time) end end def bind_save_report - Test::Unit.at_exit do + add_post_run_callback do KnapsackPro::Report.save end end @@ -59,6 +59,14 @@ 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 + + def add_post_run_callback(&block) + Test::Unit.at_exit do + block.call + end + end end end end diff --git a/spec/knapsack_pro/adapters/test_unit_adapter_spec.rb b/spec/knapsack_pro/adapters/test_unit_adapter_spec.rb index c319e0e0..30eac436 100644 --- a/spec/knapsack_pro/adapters/test_unit_adapter_spec.rb +++ b/spec/knapsack_pro/adapters/test_unit_adapter_spec.rb @@ -1,94 +1,50 @@ +require 'test/unit/testcase' + describe KnapsackPro::Adapters::TestUnitAdapter do it do - expect(described_class::TEST_DIR_PATTERN).to eq 'spec/**{,/*/**}/*_spec.rb' - end - - context do - before { expect(::RSpec).to receive(:configure) } - it_behaves_like 'adapter' + expect(described_class::TEST_DIR_PATTERN).to eq 'test/**{,/*/**}/*_test.rb' end describe '.test_path' do - let(:current_example_metadata) do - { - file_path: '1_shared_example.rb', - parent_example_group: { - file_path: '2_shared_example.rb', - parent_example_group: { - file_path: 'a_spec.rb' - } - } - } - end + subject { described_class.test_path(obj) } - subject { described_class.test_path(current_example_metadata) } - - it { should eql 'a_spec.rb' } + before do + parent_of_test_dir = File.expand_path('../../../', File.dirname(__FILE__)) + parent_of_test_dir_regexp = Regexp.new("^#{parent_of_test_dir}") + described_class.class_variable_set(:@@parent_of_test_dir, parent_of_test_dir_regexp) + end - context 'with turnip features' do - describe 'when the turnip version is less than 2' do - let(:current_example_metadata) do - { - file_path: "./spec/features/logging_in.feature", - turnip: true, - parent_example_group: { - file_path: "gems/turnip-1.2.4/lib/turnip/rspec.rb" - } - } + context 'when regular test' do + class FakeTestUnitTest + def method_name + "test_something" end - before { stub_const("Turnip::VERSION", '1.2.4') } - - it { should eql './spec/features/logging_in.feature' } + def test_something + end end - describe 'when turnip is version 2 or greater' do - let(:current_example_metadata) do - { - file_path: "gems/turnip-2.0.0/lib/turnip/rspec.rb", - turnip: true, - parent_example_group: { - file_path: "./spec/features/logging_in.feature", - } - } + class FakeTestUnitTestSuite + def tests + [FakeTestUnitTest.new] end + end - before { stub_const("Turnip::VERSION", '2.0.0') } + let(:obj) { FakeTestUnitTestSuite.new } - it { should eql './spec/features/logging_in.feature' } - end + it { should eq './spec/knapsack_pro/adapters/test_unit_adapter_spec.rb' } end end describe 'bind methods' do - let(:config) { double } - describe '#bind_time_tracker' do - let(:tracker) { instance_double(KnapsackPro::Tracker) } let(:logger) { instance_double(Logger) } - let(:test_path) { 'spec/a_spec.rb' } let(:global_time) { 'Global time: 01m 05s' } - let(:example_group) { double } - let(:current_example) do - OpenStruct.new(metadata: { - example_group: example_group - }) - end it do - expect(config).to receive(:prepend_before).with(:each).and_yield - expect(config).to receive(:append_after).with(:each).and_yield - expect(config).to receive(:after).with(:suite).and_yield - expect(::RSpec).to receive(:configure).and_yield(config) - - expect(::RSpec).to receive(:current_example).twice.and_return(current_example) - expect(described_class).to receive(:test_path).with(example_group).and_return(test_path) - - allow(KnapsackPro).to receive(:tracker).and_return(tracker) - expect(tracker).to receive(:current_test_path=).with(test_path) - expect(tracker).to receive(:start_timer) + expect(Test::Unit::TestSuite).to receive(:send).with(:prepend, KnapsackPro::Adapters::TestUnitAdapter::BindTimeTrackerTestUnitPlugin) - expect(tracker).to receive(:stop_timer) + expect(subject).to receive(:add_post_run_callback).and_yield expect(KnapsackPro::Presenter).to receive(:global_time).and_return(global_time) expect(KnapsackPro).to receive(:logger).and_return(logger) @@ -100,48 +56,25 @@ describe '#bind_save_report' do it do - expect(config).to receive(:after).with(:suite).and_yield - expect(::RSpec).to receive(:configure).and_yield(config) + expect(subject).to receive(:add_post_run_callback).and_yield expect(KnapsackPro::Report).to receive(:save) subject.bind_save_report end end + end - describe '#bind_save_queue_report' do - it do - expect(config).to receive(:after).with(:suite).and_yield - expect(::RSpec).to receive(:configure).and_yield(config) - - expect(KnapsackPro::Report).to receive(:save_subset_queue_to_file) - - subject.bind_save_queue_report - end - end - - describe '#bind_tracker_reset' do - it do - expect(config).to receive(:before).with(:suite).and_yield - expect(::RSpec).to receive(:configure).and_yield(config) + describe '#set_test_helper_path' do + let(:adapter) { described_class.new } + let(:test_helper_path) { '/code/project/test/test_helper.rb' } - tracker = instance_double(KnapsackPro::Tracker) - expect(KnapsackPro).to receive(:tracker).and_return(tracker) - expect(tracker).to receive(:reset!) + subject { adapter.set_test_helper_path(test_helper_path) } - subject.bind_tracker_reset - end + after do + expect(described_class.class_variable_get(:@@parent_of_test_dir)).to eq '/code/project' end - describe '#bind_before_queue_hook' do - it do - expect(config).to receive(:before).with(:suite).and_yield - expect(::RSpec).to receive(:configure).and_yield(config) - - expect(KnapsackPro::Hooks::Queue).to receive(:call_before_queue) - - subject.bind_before_queue_hook - end - end + it { should eql '/code/project' } end end From 553cfb3726c395bb1db9604f339dd874d169f4a8 Mon Sep 17 00:00:00 2001 From: ArturT Date: Mon, 2 Oct 2017 22:13:06 +0200 Subject: [PATCH 15/20] Add support for binary for test-unit --- bin/knapsack_pro | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/knapsack_pro b/bin/knapsack_pro index 6dc46f89..8b69de1e 100755 --- a/bin/knapsack_pro +++ b/bin/knapsack_pro @@ -10,6 +10,7 @@ MAP = { 'queue:rspec' => KnapsackPro::Runners::Queue::RSpecRunner, 'cucumber' => KnapsackPro::Runners::CucumberRunner, 'minitest' => KnapsackPro::Runners::MinitestRunner, + 'test_unit' => KnapsackPro::Runners::TestUnitRunner, 'spinach' => KnapsackPro::Runners::SpinachRunner, } From 6c3f36a0083b7c8733b6566960dac0cf014a0606 Mon Sep 17 00:00:00 2001 From: ArturT Date: Mon, 2 Oct 2017 22:15:02 +0200 Subject: [PATCH 16/20] Allow to encrypt test files for test-unit --- lib/tasks/encrypted_test_file_names.rake | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/tasks/encrypted_test_file_names.rake b/lib/tasks/encrypted_test_file_names.rake index df5b4320..80fd4328 100644 --- a/lib/tasks/encrypted_test_file_names.rake +++ b/lib/tasks/encrypted_test_file_names.rake @@ -9,12 +9,14 @@ namespace :knapsack_pro do KnapsackPro::Adapters::RSpecAdapter when 'minitest' KnapsackPro::Adapters::MinitestAdapter + when 'test_unit' + KnapsackPro::Adapters::TestUnitAdapter when 'cucumber' KnapsackPro::Adapters::CucumberAdapter when 'spinach' KnapsackPro::Adapters::SpinachAdapter else - raise('Provide adapter name like rspec, minitest, cucumber, spinach') + raise('Provide adapter name like rspec, minitest, test_unit, cucumber, spinach') end test_file_pattern = KnapsackPro::TestFilePattern.call(adapter_class) From 1030bbf654a56090b6dcde5ecad235077628a3d9 Mon Sep 17 00:00:00 2001 From: ArturT Date: Mon, 2 Oct 2017 22:20:41 +0200 Subject: [PATCH 17/20] Fix typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c8ae17d6..d82e9f63 100644 --- a/README.md +++ b/README.md @@ -294,7 +294,7 @@ Set one or more tokens depending on how many test suites you run on CI server. * `KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC` - as value set token for rspec test suite. Token can be generated when you sign in to [knapsackpro.com](http://www.knapsackpro.com). * `KNAPSACK_PRO_TEST_SUITE_TOKEN_CUCUMBER` - token for cucumber test suite. * `KNAPSACK_PRO_TEST_SUITE_TOKEN_MINITEST` - token for minitest test suite. -* `KNAPSACK_PRO_TEST_SUITE_TOKEN_SPINACH` - token for minitest test suite. +* `KNAPSACK_PRO_TEST_SUITE_TOKEN_SPINACH` - token for spinach test suite. __Tip:__ In case you have for instance multiple rspec test suites then prepend each of knapsack_pro command which executes tests with `KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC` variable. From 1d7d605925add72c5dcdba68abebaae1b5db2bf4 Mon Sep 17 00:00:00 2001 From: ArturT Date: Mon, 2 Oct 2017 22:22:34 +0200 Subject: [PATCH 18/20] Add info how to use test-unit in readme --- README.md | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 59 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index d82e9f63..9fd23755 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ The knapsack_pro gem supports: * [RSpec](http://rspec.info) * [Cucumber](https://cucumber.io) * [Minitest](http://docs.seattlerb.org/minitest/) +* [test-unit](https://github.com/test-unit/test-unit) * [Spinach](https://github.com/codegram/spinach) * [Turnip](https://github.com/jnicklas/turnip) @@ -62,6 +63,7 @@ The knapsack_pro has also [queue mode](#queue-mode) to get an optimal test suite - [Step for RSpec](#step-for-rspec) - [Step for Cucumber](#step-for-cucumber) - [Step for Minitest](#step-for-minitest) + - [Step for test-unit](#step-for-test-unit) - [Step for Spinach](#step-for-spinach) - [Custom configuration](#custom-configuration) - [Setup your CI server (How to set up 2 of 3)](#setup-your-ci-server-how-to-set-up-2-of-3) @@ -86,6 +88,7 @@ The knapsack_pro has also [queue mode](#queue-mode) to get an optimal test suite - [Passing arguments to rspec](#passing-arguments-to-rspec) - [Passing arguments to cucumber](#passing-arguments-to-cucumber) - [Passing arguments to minitest](#passing-arguments-to-minitest) + - [Passing arguments to test-unit](#passing-arguments-to-test-unit) - [Passing arguments to spinach](#passing-arguments-to-spinach) - [Knapsack Pro binary](#knapsack-pro-binary) - [Test file names encryption](#test-file-names-encryption) @@ -260,6 +263,19 @@ knapsack_pro_adapter = KnapsackPro::Adapters::MinitestAdapter.bind knapsack_pro_adapter.set_test_helper_path(__FILE__) ``` +#### Step for test-unit + +Add at the beginning of your `test_helper.rb`: + +```ruby +require 'knapsack_pro' + +# CUSTOM_CONFIG_GOES_HERE + +knapsack_pro_adapter = KnapsackPro::Adapters::TestUnitAdapter.bind +knapsack_pro_adapter.set_test_helper_path(__FILE__) +``` + #### Step for Spinach Create file `features/support/knapsack_pro.rb` and add there: @@ -274,7 +290,7 @@ KnapsackPro::Adapters::SpinachAdapter.bind #### Custom configuration -You can change the default Knapsack Pro configuration for RSpec, Cucumber, Minitest or Spinach tests. Here are examples what you can do. Put the configuration below in place of `CUSTOM_CONFIG_GOES_HERE` (in the configuration samples above). +You can change the default Knapsack Pro configuration for RSpec, Cucumber, Minitest, test-unit or Spinach tests. Here are examples what you can do. Put the configuration below in place of `CUSTOM_CONFIG_GOES_HERE` (in the configuration samples above). ```ruby # you can use your own logger @@ -294,6 +310,7 @@ Set one or more tokens depending on how many test suites you run on CI server. * `KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC` - as value set token for rspec test suite. Token can be generated when you sign in to [knapsackpro.com](http://www.knapsackpro.com). * `KNAPSACK_PRO_TEST_SUITE_TOKEN_CUCUMBER` - token for cucumber test suite. * `KNAPSACK_PRO_TEST_SUITE_TOKEN_MINITEST` - token for minitest test suite. +* `KNAPSACK_PRO_TEST_SUITE_TOKEN_TEST_UNIT` - token for test-unit test suite. * `KNAPSACK_PRO_TEST_SUITE_TOKEN_SPINACH` - token for spinach test suite. __Tip:__ In case you have for instance multiple rspec test suites then prepend each of knapsack_pro command which executes tests with `KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC` variable. @@ -311,6 +328,9 @@ On your CI server run this command for the first CI node. Update `KNAPSACK_PRO_C # Step for Minitest $ KNAPSACK_PRO_CI_NODE_TOTAL=2 KNAPSACK_PRO_CI_NODE_INDEX=0 bundle exec rake knapsack_pro:minitest + # Step for test-unit + $ KNAPSACK_PRO_CI_NODE_TOTAL=2 KNAPSACK_PRO_CI_NODE_INDEX=0 bundle exec rake knapsack_pro:test_unit + # Step for Spinach $ KNAPSACK_PRO_CI_NODE_TOTAL=2 KNAPSACK_PRO_CI_NODE_INDEX=0 bundle exec rake knapsack_pro:spinach @@ -325,6 +345,9 @@ You can add `KNAPSACK_PRO_TEST_FILE_PATTERN` if your tests are not in default di # Step for Minitest $ KNAPSACK_PRO_TEST_FILE_PATTERN="directory_with_tests/**{,/*/**}/*_test.rb" KNAPSACK_PRO_CI_NODE_TOTAL=2 KNAPSACK_PRO_CI_NODE_INDEX=0 bundle exec rake knapsack_pro:minitest + # Step for test-unit + $ KNAPSACK_PRO_TEST_FILE_PATTERN="directory_with_tests/**{,/*/**}/*_test.rb" KNAPSACK_PRO_CI_NODE_TOTAL=2 KNAPSACK_PRO_CI_NODE_INDEX=0 bundle exec rake knapsack_pro:test_unit + # Step for Spinach $ KNAPSACK_PRO_TEST_FILE_PATTERN="directory_with_features/**{,/*/**}/*.feature" KNAPSACK_PRO_CI_NODE_TOTAL=2 KNAPSACK_PRO_CI_NODE_INDEX=0 bundle exec rake knapsack_pro:spinach @@ -533,6 +556,16 @@ For instance to run verbose tests: $ bundle exec rake "knapsack_pro:minitest[--verbose]" +#### Passing arguments to test-unit + +Add arguments to knapsack_pro test-unit task like this: + + $ bundle exec rake "knapsack_pro:test_unit[--arg_name value]" + +For instance to run verbose tests: + + $ bundle exec rake "knapsack_pro:test_unit[--verbose]" + #### Passing arguments to spinach Add arguments to knapsack_pro spinach task like this: @@ -547,6 +580,7 @@ You can install knapsack_pro globally and use binary. For instance: $ knapsack_pro queue:rspec "--tag custom_tag_name --profile" $ knapsack_pro cucumber "--name feature" $ knapsack_pro minitest "--verbose --pride" + $ knapsack_pro test_unit "--verbose" $ knapsack_pro spinach "--arg_name value" This is optional way of using knapsack_pro when you don't want to add it to `Gemfile`. @@ -580,7 +614,7 @@ If you need to check what is the encryption hash for particular test file you ca $ KNAPSACK_PRO_SALT=xxx bundle exec rake knapsack_pro:encrypted_test_file_names[rspec] -You can pass the name of test runner like `rspec`, `minitest`, `cucumber`, `spinach` as argument to rake task. +You can pass the name of test runner like `rspec`, `minitest`, `test_unit`, `cucumber`, `spinach` as argument to rake task. #### How to enable branch names encryption? @@ -621,6 +655,7 @@ machine: # KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC: rspec-token # KNAPSACK_PRO_TEST_SUITE_TOKEN_CUCUMBER: cucumber-token # KNAPSACK_PRO_TEST_SUITE_TOKEN_MINITEST: minitest-token + # KNAPSACK_PRO_TEST_SUITE_TOKEN_TEST_UNIT: test-unit-token # KNAPSACK_PRO_TEST_SUITE_TOKEN_SPINACH: spinach-token test: override: @@ -636,6 +671,10 @@ test: - bundle exec rake knapsack_pro:minitest: parallel: true # Caution: there are 8 spaces indentation! + # Step for test-unit + - bundle exec rake knapsack_pro:test_unit: + parallel: true # Caution: there are 8 spaces indentation! + # Step for Spinach - bundle exec rake knapsack_pro:spinach: parallel: true # Caution: there are 8 spaces indentation! @@ -707,6 +746,9 @@ script: # Step for Minitest - "bundle exec rake knapsack_pro:minitest" + # Step for test-unit + - "bundle exec rake knapsack_pro:test_unit" + # Step for Spinach - "bundle exec rake knapsack_pro:spinach" @@ -716,6 +758,7 @@ env: - KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC=rspec-token - KNAPSACK_PRO_TEST_SUITE_TOKEN_CUCUMBER=cucumber-token - KNAPSACK_PRO_TEST_SUITE_TOKEN_MINITEST=minitest-token + - KNAPSACK_PRO_TEST_SUITE_TOKEN_TEST_UNIT=test-unit-token - KNAPSACK_PRO_TEST_SUITE_TOKEN_SPINACH=spinach-token - KNAPSACK_PRO_CI_NODE_TOTAL=2 @@ -726,14 +769,14 @@ env: Such configuration will generate matrix with 2 following ENV rows: - KNAPSACK_PRO_CI_NODE_TOTAL=2 KNAPSACK_PRO_CI_NODE_INDEX=0 KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC=rspec-token KNAPSACK_PRO_TEST_SUITE_TOKEN_CUCUMBER=cucumber-token KNAPSACK_PRO_TEST_SUITE_TOKEN_MINITEST=minitest-token KNAPSACK_PRO_TEST_SUITE_TOKEN_SPINACH=spinach-token - KNAPSACK_PRO_CI_NODE_TOTAL=2 KNAPSACK_PRO_CI_NODE_INDEX=1 KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC=rspec-token KNAPSACK_PRO_TEST_SUITE_TOKEN_CUCUMBER=cucumber-token KNAPSACK_PRO_TEST_SUITE_TOKEN_MINITEST=minitest-token KNAPSACK_PRO_TEST_SUITE_TOKEN_SPINACH=spinach-token + KNAPSACK_PRO_CI_NODE_TOTAL=2 KNAPSACK_PRO_CI_NODE_INDEX=0 KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC=rspec-token KNAPSACK_PRO_TEST_SUITE_TOKEN_CUCUMBER=cucumber-token KNAPSACK_PRO_TEST_SUITE_TOKEN_MINITEST=minitest-token KNAPSACK_PRO_TEST_SUITE_TOKEN_TEST_UNIT=test-unit-token KNAPSACK_PRO_TEST_SUITE_TOKEN_SPINACH=spinach-token + KNAPSACK_PRO_CI_NODE_TOTAL=2 KNAPSACK_PRO_CI_NODE_INDEX=1 KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC=rspec-token KNAPSACK_PRO_TEST_SUITE_TOKEN_CUCUMBER=cucumber-token KNAPSACK_PRO_TEST_SUITE_TOKEN_MINITEST=minitest-token KNAPSACK_PRO_TEST_SUITE_TOKEN_TEST_UNIT=test-unit-token KNAPSACK_PRO_TEST_SUITE_TOKEN_SPINACH=spinach-token More info about global and matrix ENV configuration in [travis docs](https://docs.travis-ci.com/user/customizing-the-build/#Build-Matrix). #### Info for semaphoreapp.com users -Knapsack Pro supports semaphoreapp ENVs `SEMAPHORE_THREAD_COUNT` and `SEMAPHORE_CURRENT_THREAD`. The only thing you need to do is set up knapsack_pro rspec/cucumber/minitest command for as many threads as you need. Here is an example: +Knapsack Pro supports semaphoreapp ENVs `SEMAPHORE_THREAD_COUNT` and `SEMAPHORE_CURRENT_THREAD`. The only thing you need to do is set up knapsack_pro rspec/cucumber/minitest/test_unit command for as many threads as you need. Here is an example: # Thread 1 ## Step for RSpec @@ -742,6 +785,8 @@ Knapsack Pro supports semaphoreapp ENVs `SEMAPHORE_THREAD_COUNT` and `SEMAPHORE_ bundle exec rake knapsack_pro:cucumber ## Step for Minitest bundle exec rake knapsack_pro:minitest + ## Step for test-unit + bundle exec rake knapsack_pro:test_unit ## Step for Spinach bundle exec rake knapsack_pro:spinach @@ -752,6 +797,8 @@ Knapsack Pro supports semaphoreapp ENVs `SEMAPHORE_THREAD_COUNT` and `SEMAPHORE_ bundle exec rake knapsack_pro:cucumber ## Step for Minitest bundle exec rake knapsack_pro:minitest + ## Step for test-unit + bundle exec rake knapsack_pro:test_unit ## Step for Spinach bundle exec rake knapsack_pro:spinach @@ -772,6 +819,9 @@ Knapsack Pro supports buildkite ENVs `BUILDKITE_PARALLEL_JOB_COUNT` and `BUILDKI # Step for Minitest bundle exec rake knapsack_pro:minitest + # Step for test-unit + bundle exec rake knapsack_pro:test_unit + # Step for Spinach bundle exec rake knapsack_pro:spinach @@ -863,6 +913,9 @@ Knapsack Pro supports snap-ci.com ENVs `SNAP_WORKER_TOTAL` and `SNAP_WORKER_INDE # Step for Minitest bundle exec rake knapsack_pro:minitest + # Step for test-unit + bundle exec rake knapsack_pro:test_unit + # Step for Spinach bundle exec rake knapsack_pro:spinach @@ -1030,7 +1083,7 @@ For instance to run subset of tests for the first CI node with specified seed yo KNAPSACK_PRO_CI_NODE_INDEX=0 \ bundle exec rake "knapsack_pro:rspec[--seed 123]" -Above example is for RSpec. You can use respectively rake task name and token environment variable when you want to run tests for minitest, cucumber or spinach. +Above example is for RSpec. You can use respectively rake task name and token environment variable when you want to run tests for minitest, test_unit, cucumber or spinach. It should work when all CI nodes finished work and sent time execution data to Knapsack Pro API. You can visit [user dashboard](https://knapsackpro.com/dashboard) to preview particular CI build and ensure time execution data were collected from all CI nodes. If at least one CI node has not sent time execution data to the Knapsack Pro API then you should check below solution. From 11ab8d6c1ed503d67275f49dae82ee50b193126b Mon Sep 17 00:00:00 2001 From: ArturT Date: Mon, 2 Oct 2017 22:31:19 +0200 Subject: [PATCH 19/20] Fix build --- circle.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/circle.yml b/circle.yml index 0003f835..2d48a9b2 100644 --- a/circle.yml +++ b/circle.yml @@ -3,3 +3,9 @@ machine: version: 2.4.0 environment: CODECLIMATE_REPO_TOKEN: b6626e682a8e97e0c5978febc92c3526792a2d018b41b8e1b52689da37fb7d92 +test: + override: + # specify command explicitly because CircleCI 1.0 adds arguments to RSpec + # bundle exec rspec "--color --require spec_helper --format documentation" "" "spec" + # and this cause error for tests because in tests we load test-unit gem + - bundle exec rspec spec From 3191fa6bbd1e37402493ac4cedf67d10a3a4c15a Mon Sep 17 00:00:00 2001 From: ArturT Date: Mon, 2 Oct 2017 22:36:57 +0200 Subject: [PATCH 20/20] Update description --- circle.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/circle.yml b/circle.yml index 2d48a9b2..a4879f56 100644 --- a/circle.yml +++ b/circle.yml @@ -5,7 +5,8 @@ machine: CODECLIMATE_REPO_TOKEN: b6626e682a8e97e0c5978febc92c3526792a2d018b41b8e1b52689da37fb7d92 test: override: - # specify command explicitly because CircleCI 1.0 adds arguments to RSpec - # bundle exec rspec "--color --require spec_helper --format documentation" "" "spec" - # and this cause error for tests because in tests we load test-unit gem + # Specify command explicitly because CircleCI 1.0 adds arguments to RSpec + # $ bundle exec rspec "--color --require spec_helper --format documentation" "" "spec" + # and this cause error because in tests we load test-unit gem that tries to parse + # the unknown arguments. - bundle exec rspec spec