Skip to content

Commit

Permalink
Add Watchexec watcher as default when installed on machine
Browse files Browse the repository at this point in the history
  * Revert to Bundler 2.3.27
  * 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.
  * Display watcher used
  * Switch Listen to Wrapper Watcher::Default
  * Override watchexec with default watcher on CI
  * Allow VersionControl.files to take file extensions
  * Default to watchexec when installed
  * Remove .puts (for now)
  • Loading branch information
AlexB52 committed Dec 1, 2024
1 parent 4b17063 commit 81fc1b7
Show file tree
Hide file tree
Showing 37 changed files with 853 additions and 43 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ DEPENDENCIES
retest!

BUNDLED WITH
2.4.21
2.3.27
7 changes: 7 additions & 0 deletions bin/test/watchexec-ruby-app
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

bundle install
bundle exec rake build
cp -R features/support features/watchexec-ruby-app/retest
ls -t pkg | head -n1 | xargs -I {} mv pkg/{} features/watchexec-ruby-app/retest.gem
docker compose -f features/watchexec-ruby-app/docker-compose.yml up --build --exit-code-from retest
21 changes: 14 additions & 7 deletions exe/retest
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ require 'retest'
$stdout.sync = true
listen_rd, listen_wr = IO.pipe
Signal.trap(:INT) do
$stdout.puts "Goodbye"
puts "Goodbye"
listen_rd.close
listen_wr.close
exit
Expand All @@ -14,12 +14,12 @@ end
options = Retest::Options.new(ARGV)

if options.help?
$stdout.puts options.help
puts options.help
return
end

if options.version?
$stdout.puts Retest::VERSION
puts Retest::VERSION
return
end

