Skip to content

Commit

Permalink
Create watcher option
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexB52 committed Nov 29, 2024
1 parent 6b901ef commit e888433
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/retest/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ class Options
convert :list
end

option :watcher do
desc "Tool used to watch file events"
permit %i[listen watchexec]
long "--watcher=<WATCHER>"
short "-w"
convert :sym
end

flag :all do
long "--all"
desc "Run all the specs of a specificied ruby setup"
Expand Down Expand Up @@ -160,6 +168,10 @@ def extensions
params[:exts]
end

def watcher
params[:watcher] || :listen
end

def extensions_regex
Regexp.new("\\.(?:#{extensions.join("|")})$")
end
Expand Down
2 changes: 2 additions & 0 deletions test/retest/options/help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Options:
--rspec Shortcut for a standard RSpec setup
--ruby Shortcut for a Ruby project
-v, --version Print retest version
-w, --watcher=<WATCHER> Tool used to watch file events (permitted: listen,
watchexec)

Examples:
Runs a matching rails test after a file change
Expand Down
20 changes: 20 additions & 0 deletions test/retest/options_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,25 @@ def test_all_version_copy
assert_equal %w[--notify --rake --all], copy.args
refute_equal copy.object_id, @subject.object_id
end

def test_listener
@subject.args = %w[--watcher=watchexec]
assert_equal :watchexec, @subject.watcher

@subject.args = %w[-w watchexec]
assert_equal :watchexec, @subject.watcher

@subject.args = %w[--watcher=listen]
assert_equal :listen, @subject.watcher

@subject.args = %w[-w listen]
assert_equal :listen, @subject.watcher

@subject.args = %w[-w hello]
assert_equal :listen, @subject.watcher

@subject.args = %w[] # default when no listeners are install by default
assert_equal :listen, @subject.watcher
end
end
end

0 comments on commit e888433

Please sign in to comment.