add exclude pattern option#682
Conversation
| BANNER | ||
| opts.on("-n [PROCESSES]", Integer, "How many processes to use, default: available CPUs") { |n| options[:count] = n } | ||
| opts.on("-p", "--pattern [PATTERN]", "run tests matching this regex pattern") { |pattern| options[:pattern] = /#{pattern}/ } | ||
| opts.on("--exclude-pattern", "--exclude-pattern [PATTERN]", "run tests matching this regex pattern") { |pattern| options[:exclude_pattern] = /#{pattern}/ } |
There was a problem hiding this comment.
| opts.on("--exclude-pattern", "--exclude-pattern [PATTERN]", "run tests matching this regex pattern") { |pattern| options[:exclude_pattern] = /#{pattern}/ } | |
| opts.on("--exclude-pattern", "--exclude-pattern [PATTERN]", "run tests not matching this regex pattern") { |pattern| options[:exclude_pattern] = /#{pattern}/ } |
|
|
||
| def find_tests(tests, options = {}) | ||
| tests_list = all_tests(tests, options) | ||
| exclude_tests(tests_list, options) |
There was a problem hiding this comment.
this seems asymmetric ... do it at the same place the pattern matching is done ?
| end | ||
|
|
||
| def exclude_tests(tests_list, options = {}) | ||
| tests_list.reject { |file| file =~ (options[:exclude_pattern] || //) } |
There was a problem hiding this comment.
//matches everything- use either reject! or grep since they are more efficient
- do as little work as possible in the inner loop (use local variable and not option lookup)
| tests_list.reject { |file| file =~ (options[:exclude_pattern] || //) } | |
| if regex = options[:exclude_pattern] | |
| tests_list -= tests_list.grep(regex) | |
| end |
There was a problem hiding this comment.
Addressed. Thanks for the quick feedback!
2ef59df to
f57719e
Compare
|
|
||
| task :default do | ||
| sh "rspec spec/" | ||
| system "rspec spec/" |
There was a problem hiding this comment.
This need to fail when the command fails, so use sh
|
|
||
| def find_tests(tests, options = {}) | ||
| (tests || []).map do |file_or_folder| | ||
| def find_tests(tests = [], options = {}) |
There was a problem hiding this comment.
tests should not have a default value
|
|
||
| if regex = options[:exclude_pattern] | ||
| files_list.reject! { |file| file =~ regex } | ||
| end |
There was a problem hiding this comment.
this is not consistent with how pattern works, it should be done inside so it does not apply to folders
... or both should apply to folders 🤷♂️
... and while your in here: it should use .flat_map + [file_or_folder] and not .flatten and .uniq!
There was a problem hiding this comment.
My assumption would be that anything matching the regex for the include pattern would be included, and the exclude_pattern will filter out anything matching the exclude pattern. It should apply to folders or files, as the exclude pattern behavior should mirror the behavior of native rspec --exclude-pattern option.
4e5b3e3 to
0dd7821
Compare
0dd7821 to
4826f07
Compare
|
@grosser Thanks for merging! Is there anything I need to do to get a new gem version out? |
|
no, I'm just waiting for my cleanup PR to go green and will then release |
|
v2.28.0 |
|
Awesome. Thanks a ton! Hopefully this will help others as well.
…On Thu, Feb 7, 2019 at 12:46 PM Michael Grosser ***@***.***> wrote:
v2.28.0
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#682 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AsNR3ix4I-RvcYBrJXW0FHDHXi5pm56qks5vLHRogaJpZM4aesUT>
.
--
This email and its attachments are confidential and may be privileged. Any
unauthorized use or disclosure is prohibited. If you receive this email in
error, please notify the sender and permanently delete the original without
forwarding, making any copies or disclosing its contents. NextCapital is a
brand name representing NextCapital Group, Inc. and its subsidiaries,
NextCapital Software, Inc. and NextCapital Advisers, Inc.
|
Add the ability to pass
--exclude-patternfixes #647
fixes #573