Expand All @@ -28,6 +28,7 @@ repository = Retest::Repository.new(files: Retest::VersionControl.files, prompt:
command = Retest::Command.for_options(options)
runner = Retest::Runner.new(command)
sounds = Retest::Sounds.for(options)
watcher = Retest::Watcher.for(options.watcher)

sounds.play(:start)
runner.add_observer(sounds)
Expand All @@ -43,25 +44,31 @@ if options.params[:diff]
return
end

if watcher == Retest::Watcher::Watchexec
puts "Watcher: [WATCHEXEC]"
else Retest::Watcher::Default
puts "Watcher: [LISTEN]"
end

launching_message = "Launching Retest..."
if options.force_polling?
launching_message = "Launching Retest with polling method..."
end

# Main action

$stdout.puts launching_message
Retest.listen(options) do |modified, added, removed|
puts launching_message
Retest.listen(options, listener: watcher) do |modified, added, removed|
begin
repository.sync(added: added, removed: removed)
runner.sync(added: added, removed: removed)

listen_wr.puts "file changed: #{(modified + added).first}"
rescue => e
$stdout.puts "Something went wrong: #{e.message}"
puts "Something went wrong: #{e.message}"
end
end
$stdout.puts "Ready to refactor! You can make file changes now"
puts "Ready to refactor! You can make file changes now"

def run_command(input:, program:)
program.clear_terminal
Expand Down
2 changes: 2 additions & 0 deletions features/hanami-app/retest/retest_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def test_with_no_command

assert_match <<~OUTPUT, @output.read
Setup identified: [RAKE]. Using command: 'bundle exec rake test TEST=<test>'
Watcher: [LISTEN]
Launching Retest...
Ready to refactor! You can make file changes now
OUTPUT
Expand All @@ -81,6 +82,7 @@ def test_with_no_command_all

assert_match <<~OUTPUT, @output.read
Setup identified: [RAKE]. Using command: 'bundle exec rake test'
Watcher: [LISTEN]
Launching Retest...
Ready to refactor! You can make file changes now
OUTPUT
Expand Down
2 changes: 2 additions & 0 deletions features/rails-app/retest/retest_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def test_with_no_command

assert_match <<~OUTPUT, @output.read
Setup identified: [RAILS]. Using command: 'bin/rails test <test>'
Watcher: [LISTEN]
Launching Retest...
Ready to refactor! You can make file changes now
OUTPUT
Expand All @@ -81,6 +82,7 @@ def test_with_no_command_all

assert_match <<~OUTPUT, @output.read
Setup identified: [RAILS]. Using command: 'bin/rails test'
Watcher: [LISTEN]
Launching Retest...
Ready to refactor! You can make file changes now
OUTPUT
Expand Down
2 changes: 2 additions & 0 deletions features/rspec-rails/retest/retest_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def test_with_no_command

assert_match <<~OUTPUT, @output.read
Setup identified: [RSPEC]. Using command: 'bundle exec rspec <test>'
Watcher: [LISTEN]
Launching Retest...
Ready to refactor! You can make file changes now
OUTPUT
Expand All @@ -81,6 +82,7 @@ def test_with_no_command_all

assert_match <<~OUTPUT, @output.read
Setup identified: [RSPEC]. Using command: 'bundle exec rspec'
Watcher: [LISTEN]
Launching Retest...
Ready to refactor! You can make file changes now
OUTPUT
Expand Down
1 change: 1 addition & 0 deletions features/rspec-ruby/retest/retest_test/flags_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def test_with_no_command

assert_match <<~OUTPUT, @output.read
Setup identified: [RSPEC]. Using command: 'bundle exec rspec <test>'
Watcher: [LISTEN]
Launching Retest...
Ready to refactor! You can make file changes now
OUTPUT
Expand Down
1 change: 1 addition & 0 deletions features/ruby-app/retest/retest_test/flags_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def test_with_no_command

assert_match <<~OUTPUT, @output.read
Setup identified: [RUBY]. Using command: 'bundle exec ruby <test>'
Watcher: [LISTEN]
Launching Retest...
Ready to refactor! You can make file changes now
OUTPUT
Expand Down
1 change: 1 addition & 0 deletions features/ruby-bare/retest/scenarios/auto_flag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def test_start_retest

assert_match <<~OUTPUT, @output.read
Setup identified: [RUBY]. Using command: 'ruby <test>'
Watcher: [LISTEN]
Launching Retest...
Ready to refactor! You can make file changes now
OUTPUT
Expand Down
2 changes: 1 addition & 1 deletion features/ruby-bare/retest/scenarios/custom_extensions.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class CustomExtensionTest < Minitest::Test
def setup
@command = %Q{retest "echo 'I captured a change'" --ext="\\.txt$"}
@command = %Q{retest "echo 'I captured a change'" --exts="txt"}
end

def teardown
Expand Down
3 changes: 3 additions & 0 deletions features/watchexec-ruby-app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.ruby-version
retest.gem
/tmp/*
32 changes: 32 additions & 0 deletions features/watchexec-ruby-app/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
FROM ruby:2.5.9-alpine3.13

ARG BUILD_PACKAGES="build-base git"

RUN apk update && \
apk upgrade && \
apk add --update --no-cache $BUILD_PACKAGES && \
rm -rf /var/cache/apk/*

# throw errors if Gemfile has been modified since Gemfile.lock
RUN bundle config --global frozen 1

WORKDIR /usr/src/app

ENV LANG C.UTF-8
ENV BUNDLER_VERSION 2.1

ENV GEM_HOME="/usr/local/bundle"
ENV PATH $GEM_HOME/bin:$GEM_HOME/gems/bin:$PATH

COPY watchexec /usr/bin/

COPY Gemfile Gemfile.lock retest.gem ./
RUN gem update --system 3.2.3
RUN gem install bundler -v 2.1.4
RUN bundle config --delete frozen
RUN bundle install
RUN gem install retest.gem

COPY . /usr/src/app

CMD ["retest", "--ruby"]
3 changes: 3 additions & 0 deletions features/watchexec-ruby-app/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source 'https://rubygems.org'
gem 'minitest', '~> 5.4'
gem 'byebug'
15 changes: 15 additions & 0 deletions features/watchexec-ruby-app/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
GEM
remote: https://rubygems.org/
specs:
byebug (11.1.3)
minitest (5.14.0)

PLATFORMS
ruby

DEPENDENCIES
byebug
minitest (~> 5.4)

BUNDLED WITH
2.4.21
21 changes: 21 additions & 0 deletions features/watchexec-ruby-app/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Alexandre Barret

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
23 changes: 23 additions & 0 deletions features/watchexec-ruby-app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 99 Bottles

## Installing Ruby

### Windows

There's an installer, it's easy.
http://rubyinstaller.org/

### Mac

Newer macs ship with a usable version of Ruby.

Try `ruby -v` in a terminal window, and if it's 1.9.x or 2.x you're fine.

http://www.railstutorial.org/book/beginning#sec-install_ruby
http://tutorials.jumpstartlab.com/topics/environment/environment.html
http://docs.railsbridge.org/installfest/macintosh

### Linux

Ubuntu: http://docs.railsbridge.org/installfest/linux
https://www.ruby-lang.org/en/installation/
9 changes: 9 additions & 0 deletions features/watchexec-ruby-app/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
services:
retest:
build: .
volumes:
- .:/usr/src/app
environment:
- DEFAULT_SLEEP_SECONDS=1
- LAUNCH_SLEEP_SECONDS=1.5
command: ruby retest/retest_test.rb
119 changes: 119 additions & 0 deletions features/watchexec-ruby-app/lib/bottles.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
class CountdownSong
attr_reader :verse_template, :max, :min

def initialize(verse_template:, max: 999999, min: 0)
@verse_template = verse_template
@max, @min = max, min
end

def song
verses(max, min)
end

def verses(upper, lower)
upper.downto(lower).collect {|i| verse(i)}.join("\n")
end

def verse(number)
verse_template.lyrics(number)
end
end


class BottleVerse
def self.lyrics(number)
new(BottleNumber.for(number)).lyrics
end

attr_reader :bottle_number

def initialize(bottle_number)
@bottle_number = bottle_number
end

def lyrics
"#{bottle_number} of beer on the wall, ".capitalize +
"#{bottle_number} of beer.\n" +
"#{bottle_number.action}, " +
"#{bottle_number.successor} of beer on the wall.\n"
end
end


class BottleNumber
def self.for(number)
case number
when 0
BottleNumber0
when 1
BottleNumber1
when 6
BottleNumber6
else
BottleNumber
end.new(number)
end

attr_reader :number
def initialize(number)
@number = number
end

def to_s
"#{quantity} #{container}"
end

def quantity
number.to_s
end

def container
"bottles"
end

def action
"Take #{pronoun} down and pass it around"
end

def pronoun
"one"
end

def successor
BottleNumber.for(number - 1)
end
end

class BottleNumber0 < BottleNumber
def quantity
"no more"
end

def action
"Go to the store and buy some more"
end

def successor
BottleNumber.for(99)
end
end

class BottleNumber1 < BottleNumber
def container
"bottle"
end

def pronoun
"it"
end
end

class BottleNumber6 < BottleNumber
def quantity
"1"
end

def container
"six-pack"
end
end
Loading

0 comments on commit 81fc1b7

Please sign in to comment.