knapsack_pro 1.10.1 → 1.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +80 -1
- data/lib/knapsack_pro/config/env.rb +4 -0
- data/lib/knapsack_pro/test_file_finder.rb +4 -0
- data/lib/knapsack_pro/version.rb +1 -1
- data/spec/knapsack_pro/config/env_spec.rb +14 -0
- data/spec/knapsack_pro/test_file_finder_spec.rb +26 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 640a408f0a698ec1f064a7857699aeaf5ec27c72a3b30e96a0dfc80655473549
|
4
|
+
data.tar.gz: b8a305a9e170cf0f015be62a85c0415bfe3ba76c1255122fdc0c1b0c46a8d934
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e6ecaf953291bf583006846a3511162f7896f5e0ad374dcf861c8aa99dc017f2d102bf0a85b96133b24afc4a3ce99632aaded1384e853a6cd6c2a7d48c77c0d
|
7
|
+
data.tar.gz: 0350dafb658f2d965bd46728f0f18ae1d3dc0e44639eb1d54969c6f203bdc82f2d7653da63ec71fe7de9fe0013b8faf1e5142ef26dac7b702342f012449b7f6c
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
### 1.11.0
|
4
|
+
|
5
|
+
* Add support for `KNAPSACK_PRO_TEST_FILE_LIST` environment variable to run explicitly listed tests
|
6
|
+
|
7
|
+
https://github.com/KnapsackPro/knapsack_pro-ruby/pull/86
|
8
|
+
|
9
|
+
https://github.com/KnapsackPro/knapsack_pro-ruby/compare/v1.10.1...v1.11.0
|
10
|
+
|
3
11
|
### 1.10.1
|
4
12
|
|
5
13
|
* Fix log info when measured time of tests was lost
|
data/README.md
CHANGED
@@ -120,6 +120,7 @@ You can see list of questions for common problems and tips in below [Table of Co
|
|
120
120
|
- [Why I see HEAD as branch name in user dashboard for Build metrics for my API token?](#why-i-see-head-as-branch-name-in-user-dashboard-for-build-metrics-for-my-api-token)
|
121
121
|
- [Why Capybara feature tests randomly fail when using CI parallelisation?](#why-capybara-feature-tests-randomly-fail-when-using-ci-parallelisation)
|
122
122
|
- [Why knapsack_pro freezes / hangs my CI (for instance Travis)?](#why-knapsack_pro-freezes--hangs-my-ci-for-instance-travis)
|
123
|
+
- [Why tests hitting external API fail?](#why-tests-hitting-external-api-fail)
|
123
124
|
- [Queue Mode problems](#queue-mode-problems)
|
124
125
|
- [Why when I use Queue Mode for RSpec then my tests fail?](#why-when-i-use-queue-mode-for-rspec-then-my-tests-fail)
|
125
126
|
- [Why when I use Queue Mode for RSpec then FactoryBot/FactoryGirl tests fail?](#why-when-i-use-queue-mode-for-rspec-then-factorybotfactorygirl-tests-fail)
|
@@ -173,10 +174,12 @@ You can see list of questions for common problems and tips in below [Table of Co
|
|
173
174
|
- [Why when I use 2 different CI providers then not all test files are executed?](#why-when-i-use-2-different-ci-providers-then-not-all-test-files-are-executed)
|
174
175
|
- [How to run only RSpec feature tests or non feature tests?](#how-to-run-only-rspec-feature-tests-or-non-feature-tests)
|
175
176
|
- [How to exclude tests from running them?](#how-to-exclude-tests-from-running-them)
|
177
|
+
- [How to run a specific list of test files or only some tests from test file?](#how-to-run-a-specific-list-of-test-files-or-only-some-tests-from-test-file)
|
176
178
|
- [How to use CodeClimate with knapsack_pro?](#how-to-use-codeclimate-with-knapsack_pro)
|
177
179
|
- [How to run knapsack_pro only on a few parallel CI nodes instead of all?](#how-to-run-knapsack_pro-only-on-a-few-parallel-ci-nodes-instead-of-all)
|
178
180
|
- [How to use simplecov in Queue Mode?](#how-to-use-simplecov-in-queue-mode)
|
179
181
|
- [Do I need to use separate API token for Queue Mode and Regular Mode?](#do-i-need-to-use-separate-api-token-for-queue-mode-and-regular-mode)
|
182
|
+
- [How to stop running tests on the first failed test (fail fast tests in RSpec)?](#how-to-stop-running-tests-on-the-first-failed-test-fail-fast-tests-in-rspec)
|
180
183
|
- [Questions around data usage and security](#questions-around-data-usage-and-security)
|
181
184
|
- [What data is sent to your servers?](#what-data-is-sent-to-your-servers)
|
182
185
|
- [How is that data secured?](#how-is-that-data-secured)
|
@@ -1409,6 +1412,26 @@ RSpec.configure do |c|
|
|
1409
1412
|
end
|
1410
1413
|
```
|
1411
1414
|
|
1415
|
+
#### Why tests hitting external API fail?
|
1416
|
+
|
1417
|
+
If you use knapsack_pro and you have tests that do real HTTP requests to external API you need to ensure your tests can be run across parallel CI nodes.
|
1418
|
+
|
1419
|
+
Let's say you have tests that do requests to Stripe API or any other API. Before running each test you want to make sure Stripe Sandbox is clean up so you have removed all fake subscriptions and customers from Stripe Sandbox.
|
1420
|
+
|
1421
|
+
```ruby
|
1422
|
+
# RSpec hook
|
1423
|
+
before(:each) do
|
1424
|
+
Stripe::Subscription.all.each { |sub| sub.delete }
|
1425
|
+
Stripe::Customer.all.each { |customer| customer.delete }
|
1426
|
+
end
|
1427
|
+
```
|
1428
|
+
|
1429
|
+
But this will cause a problem when 2 different test files will run on 2 different CI nodes at the same time and this hook will be called. You will remove subscriptions and customers while another parallel test was running. Simply speaking you have tests that are written in a way that you can't run them in parallel.
|
1430
|
+
|
1431
|
+
To fix that you can think of:
|
1432
|
+
* using [VCR](https://github.com/vcr/vcr) gem to record HTTP requests and then instead of doing real HTTP requests just reply recorded requests.
|
1433
|
+
* maybe you could write your tests in a way when you generate some fake customers or subscriptions with fake id and each test has different customer id so there will be no conflict when 2 tests are run at the same time.
|
1434
|
+
|
1412
1435
|
#### Queue Mode problems
|
1413
1436
|
|
1414
1437
|
##### Why when I use Queue Mode for RSpec then my tests fail?
|
@@ -1421,6 +1444,18 @@ In that case you need to resolve failed tests in a way that allows RSpec to run
|
|
1421
1444
|
|
1422
1445
|
You can learn more about [recent RSpec team changes](https://github.com/KnapsackPro/knapsack_pro-ruby/pull/42) that was backported into knapsack_pro.
|
1423
1446
|
|
1447
|
+
To solve failing tests in Queue Mode you can check:
|
1448
|
+
|
1449
|
+
* you use full namespacing. If you see error like `NameError: uninitialized constant MyModule::ModelName` then in some cases a top-level constant would be matched if the code hadn't been loaded for the scoped constant. Try to use full namespacing `::SomeModule::MyModule::ModelName` etc.
|
1450
|
+
* you can try to use binary version of knapsack_pro instead of running it via rake task. This helps if your rake tasks mess up with tests and make knapsack_pro Queue Mode fail. [See example](#why-when-i-use-queue-mode-for-rspec-then-factorybotfactorygirl-tests-fail):
|
1451
|
+
|
1452
|
+
```bash
|
1453
|
+
# Knapsack Pro Queue Mode run via binary
|
1454
|
+
bundle exec knapsack_pro queue:rspec "--profile 10 --format progress"
|
1455
|
+
```
|
1456
|
+
|
1457
|
+
* You can check below questions for common reasons of failing tests in Queue Mode
|
1458
|
+
|
1424
1459
|
##### Why when I use Queue Mode for RSpec then FactoryBot/FactoryGirl tests fail?
|
1425
1460
|
|
1426
1461
|
You can use [knapsack_pro binary](#knapsack-pro-binary) instead of rake task version to solve problem:
|
@@ -2312,10 +2347,14 @@ require 'spec_helper'
|
|
2312
2347
|
|
2313
2348
|
#### Why I don't see all test files being recorded in user dashboard
|
2314
2349
|
|
2315
|
-
If you open `Build metrics` for particular API token at [user dashboard](https://knapsackpro.com/dashboard) and you don't see all time execution data recorded for all test files then you should know that knapsack_pro does not track test files with empty content or when the test file contains only pending tests.
|
2350
|
+
If you open `Build metrics` for particular API token at [user dashboard](https://knapsackpro.com/dashboard) and you don't see all time execution data recorded for all test files then you should know that knapsack_pro version older than [`1.0.2`](https://github.com/KnapsackPro/knapsack_pro-ruby/blob/master/CHANGELOG.md#102) does not track test files with empty content or when the test file contains only pending tests.
|
2316
2351
|
|
2317
2352
|
The test files with pending tests are executed so you will see it in RSpec output but just not recorded in Knapsack Pro API because there is nothing to record time for.
|
2318
2353
|
|
2354
|
+
We recommend to update to the latest version of knapsack_pro.
|
2355
|
+
|
2356
|
+
Please check also this question [why you may don't see time execution data](#why-i-dont-see-collected-time-execution-data-for-my-build-in-user-dashboard) in your dashboard.
|
2357
|
+
|
2319
2358
|
#### Why when I use 2 different CI providers then not all test files are executed?
|
2320
2359
|
|
2321
2360
|
Please ensure you use 2 different API token per test suite. If you use 2 CI providers for instance CircleCI and TravisCI at the same time and you run the RSpec test suite then you need to have separate API token for RSpec executed on CircleCI and a separate API token for RSpec test suite executed on the TravisCI.
|
@@ -2383,6 +2422,20 @@ bundle exec rake knapsack_pro:queue:rspec
|
|
2383
2422
|
|
2384
2423
|
The test file pattern and exclude pattern support any glob pattern handled by [`Dir.glob`](http://ruby-doc.org/core-2.4.1/Dir.html#method-c-glob).
|
2385
2424
|
|
2425
|
+
#### How to run a specific list of test files or only some tests from test file?
|
2426
|
+
|
2427
|
+
: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.
|
2428
|
+
|
2429
|
+
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:
|
2430
|
+
|
2431
|
+
`KNAPSACK_PRO_TEST_FILE_LIST=spec/features/dashboard_spec.rb,spec/models/user.rb:10,spec/models/user.rb:29`
|
2432
|
+
|
2433
|
+
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.
|
2434
|
+
|
2435
|
+
Note when you set `KNAPSACK_PRO_TEST_FILE_LIST` then below environment variables are ignored:
|
2436
|
+
* `KNAPSACK_PRO_TEST_FILE_PATTERN`
|
2437
|
+
* `KNAPSACK_PRO_TEST_FILE_EXCLUDE_PATTERN`
|
2438
|
+
|
2386
2439
|
#### How to use CodeClimate with knapsack_pro?
|
2387
2440
|
|
2388
2441
|
You can check CodeClimate docs about [parallel tests](https://docs.codeclimate.com/docs/configuring-test-coverage#section-parallel-tests) and [multiple test suites](https://docs.codeclimate.com/docs/configuring-test-coverage#section-multiple-test-suites).
|
@@ -2433,6 +2486,32 @@ I recommend to record timing of a new test suite with `API token A` and knapsack
|
|
2433
2486
|
|
2434
2487
|
When you want to go back from Queue Mode to Regular Mode then the fact of using the same API token could cause edge cases that some builds might not be well balanced in Regular Mode. That is why I recommend using separate API token for Regular Mode and Queue Mode. If you plan to use only Queue Mode then no worry.
|
2435
2488
|
|
2489
|
+
#### How to stop running tests on the first failed test (fail fast tests in RSpec)?
|
2490
|
+
|
2491
|
+
If you want to stop running tests as soon as one of it fails then you can pass [--fail-fast](https://relishapp.com/rspec/rspec-core/docs/command-line/fail-fast-option) RSpec option to knapsack_pro:
|
2492
|
+
|
2493
|
+
```
|
2494
|
+
# Regular Mode
|
2495
|
+
bundle exec rake "knapsack_pro:rspec[--fail-fast]"
|
2496
|
+
|
2497
|
+
# Queue Mode
|
2498
|
+
bundle exec rake "knapsack_pro:queue:rspec[--fail-fast]"
|
2499
|
+
```
|
2500
|
+
|
2501
|
+
You may add a parameter to tell RSpec to stop running the test suite after N failed tests, for example: `--fail-fast=3`.
|
2502
|
+
|
2503
|
+
```
|
2504
|
+
Note there is no = sign on purpose here:
|
2505
|
+
|
2506
|
+
# Regular Mode
|
2507
|
+
bundle exec rake "knapsack_pro:rspec[--fail-fast 3]"
|
2508
|
+
|
2509
|
+
# Queue Mode
|
2510
|
+
bundle exec rake "knapsack_pro:queue:rspec[--fail-fast 3]"
|
2511
|
+
```
|
2512
|
+
|
2513
|
+
There is a downside to it. If you stop running tests then tests that were never run will have no recorded timing of execution and because of that, the future CI build might have tests split across CI nodes in no optimal way.
|
2514
|
+
|
2436
2515
|
### Questions around data usage and security
|
2437
2516
|
|
2438
2517
|
#### What data is sent to your servers?
|
@@ -21,6 +21,10 @@ module KnapsackPro
|
|
21
21
|
attr_reader :test_file_pattern
|
22
22
|
|
23
23
|
def test_files
|
24
|
+
if KnapsackPro::Config::Env.test_file_list
|
25
|
+
return KnapsackPro::Config::Env.test_file_list.split(',').map(&:strip)
|
26
|
+
end
|
27
|
+
|
24
28
|
test_file_paths = Dir.glob(test_file_pattern).uniq
|
25
29
|
|
26
30
|
excluded_test_file_paths =
|
data/lib/knapsack_pro/version.rb
CHANGED
@@ -167,6 +167,20 @@ describe KnapsackPro::Config::Env do
|
|
167
167
|
end
|
168
168
|
end
|
169
169
|
|
170
|
+
describe '.test_file_list' do
|
171
|
+
subject { described_class.test_file_list }
|
172
|
+
|
173
|
+
context 'when ENV exists' do
|
174
|
+
let(:test_file_list) { 'spec/features/dashboard_spec.rb,spec/models/user.rb:10,spec/models/user.rb:29' }
|
175
|
+
before { stub_const("ENV", { 'KNAPSACK_PRO_TEST_FILE_LIST' => test_file_list }) }
|
176
|
+
it { should eq test_file_list }
|
177
|
+
end
|
178
|
+
|
179
|
+
context "when ENV doesn't exist" do
|
180
|
+
it { should be_nil }
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
170
184
|
describe '.test_dir' do
|
171
185
|
subject { described_class.test_dir }
|
172
186
|
|
@@ -52,5 +52,31 @@ describe KnapsackPro::TestFileFinder do
|
|
52
52
|
])
|
53
53
|
end
|
54
54
|
end
|
55
|
+
|
56
|
+
context 'when KNAPSACK_PRO_TEST_FILE_LIST is defined' do
|
57
|
+
# added spaces next to comma to check space is removed later
|
58
|
+
let(:test_file_list) { 'spec/bar_spec.rb,spec/foo_spec.rb, spec/time_helpers_spec.rb:10 , spec/time_helpers_spec.rb:38' }
|
59
|
+
|
60
|
+
before do
|
61
|
+
stub_const("ENV", { 'KNAPSACK_PRO_TEST_FILE_LIST' => test_file_list })
|
62
|
+
end
|
63
|
+
|
64
|
+
it do
|
65
|
+
expect(subject).to eq([
|
66
|
+
{
|
67
|
+
'path' => 'spec/bar_spec.rb',
|
68
|
+
},
|
69
|
+
{
|
70
|
+
'path' => 'spec/foo_spec.rb',
|
71
|
+
},
|
72
|
+
{
|
73
|
+
'path' => 'spec/time_helpers_spec.rb:10',
|
74
|
+
},
|
75
|
+
{
|
76
|
+
'path' => 'spec/time_helpers_spec.rb:38',
|
77
|
+
},
|
78
|
+
])
|
79
|
+
end
|
80
|
+
end
|
55
81
|
end
|
56
82
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knapsack_pro
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ArturT
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-05-
|
11
|
+
date: 2019-05-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|