From 90c96f43e2286e7fc190246455c13169babcbbdd Mon Sep 17 00:00:00 2001 From: Feng Sha Date: Thu, 29 Oct 2020 16:39:50 -0400 Subject: [PATCH 01/12] allow accept file containing test files --- lib/knapsack_pro/config/env.rb | 4 ++++ lib/knapsack_pro/test_file_finder.rb | 4 ++++ spec/knapsack_pro/test_file_finder_spec.rb | 18 ++++++++++++++++++ spec_fake/fake_test | 4 ++++ 4 files changed, 30 insertions(+) create mode 100644 spec_fake/fake_test diff --git a/lib/knapsack_pro/config/env.rb b/lib/knapsack_pro/config/env.rb index 0b7b3d5f..bc3d1c02 100644 --- a/lib/knapsack_pro/config/env.rb +++ b/lib/knapsack_pro/config/env.rb @@ -74,6 +74,10 @@ def test_file_list ENV['KNAPSACK_PRO_TEST_FILE_LIST'] end + def test_file_list_source_file + ENV['KNAPSACK_PRO_TEST_FILE_LIST_SOURCE_FILE'] + end + def test_dir ENV['KNAPSACK_PRO_TEST_DIR'] end diff --git a/lib/knapsack_pro/test_file_finder.rb b/lib/knapsack_pro/test_file_finder.rb index c66ba280..a85743c0 100644 --- a/lib/knapsack_pro/test_file_finder.rb +++ b/lib/knapsack_pro/test_file_finder.rb @@ -63,6 +63,10 @@ def test_files return KnapsackPro::Config::Env.test_file_list.split(',').map(&:strip) end + if test_file_list_enabled && KnapsackPro::Config::Env.test_file_list_source_file + return File.read(ENV['KNAPSACK_PRO_TEST_FILE_LIST_SOURCE_FILE']).split(/\n/) + end + test_file_paths = Dir.glob(test_file_pattern).uniq excluded_test_file_paths = diff --git a/spec/knapsack_pro/test_file_finder_spec.rb b/spec/knapsack_pro/test_file_finder_spec.rb index 56345318..fccec184 100644 --- a/spec/knapsack_pro/test_file_finder_spec.rb +++ b/spec/knapsack_pro/test_file_finder_spec.rb @@ -154,5 +154,23 @@ end end end + + context 'when KNAPSACK_PRO_TEST_FILE_LIST_SOURCE_FILE is defined' do + let(:test_file_list_source_file) { 'spec_fake/fake_test' } + + before do + stub_const("ENV", { 'KNAPSACK_PRO_TEST_FILE_LIST_SOURCE_FILE' => test_file_list_source_file }) + end + + it do + expect(subject).to eq([ + { 'path' => 'spec/test1.rb' }, + { 'path' => 'spec/test2.rb[1]' }, + { 'path' => 'spec/test3.rb[1:2:3:4]' }, + { 'path' => 'spec/test4.rb:4' }, + ]) + end + + end end end diff --git a/spec_fake/fake_test b/spec_fake/fake_test new file mode 100644 index 00000000..3d8c7567 --- /dev/null +++ b/spec_fake/fake_test @@ -0,0 +1,4 @@ +./spec/test1.rb +./spec/test2.rb[1] +./spec/test3.rb[1:2:3:4] +./spec/test4.rb:4 \ No newline at end of file From 5204cb2c3f1cebf622bb1a75e2e000ed998d6f40 Mon Sep 17 00:00:00 2001 From: Feng Sha Date: Tue, 3 Nov 2020 14:31:06 -0500 Subject: [PATCH 02/12] modifying according to code reivew --- README.md | 19 +++++++++++++++++-- lib/knapsack_pro/test_file_cleaner.rb | 2 +- lib/knapsack_pro/test_file_finder.rb | 2 +- spec/fixtures/test_file_list_source_file.txt | 6 ++++++ spec/knapsack_pro/config/env_spec.rb | 14 ++++++++++++++ spec/knapsack_pro/test_file_finder_spec.rb | 3 ++- spec_fake/fake_test | 4 ---- 7 files changed, 41 insertions(+), 9 deletions(-) create mode 100644 spec/fixtures/test_file_list_source_file.txt delete mode 100644 spec_fake/fake_test diff --git a/README.md b/README.md index 145caa02..eb421477 100644 --- a/README.md +++ b/README.md @@ -3082,7 +3082,9 @@ The test file pattern and exclude pattern support any glob pattern handled by [` #### How to run a specific list of test files or only some tests from test file? -:information_source: If you don't want to use the pattern [`KNAPSACK_PRO_TEST_FILE_PATTERN`](#how-can-i-run-tests-from-multiple-directories) to define a list of tests to run then read below. +:information_source: If you don't want to use the pattern [`KNAPSACK_PRO_TEST_FILE_PATTERN`](#how-can-i-run-tests-from-multiple-directories) to define a list of tests to run then read below two options. + +**Option 1:** If you want to run a specific list of test files that are explicitly defined by you or auto-generated by some kind of script you created then please use: @@ -3090,7 +3092,20 @@ If you want to run a specific list of test files that are explicitly defined by Note `KNAPSACK_PRO_TEST_FILE_LIST` must be a list of test files comma separated. You can provide line number for tests inside of spec file in case of RSpec (this way you can run only one test or a group of tests from RSpec spec file). You can provide the same file a few times with different test line number. -Note when you set `KNAPSACK_PRO_TEST_FILE_LIST` then below environment variables are ignored: +**Option 2:** + +Similarly, you can also provide a source file containing the test files that you would like to run. For example: +`KNAPSACK_PRO_TEST_FILE_LIST_SOURCE_FILE=spec/fixtures/test_file_list_source_file.txt` +And the content of the test file can be any format below or combination: +``` +./spec/test1.rb, +spec/test2.rb[1] +./spec/test3.rb[1:2:3:4], +./spec/test4.rb:4 +./spec/test4.rb:5, +``` + +Note when you set `KNAPSACK_PRO_TEST_FILE_LIST` or `KNAPSACK_PRO_TEST_FILE_LIST_SOURCE_FILE` then below environment variables are ignored: * `KNAPSACK_PRO_TEST_FILE_PATTERN` * `KNAPSACK_PRO_TEST_FILE_EXCLUDE_PATTERN` diff --git a/lib/knapsack_pro/test_file_cleaner.rb b/lib/knapsack_pro/test_file_cleaner.rb index dbe1535f..f6b63d22 100644 --- a/lib/knapsack_pro/test_file_cleaner.rb +++ b/lib/knapsack_pro/test_file_cleaner.rb @@ -1,7 +1,7 @@ module KnapsackPro class TestFileCleaner def self.clean(test_file_path) - test_file_path.sub(/^\.\//, '') + test_file_path.sub(/^\.\//, '').chomp(",") end end end diff --git a/lib/knapsack_pro/test_file_finder.rb b/lib/knapsack_pro/test_file_finder.rb index a85743c0..457e0645 100644 --- a/lib/knapsack_pro/test_file_finder.rb +++ b/lib/knapsack_pro/test_file_finder.rb @@ -64,7 +64,7 @@ def test_files end if test_file_list_enabled && KnapsackPro::Config::Env.test_file_list_source_file - return File.read(ENV['KNAPSACK_PRO_TEST_FILE_LIST_SOURCE_FILE']).split(/\n/) + return File.read(KnapsackPro::Config::Env.test_file_list_source_file).split(/\n/) end test_file_paths = Dir.glob(test_file_pattern).uniq diff --git a/spec/fixtures/test_file_list_source_file.txt b/spec/fixtures/test_file_list_source_file.txt new file mode 100644 index 00000000..e7af1321 --- /dev/null +++ b/spec/fixtures/test_file_list_source_file.txt @@ -0,0 +1,6 @@ +./spec/test1.rb, +spec/test2.rb[1] +./spec/test3.rb[1:2:3:4], +./spec/test4.rb:4 +./spec/test4.rb:5, + diff --git a/spec/knapsack_pro/config/env_spec.rb b/spec/knapsack_pro/config/env_spec.rb index 45531d08..45dbe14e 100644 --- a/spec/knapsack_pro/config/env_spec.rb +++ b/spec/knapsack_pro/config/env_spec.rb @@ -238,6 +238,20 @@ end end + describe '.test_file_list_source_file' do + subject { described_class.test_file_list_source_file } + + context 'when ENV exists' do + let(:test_file_list_source_file) { 'spec/fixtures/test_file_list_source_file.txt' } + before { stub_const("ENV", { 'KNAPSACK_PRO_TEST_FILE_LIST_SOURCE_FILE' => test_file_list_source_file }) } + it { should eq test_file_list_source_file } + end + + context "when ENV doesn't exist" do + it { should be_nil } + end + end + describe '.test_dir' do subject { described_class.test_dir } diff --git a/spec/knapsack_pro/test_file_finder_spec.rb b/spec/knapsack_pro/test_file_finder_spec.rb index fccec184..69363789 100644 --- a/spec/knapsack_pro/test_file_finder_spec.rb +++ b/spec/knapsack_pro/test_file_finder_spec.rb @@ -156,7 +156,7 @@ end context 'when KNAPSACK_PRO_TEST_FILE_LIST_SOURCE_FILE is defined' do - let(:test_file_list_source_file) { 'spec_fake/fake_test' } + let(:test_file_list_source_file) { 'spec/fixtures/test_file_list_source_file.txt' } before do stub_const("ENV", { 'KNAPSACK_PRO_TEST_FILE_LIST_SOURCE_FILE' => test_file_list_source_file }) @@ -168,6 +168,7 @@ { 'path' => 'spec/test2.rb[1]' }, { 'path' => 'spec/test3.rb[1:2:3:4]' }, { 'path' => 'spec/test4.rb:4' }, + { 'path' => 'spec/test4.rb:5' }, ]) end diff --git a/spec_fake/fake_test b/spec_fake/fake_test deleted file mode 100644 index 3d8c7567..00000000 --- a/spec_fake/fake_test +++ /dev/null @@ -1,4 +0,0 @@ -./spec/test1.rb -./spec/test2.rb[1] -./spec/test3.rb[1:2:3:4] -./spec/test4.rb:4 \ No newline at end of file From 77320671361585abd43ef793a9a20628f51c87ba Mon Sep 17 00:00:00 2001 From: Feng Sha Date: Tue, 3 Nov 2020 15:33:04 -0500 Subject: [PATCH 03/12] remove , from end of the test file path --- spec/knapsack_pro/test_file_cleaner_spec.rb | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/spec/knapsack_pro/test_file_cleaner_spec.rb b/spec/knapsack_pro/test_file_cleaner_spec.rb index 558739db..00dd5d3a 100644 --- a/spec/knapsack_pro/test_file_cleaner_spec.rb +++ b/spec/knapsack_pro/test_file_cleaner_spec.rb @@ -1,11 +1,19 @@ describe KnapsackPro::TestFileCleaner do describe '.clean' do - let(:test_file_path) { './models/user_spec.rb' } - subject { described_class.clean(test_file_path) } - it 'removes ./ from the begining of the test file path' do - expect(subject).to eq 'models/user_spec.rb' + context "removes ./ " do + let(:test_file_path) { './models/user_spec.rb' } + it 'removes ./ from the begining of the test file path' do + expect(subject).to eq 'models/user_spec.rb' + end + end + + context "removes , " do + let(:test_file_path) { 'models/user_spec.rb,' } + it 'removes , from the end of the test file path' do + expect(subject).to eq 'models/user_spec.rb' + end end end end From 5b97ad6bb933f287c1fae6a53c44eed5be2b7987 Mon Sep 17 00:00:00 2001 From: Feng Sha Date: Tue, 3 Nov 2020 15:33:04 -0500 Subject: [PATCH 04/12] Revert "remove , from end of the test file path" This reverts commit 77320671361585abd43ef793a9a20628f51c87ba. --- spec/knapsack_pro/test_file_cleaner_spec.rb | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/spec/knapsack_pro/test_file_cleaner_spec.rb b/spec/knapsack_pro/test_file_cleaner_spec.rb index 00dd5d3a..558739db 100644 --- a/spec/knapsack_pro/test_file_cleaner_spec.rb +++ b/spec/knapsack_pro/test_file_cleaner_spec.rb @@ -1,19 +1,11 @@ describe KnapsackPro::TestFileCleaner do describe '.clean' do - subject { described_class.clean(test_file_path) } + let(:test_file_path) { './models/user_spec.rb' } - context "removes ./ " do - let(:test_file_path) { './models/user_spec.rb' } - it 'removes ./ from the begining of the test file path' do - expect(subject).to eq 'models/user_spec.rb' - end - end + subject { described_class.clean(test_file_path) } - context "removes , " do - let(:test_file_path) { 'models/user_spec.rb,' } - it 'removes , from the end of the test file path' do - expect(subject).to eq 'models/user_spec.rb' - end + it 'removes ./ from the begining of the test file path' do + expect(subject).to eq 'models/user_spec.rb' end end end From 86ebfc0cbdfe4d2d560d38d151e99f01b9fc1cfa Mon Sep 17 00:00:00 2001 From: Feng Sha Date: Tue, 3 Nov 2020 17:11:49 -0500 Subject: [PATCH 05/12] remove comma handling feature --- README.md | 9 +++++---- lib/knapsack_pro/test_file_cleaner.rb | 2 +- spec/fixtures/test_file_list_source_file.txt | 7 ++++--- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index eb421477..fc4a9e0d 100644 --- a/README.md +++ b/README.md @@ -3096,14 +3096,15 @@ Note `KNAPSACK_PRO_TEST_FILE_LIST` must be a list of test files comma separated. Similarly, you can also provide a source file containing the test files that you would like to run. For example: `KNAPSACK_PRO_TEST_FILE_LIST_SOURCE_FILE=spec/fixtures/test_file_list_source_file.txt` -And the content of the test file can be any format below or combination: +And the content of the source file can be any of the format below: ``` -./spec/test1.rb, +./spec/test1.rb spec/test2.rb[1] -./spec/test3.rb[1:2:3:4], +./spec/test3.rb[1:2:3:4] ./spec/test4.rb:4 -./spec/test4.rb:5, +./spec/test4.rb:5 ``` +> Note that each of the line must be ending with `\n` the new line. Note when you set `KNAPSACK_PRO_TEST_FILE_LIST` or `KNAPSACK_PRO_TEST_FILE_LIST_SOURCE_FILE` then below environment variables are ignored: * `KNAPSACK_PRO_TEST_FILE_PATTERN` diff --git a/lib/knapsack_pro/test_file_cleaner.rb b/lib/knapsack_pro/test_file_cleaner.rb index f6b63d22..dbe1535f 100644 --- a/lib/knapsack_pro/test_file_cleaner.rb +++ b/lib/knapsack_pro/test_file_cleaner.rb @@ -1,7 +1,7 @@ module KnapsackPro class TestFileCleaner def self.clean(test_file_path) - test_file_path.sub(/^\.\//, '').chomp(",") + test_file_path.sub(/^\.\//, '') end end end diff --git a/spec/fixtures/test_file_list_source_file.txt b/spec/fixtures/test_file_list_source_file.txt index e7af1321..4eca7c2e 100644 --- a/spec/fixtures/test_file_list_source_file.txt +++ b/spec/fixtures/test_file_list_source_file.txt @@ -1,6 +1,7 @@ -./spec/test1.rb, +./spec/test1.rb spec/test2.rb[1] -./spec/test3.rb[1:2:3:4], +./spec/test3.rb[1:2:3:4] ./spec/test4.rb:4 -./spec/test4.rb:5, +./spec/test4.rb:5 + From 9bc812e022661f64949d3d923a70f12a6d2763dd Mon Sep 17 00:00:00 2001 From: Feng Sha Date: Tue, 3 Nov 2020 17:22:35 -0500 Subject: [PATCH 06/12] adding _spec for convention --- README.md | 10 +++++----- spec/fixtures/test_file_list_source_file.txt | 10 +++++----- spec/knapsack_pro/test_file_finder_spec.rb | 10 +++++----- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index fc4a9e0d..89b18971 100644 --- a/README.md +++ b/README.md @@ -3098,11 +3098,11 @@ Similarly, you can also provide a source file containing the test files that you `KNAPSACK_PRO_TEST_FILE_LIST_SOURCE_FILE=spec/fixtures/test_file_list_source_file.txt` And the content of the source file can be any of the format below: ``` -./spec/test1.rb -spec/test2.rb[1] -./spec/test3.rb[1:2:3:4] -./spec/test4.rb:4 -./spec/test4.rb:5 +./spec/test1_spec.rb +spec/test2_spec.rb[1] +./spec/test3_spec.rb[1:2:3:4] +./spec/test4_spec.rb:4 +./spec/test4_spec.rb:5 ``` > Note that each of the line must be ending with `\n` the new line. diff --git a/spec/fixtures/test_file_list_source_file.txt b/spec/fixtures/test_file_list_source_file.txt index 4eca7c2e..600e1214 100644 --- a/spec/fixtures/test_file_list_source_file.txt +++ b/spec/fixtures/test_file_list_source_file.txt @@ -1,7 +1,7 @@ -./spec/test1.rb -spec/test2.rb[1] -./spec/test3.rb[1:2:3:4] -./spec/test4.rb:4 -./spec/test4.rb:5 +./spec/test1_spec.rb +spec/test2_spec.rb[1] +./spec/test3_spec.rb[1:2:3:4] +./spec/test4_spec.rb:4 +./spec/test4_spec.rb:5 diff --git a/spec/knapsack_pro/test_file_finder_spec.rb b/spec/knapsack_pro/test_file_finder_spec.rb index 69363789..148a33a6 100644 --- a/spec/knapsack_pro/test_file_finder_spec.rb +++ b/spec/knapsack_pro/test_file_finder_spec.rb @@ -164,11 +164,11 @@ it do expect(subject).to eq([ - { 'path' => 'spec/test1.rb' }, - { 'path' => 'spec/test2.rb[1]' }, - { 'path' => 'spec/test3.rb[1:2:3:4]' }, - { 'path' => 'spec/test4.rb:4' }, - { 'path' => 'spec/test4.rb:5' }, + { 'path' => 'spec/test1_spec.rb' }, + { 'path' => 'spec/test2_spec.rb[1]' }, + { 'path' => 'spec/test3_spec.rb[1:2:3:4]' }, + { 'path' => 'spec/test4_spec.rb:4' }, + { 'path' => 'spec/test4_spec.rb:5' }, ]) end From 70c30666b7aa782a8c3c3fa5c3593b857a33d4fc Mon Sep 17 00:00:00 2001 From: Feng Sha Date: Tue, 3 Nov 2020 17:28:47 -0500 Subject: [PATCH 07/12] change log for 2.7 --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d1a2d6c..cca05cca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Change Log +### 2.7.0 + +* Add support for env var KNAPSACK_PRO_TEST_FILE_LIST_SOURCE_FILE + + https://github.com/KnapsackPro/knapsack_pro-ruby/pull/129 + +https://github.com/KnapsackPro/knapsack_pro-ruby/compare/v2.6.0...v2.7.0 + ### 2.6.0 * Improve logger to show failed requests URL and when retry will happen From d4bfab63d6209f6c4041dea5f6cabc159bad92ab Mon Sep 17 00:00:00 2001 From: Artur Trzop Date: Tue, 3 Nov 2020 23:35:10 +0100 Subject: [PATCH 08/12] Update CHANGELOG.md Add more explanation why we added KNAPSACK_PRO_TEST_FILE_LIST_SOURCE_FILE and mark it with `KNAPSACK_PRO_TEST_FILE_LIST_SOURCE_FILE` --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cca05cca..daf0c3c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ### 2.7.0 -* Add support for env var KNAPSACK_PRO_TEST_FILE_LIST_SOURCE_FILE +* Add support for env var `KNAPSACK_PRO_TEST_FILE_LIST_SOURCE_FILE` to allow accepting file containing test files to run specified list of test files. https://github.com/KnapsackPro/knapsack_pro-ruby/pull/129 From 543a95d2f4d218123782b0061638411b5b2a55f9 Mon Sep 17 00:00:00 2001 From: Feng Sha Date: Tue, 3 Nov 2020 17:35:35 -0500 Subject: [PATCH 09/12] remove un-necessary empty lines --- spec/fixtures/test_file_list_source_file.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/spec/fixtures/test_file_list_source_file.txt b/spec/fixtures/test_file_list_source_file.txt index 600e1214..e827c5a0 100644 --- a/spec/fixtures/test_file_list_source_file.txt +++ b/spec/fixtures/test_file_list_source_file.txt @@ -3,5 +3,3 @@ spec/test2_spec.rb[1] ./spec/test3_spec.rb[1:2:3:4] ./spec/test4_spec.rb:4 ./spec/test4_spec.rb:5 - - From ae86700fb857d8343a1a846135c9941af36a9b67 Mon Sep 17 00:00:00 2001 From: Artur Trzop Date: Tue, 3 Nov 2020 23:36:11 +0100 Subject: [PATCH 10/12] Update README.md add new lines --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 89b18971..9184e15e 100644 --- a/README.md +++ b/README.md @@ -3097,6 +3097,7 @@ Note `KNAPSACK_PRO_TEST_FILE_LIST` must be a list of test files comma separated. Similarly, you can also provide a source file containing the test files that you would like to run. For example: `KNAPSACK_PRO_TEST_FILE_LIST_SOURCE_FILE=spec/fixtures/test_file_list_source_file.txt` And the content of the source file can be any of the format below: + ``` ./spec/test1_spec.rb spec/test2_spec.rb[1] @@ -3104,9 +3105,11 @@ spec/test2_spec.rb[1] ./spec/test4_spec.rb:4 ./spec/test4_spec.rb:5 ``` + > Note that each of the line must be ending with `\n` the new line. Note when you set `KNAPSACK_PRO_TEST_FILE_LIST` or `KNAPSACK_PRO_TEST_FILE_LIST_SOURCE_FILE` then below environment variables are ignored: + * `KNAPSACK_PRO_TEST_FILE_PATTERN` * `KNAPSACK_PRO_TEST_FILE_EXCLUDE_PATTERN` From e4a7fe9ce71952a06cda3838ad60fb6dc5912a21 Mon Sep 17 00:00:00 2001 From: Artur Trzop Date: Tue, 3 Nov 2020 23:37:03 +0100 Subject: [PATCH 11/12] Update test_file_finder_spec.rb remove new line --- spec/knapsack_pro/test_file_finder_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/knapsack_pro/test_file_finder_spec.rb b/spec/knapsack_pro/test_file_finder_spec.rb index 148a33a6..eb4cd4fe 100644 --- a/spec/knapsack_pro/test_file_finder_spec.rb +++ b/spec/knapsack_pro/test_file_finder_spec.rb @@ -171,7 +171,6 @@ { 'path' => 'spec/test4_spec.rb:5' }, ]) end - end end end From 4eff9b93b27d6617c2aec12ed345583cc76ce835 Mon Sep 17 00:00:00 2001 From: Artur Trzop Date: Tue, 3 Nov 2020 23:39:15 +0100 Subject: [PATCH 12/12] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index daf0c3c9..e06094b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ### 2.7.0 -* Add support for env var `KNAPSACK_PRO_TEST_FILE_LIST_SOURCE_FILE` to allow accepting file containing test files to run specified list of test files. +* Add support for env var `KNAPSACK_PRO_TEST_FILE_LIST_SOURCE_FILE` to allow accepting file containing test files to run. https://github.com/KnapsackPro/knapsack_pro-ruby/pull/129