Skip to content

Commit

Permalink
Merge ruby-app to use both watchexec and listen watchers
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexB52 committed Dec 5, 2024
1 parent 2deadc8 commit 68b7774
Show file tree
Hide file tree
Showing 27 changed files with 207 additions and 776 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ jobs:
- rspec-rails
- rspec-ruby
- bundler-app
- watchexec-ruby-app
steps:
- uses: actions/checkout@v4
- name: Set up Ruby
Expand Down
4 changes: 2 additions & 2 deletions bin/test/ruby-app
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

bundle install
bundle exec rake build
cp -R features/support features/ruby-app/retest
# cp -R features/support features/ruby-app/retest
ls -t pkg | head -n1 | xargs -I {} mv pkg/{} features/ruby-app/retest.gem
docker compose -f features/ruby-app/docker-compose.yml up --build --exit-code-from retest
docker compose -f features/ruby-app/docker-compose.yml up --build --exit-code-from retest
7 changes: 0 additions & 7 deletions bin/test/watchexec-ruby-app

This file was deleted.

17 changes: 10 additions & 7 deletions features/ruby-app/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
FROM ruby:2.5.9-alpine3.13
FROM ruby:2.7-slim-bullseye

ARG BUILD_PACKAGES="build-base git"
# Install necessary dependencies
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y build-essential git && \
apt-get clean && rm -rf /var/lib/apt/lists/*

RUN apk update && \
apk upgrade && \
apk add --update --no-cache $BUILD_PACKAGES && \
rm -rf /var/cache/apk/*
# Copy watchexec from the Rust stage
COPY --from=ghcr.io/alexb52/slim-bullseye-watchexec:latest /usr/local/cargo/bin/watchexec /usr/local/bin/watchexec

# Verify watchexec installation in the final image
RUN watchexec --version

# throw errors if Gemfile has been modified since Gemfile.lock
RUN bundle config --global frozen 1
Expand All @@ -14,7 +18,6 @@ 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

Expand Down
83 changes: 77 additions & 6 deletions features/ruby-app/retest/retest_test.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,83 @@
require 'retest'
require_relative 'support/test_helper'
require 'byebug'
require 'minitest/autorun'
require_relative 'retest_test/file_changes_test'
require_relative 'retest_test/flags_test'
require_relative 'retest_test/setup_test'
require_relative 'retest_test/matching_unmatching_command_test'
require_relative 'support/test_helper'
require_relative 'shared/file_changes'
require_relative 'shared/setup'
require_relative 'shared/explicit_matching'

$stdout.sync = true

include FileHelper
class TestListenWatcher < Minitest::Test
# Helpers
include FileHelper
include OutputHelper
include CommandHelper

# Assertions
include Setup
include FileChanges
include ExplicitMatching

def setup
@command = 'retest -w listen'
end

def test_start_retest
launch_retest(@command)

assert_match <<~EXPECTED, read_output
Setup identified: [RUBY]. Using command: 'bundle exec ruby <test>'
Watcher: [LISTEN]
Launching Retest...
Ready to refactor! You can make file changes now
EXPECTED
end
end

class TestWatchexecWatcher < Minitest::Test
# Helpers
include FileHelper
include OutputHelper
include CommandHelper

# Assertions
include Setup
include FileChanges
include ExplicitMatching

def setup
@command = 'retest -w watchexec'
end

def test_start_retest
launch_retest(@command)

assert_match <<~EXPECTED, read_output
Setup identified: [RUBY]. Using command: 'bundle exec ruby <test>'
Watcher: [WATCHEXEC]
Launching Retest...
Ready to refactor! You can make file changes now
EXPECTED
end
end

class TestDefaultWatcher < Minitest::Test
include OutputHelper
include CommandHelper

def setup
@command = 'retest'
end

def test_uses_watchexec_when_installed
launch_retest(@command)

assert_match <<~EXPECTED, read_output
Setup identified: [RUBY]. Using command: 'bundle exec ruby <test>'
Watcher: [WATCHEXEC]
Launching Retest...
Ready to refactor! You can make file changes now
EXPECTED
end
end
83 changes: 0 additions & 83 deletions features/ruby-app/retest/retest_test/file_changes_test.rb

This file was deleted.

23 changes: 0 additions & 23 deletions features/ruby-app/retest/retest_test/flags_test.rb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,30 +1,18 @@
class MatchingUnmatchingCommandTest < Minitest::Test
def setup
create_file('test/other_bottles_test.rb', should_sleep: false)
end

module ExplicitMatching
def teardown
end_retest
delete_file('test/other_bottles_test.rb')
end

def test_not_displaying_options_on_unmatching_command
launch_retest "retest 'echo there was no command'"

modify_file('lib/bottles.rb')

refute_match "We found few tests matching:", @output.read
assert_match "there was no command", @output.read
end

def test_displaying_options_on_matching_command
launch_retest('retest --ruby')
create_file('test/other_bottles_test.rb', should_sleep: false)

launch_retest(@command)

create_file 'foo_test.rb'
assert_match "Test file: foo_test.rb", @output.read
assert_match "Test file: foo_test.rb", read_output

modify_file('lib/bottles.rb')
assert_match <<~EXPECTED.chomp, @output.read
assert_match <<~EXPECTED.chomp, read_output
We found few tests matching: lib/bottles.rb
[0] - test/bottles_test.rb
Expand All @@ -39,9 +27,10 @@ def test_displaying_options_on_matching_command
@input.write "2\n"
wait

assert_match "Test file: foo_test.rb", @output.read
assert_match "Test file: foo_test.rb", read_output

ensure
delete_file 'foo_test.rb'
delete_file('test/other_bottles_test.rb')
end
end
74 changes: 74 additions & 0 deletions features/ruby-app/retest/shared/file_changes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
module FileChanges
def teardown
end_retest
end

def test_modifying_existing_file
launch_retest(@command)

modify_file('lib/bottles.rb')

read_output do |output|
assert_match "Test file: test/bottles_test.rb", output
assert_match "12 runs, 12 assertions, 0 failures, 0 errors, 0 skips", output
end
end

def test_modifying_existing_test_file
launch_retest(@command)

modify_file('test/bottles_test.rb')

read_output do |output|
assert_match "Test file: test/bottles_test.rb", output
assert_match "12 runs, 12 assertions, 0 failures, 0 errors, 0 skips", output
end
end

def test_creating_a_new_test_file
launch_retest(@command)

create_file 'foo_test.rb'

assert_match "Test file: foo_test.rb", read_output

ensure
delete_file 'foo_test.rb'
end

def test_creating_a_new_file
launch_retest(@command)

create_file 'foo.rb'
assert_match <<~EXPECTED, read_output
FileNotFound - Retest could not find a matching test file to run.
EXPECTED

create_file 'foo_test.rb'
assert_match "Test file: foo_test.rb", read_output

modify_file('lib/bottles.rb')
assert_match "Test file: test/bottles_test.rb", read_output

modify_file('foo.rb')
assert_match "Test file: foo_test.rb", read_output

ensure
delete_file 'foo.rb'
delete_file 'foo_test.rb'
end

def test_untracked_file
create_file 'foo.rb', should_sleep: false
create_file 'foo_test.rb', should_sleep: false

launch_retest(@command)

modify_file 'foo.rb'
assert_match "Test file: foo_test.rb", read_output

ensure
delete_file 'foo.rb'
delete_file 'foo_test.rb'
end
end
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class SetupTest < Minitest::Test
module Setup
def test_repository_setup
assert_equal :ruby, Retest::Setup.new.type
end
end
end
Loading

0 comments on commit 68b7774

Please sign in to comment.