Skip to content

Commit 7c1b0da

Browse files
authored
Disable trunk listener when running under knapsack_pro:rspec_test_example_detector (#937)
`knapsack_pro:rspec_test_example_detector` instantiates all tests in a file to determine how to split by test examples ([reference](https://docs.knapsackpro.com/ruby/split-by-test-examples/)). This step is done before actually running the tests. When that happens, the RSpec reporter reports all test examples as passing, despite the fact that they're not actually run. This change checks if the command line contains "knapsack_pro:rspec_test_example_detector", and if so, disables test collection and uploading.
1 parent 101b9eb commit 7c1b0da

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

rspec-trunk-flaky-tests/lib/trunk_spec_helper.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,21 @@ def escape(str)
5555
str.dump[1..-2]
5656
end
5757

58+
# Knapsack example detector instantiates all test cases in order to determine how to shard them
59+
# These instantiations should not generate test bundles, so we
60+
# disable the gem when running under knapsack_pro:rspec_test_example_detector
61+
def knapsack_detector_mode?
62+
knapsack_detector_command?
63+
end
64+
65+
def knapsack_detector_command?
66+
command_line = "#{$PROGRAM_NAME} #{ARGV.join(' ')}".strip
67+
command_line.include?('knapsack_pro:rspec_test_example_detector')
68+
end
69+
5870
def trunk_disabled
59-
ENV['DISABLE_RSPEC_TRUNK_FLAKY_TESTS'] == 'true' || ENV['TRUNK_ORG_URL_SLUG'].nil? || ENV['TRUNK_API_TOKEN'].nil?
71+
knapsack_detector_mode? || ENV['DISABLE_RSPEC_TRUNK_FLAKY_TESTS'] == 'true' ||
72+
ENV['TRUNK_ORG_URL_SLUG'].nil? || ENV['TRUNK_API_TOKEN'].nil?
6073
end
6174

6275
# we want to cache the test report so we can add to it as we go and reduce the number of API calls

0 commit comments

Comments
 (0)