Skip to content

Commit 2cc7102

Browse files
committed
Create --exts and Delete --ext option
We allow to pass a list of extensions instead of a regex and build the regex from the options instead of the user. This is simpler and easier for the user.
1 parent 4b17063 commit 2cc7102

File tree

6 files changed

+44
-25
lines changed

6 files changed

+44
-25
lines changed

features/ruby-bare/retest/scenarios/custom_extensions.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class CustomExtensionTest < Minitest::Test
22
def setup
3-
@command = %Q{retest "echo 'I captured a change'" --ext="\\.txt$"}
3+
@command = %Q{retest "echo 'I captured a change'" --exts="txt"}
44
end
55

66
def teardown

lib/retest.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Error < StandardError; end
2323
class FileNotFound < StandardError; end
2424

2525
def self.listen(options, listener: Listen)
26-
listener.to('.', only: options.extension, relative: true, force_polling: options.force_polling?) do |modified, added, removed|
26+
listener.to('.', only: options.extensions, relative: true, force_polling: options.force_polling?) do |modified, added, removed|
2727
yield modified, added, removed
2828
end.start
2929
end

lib/retest/options.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ class Options
6363
long "--diff=git-branch"
6464
end
6565

66-
option :ext do
67-
desc "Regex of file extensions to listen to"
68-
long "--ext=regex"
69-
default "\\.rb$"
66+
option :exts do
67+
desc "Comma separated of filenames extensions to filter to"
68+
long "--exts=<EXTENSIONS>"
69+
default "rb"
7070
end
7171

7272
flag :all do
@@ -155,8 +155,9 @@ def force_polling?
155155
params[:polling]
156156
end
157157

158-
def extension
159-
Regexp.new(params[:ext])
158+
def extensions
159+
exts = params[:exts].split(',').map(&:strip)
160+
Regexp.new("\\.(?:#{exts.join("|")})$")
160161
end
161162

162163
def merge(options = [])

test/retest/options/help.txt

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@ Arguments:
99

1010

1111
Options:
12-
--all Run all the specs of a specificied ruby setup
13-
--diff=git-branch Pipes all matching tests from diffed branch to test
14-
command
15-
--ext=regex Regex of file extensions to listen to (default
16-
"\\.rb$")
17-
-h, --help Print usage
18-
--notify Play a sound when specs pass or fail (macOS only)
19-
--polling Use polling method when listening to file changes
20-
Some filesystems won't work without it
21-
VM/Vagrant Shared folders, NFS, Samba, sshfs...
22-
--rails Shortcut for a standard Rails setup
23-
--rake Shortcut for a standard Rake setup
24-
--rspec Shortcut for a standard RSpec setup
25-
--ruby Shortcut for a Ruby project
26-
-v, --version Print retest version
12+
--all Run all the specs of a specificied ruby setup
13+
--diff=git-branch Pipes all matching tests from diffed branch to test
14+
command
15+
--exts=<EXTENSIONS> Comma separated of filenames extensions to filter
16+
to (default "rb")
17+
-h, --help Print usage
18+
--notify Play a sound when specs pass or fail (macOS only)
19+
--polling Use polling method when listening to file changes
20+
Some filesystems won't work without it
21+
VM/Vagrant Shared folders, NFS, Samba, sshfs...
22+
--rails Shortcut for a standard Rails setup
23+
--rake Shortcut for a standard Rake setup
24+
--rspec Shortcut for a standard RSpec setup
25+
--ruby Shortcut for a Ruby project
26+
-v, --version Print retest version
2727

2828
Examples:
2929
Runs a matching rails test after a file change

test/retest/options_test.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,24 @@ def test_notify?
4949
assert @subject.notify?
5050
end
5151

52+
def test_exts
53+
@subject.args = ["--exts rb"]
54+
55+
assert @subject.extensions.match? "a/file/path.rb"
56+
refute @subject.extensions.match? "a/file/path.js"
57+
refute @subject.extensions.match? "a/file/path.ts"
58+
refute @subject.extensions.match? "a/file/path.css"
59+
refute @subject.extensions.match? "a/file/path.html"
60+
61+
@subject.args = ["--exts rb,js, html,css ,ts"]
62+
63+
assert @subject.extensions.match? "a/file/path.rb"
64+
assert @subject.extensions.match? "a/file/path.js"
65+
assert @subject.extensions.match? "a/file/path.ts"
66+
assert @subject.extensions.match? "a/file/path.css"
67+
assert @subject.extensions.match? "a/file/path.html"
68+
end
69+
5270
def test_all_version_copy
5371
@subject.args = %w[--notify --rake]
5472

test/retest_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class ListenTests < MiniTest::Test
1313

1414
def test_listen_default_behaviour
1515
listener = MiniTest::Mock.new
16-
expected_options = {relative: true, only: Regexp.new('\\.rb$'), force_polling: false}
16+
expected_options = {relative: true, only: Regexp.new('\\.(?:rb)$'), force_polling: false}
1717

1818
listener.expect(:to, Struct.new(:start).new, ['.', expected_options])
1919

@@ -24,7 +24,7 @@ def test_listen_default_behaviour
2424

2525
def test_listen_when_polling
2626
listener = MiniTest::Mock.new
27-
expected_options = {relative: true, only: Regexp.new('\\.rb$'), force_polling: true}
27+
expected_options = {relative: true, only: Regexp.new('\\.(?:rb)$'), force_polling: true}
2828

2929
listener.expect(:to, Struct.new(:start).new, ['.', expected_options])
3030

0 commit comments

Comments
 (0)