diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e90626dd..d0e23247 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -55,7 +55,6 @@ jobs: - rspec-rails - rspec-ruby - bundler-app - - watchexec-ruby-app steps: - uses: actions/checkout@v4 - name: Set up Ruby diff --git a/bin/test/ruby-app b/bin/test/ruby-app index 135554a0..5b314ad1 100755 --- a/bin/test/ruby-app +++ b/bin/test/ruby-app @@ -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 \ No newline at end of file +docker compose -f features/ruby-app/docker-compose.yml up --build --exit-code-from retest diff --git a/bin/test/watchexec-ruby-app b/bin/test/watchexec-ruby-app deleted file mode 100755 index 689edf80..00000000 --- a/bin/test/watchexec-ruby-app +++ /dev/null @@ -1,7 +0,0 @@ -#!/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 diff --git a/features/ruby-app/Dockerfile b/features/ruby-app/Dockerfile index f52b6c3f..a8964376 100644 --- a/features/ruby-app/Dockerfile +++ b/features/ruby-app/Dockerfile @@ -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 @@ -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 diff --git a/features/ruby-app/retest/retest_test.rb b/features/ruby-app/retest/retest_test.rb index f48ba94a..7c34966b 100644 --- a/features/ruby-app/retest/retest_test.rb +++ b/features/ruby-app/retest/retest_test.rb @@ -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 ' + 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 ' + 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 ' + Watcher: [WATCHEXEC] + Launching Retest... + Ready to refactor! You can make file changes now + EXPECTED + end +end diff --git a/features/ruby-app/retest/retest_test/file_changes_test.rb b/features/ruby-app/retest/retest_test/file_changes_test.rb deleted file mode 100644 index 83faa66d..00000000 --- a/features/ruby-app/retest/retest_test/file_changes_test.rb +++ /dev/null @@ -1,83 +0,0 @@ -class FileChangesTest < Minitest::Test - def setup - @command = 'retest --ruby' - end - - def teardown - end_retest - end - - def test_start_retest - launch_retest @command - - assert_match <<~EXPECTED, @output.read - Launching Retest... - Ready to refactor! You can make file changes now - EXPECTED - end - - def test_modifying_existing_file - launch_retest @command - - modify_file('lib/bottles.rb') - - assert_match "Test file: test/bottles_test.rb", @output.read - assert_match "12 runs, 12 assertions, 0 failures, 0 errors, 0 skips", @output.read - end - - def test_modifying_existing_test_file - launch_retest @command - - modify_file('test/bottles_test.rb') - - assert_match "Test file: test/bottles_test.rb", @output.read - assert_match "12 runs, 12 assertions, 0 failures, 0 errors, 0 skips", @output.read - end - - def test_creating_a_new_test_file - launch_retest @command - - create_file 'foo_test.rb' - - assert_match "Test file: foo_test.rb", @output.read - - ensure - delete_file 'foo_test.rb' - end - - def test_creating_a_new_file - launch_retest @command - - create_file 'foo.rb' - assert_match <<~EXPECTED, @output.read - FileNotFound - Retest could not find a matching test file to run. - EXPECTED - - create_file 'foo_test.rb' - assert_match "Test file: foo_test.rb", @output.read - - modify_file('lib/bottles.rb') - assert_match "Test file: test/bottles_test.rb", @output.read - - modify_file('foo.rb') - assert_match "Test file: foo_test.rb", @output.read - - 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", @output.read - - ensure - delete_file 'foo.rb' - delete_file 'foo_test.rb' - end -end diff --git a/features/ruby-app/retest/retest_test/flags_test.rb b/features/ruby-app/retest/retest_test/flags_test.rb deleted file mode 100644 index 73e6b732..00000000 --- a/features/ruby-app/retest/retest_test/flags_test.rb +++ /dev/null @@ -1,23 +0,0 @@ -class FlagTest < Minitest::Test - def setup - end - - def teardown - end_retest - end - - def test_with_no_command - launch_retest 'retest' - - assert_match <<~OUTPUT, @output.read - Setup identified: [RUBY]. Using command: 'bundle exec ruby ' - Watcher: [LISTEN] - Launching Retest... - Ready to refactor! You can make file changes now - OUTPUT - - modify_file('lib/bottles.rb') - - assert_match "Test file: test/bottles_test.rb", @output.read - end -end \ No newline at end of file diff --git a/features/ruby-app/retest/retest_test/matching_unmatching_command_test.rb b/features/ruby-app/retest/shared/explicit_matching.rb similarity index 52% rename from features/ruby-app/retest/retest_test/matching_unmatching_command_test.rb rename to features/ruby-app/retest/shared/explicit_matching.rb index 0714afbd..1bff62f1 100644 --- a/features/ruby-app/retest/retest_test/matching_unmatching_command_test.rb +++ b/features/ruby-app/retest/shared/explicit_matching.rb @@ -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 @@ -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 diff --git a/features/ruby-app/retest/shared/file_changes.rb b/features/ruby-app/retest/shared/file_changes.rb new file mode 100644 index 00000000..2ea0115d --- /dev/null +++ b/features/ruby-app/retest/shared/file_changes.rb @@ -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 diff --git a/features/ruby-app/retest/retest_test/setup_test.rb b/features/ruby-app/retest/shared/setup.rb similarity index 69% rename from features/ruby-app/retest/retest_test/setup_test.rb rename to features/ruby-app/retest/shared/setup.rb index 346af806..5bcb57a1 100644 --- a/features/ruby-app/retest/retest_test/setup_test.rb +++ b/features/ruby-app/retest/shared/setup.rb @@ -1,5 +1,5 @@ -class SetupTest < Minitest::Test +module Setup def test_repository_setup assert_equal :ruby, Retest::Setup.new.type end -end \ No newline at end of file +end diff --git a/features/ruby-app/retest/support/output_file.rb b/features/ruby-app/retest/support/output_file.rb deleted file mode 100644 index c58f646e..00000000 --- a/features/ruby-app/retest/support/output_file.rb +++ /dev/null @@ -1,21 +0,0 @@ -class OutputFile - attr_reader :output - def initialize - @output = Tempfile.new - end - - def path - @output.path - end - - def read - @output.rewind - @output.read.split('').last - end - - def delete - @output.close - @output.unlink - end - alias :clear :delete -end diff --git a/features/ruby-app/retest/support/test_helper.rb b/features/ruby-app/retest/support/test_helper.rb index 2b41621f..d50ea30a 100644 --- a/features/ruby-app/retest/support/test_helper.rb +++ b/features/ruby-app/retest/support/test_helper.rb @@ -1,4 +1,22 @@ -require_relative 'output_file' +# Can be updated to all feature repositories with +# $ bin/test/reset_helpers + +module OutputHelper + def read_output(output = @output) + result = "" + loop do + result += output.read_nonblock(1024) + rescue IO::WaitReadable + break + end + + if block_given? + yield result + else + result + end + end +end module FileHelper def default_sleep_seconds @@ -41,19 +59,21 @@ def rename_file(path, new_path) end end -def launch_retest(command, sleep_seconds: launch_sleep_seconds) - @rd, @input = IO.pipe - @output = OutputFile.new - @pid = Process.spawn command, out: @output.path, in: @rd - sleep sleep_seconds -end +module CommandHelper + def launch_retest(command, sleep_seconds: Float(ENV.fetch('LAUNCH_SLEEP_SECONDS', 1.5))) + require 'open3' + @input, @output, @stderr, @wait_thr = Open3.popen3(command) + @pid = @wait_thr[:pid] + sleep sleep_seconds + end -def end_retest(file = nil, pid = nil) - @output&.delete - @rd&.close - @input&.close - if @pid - Process.kill('SIGHUP', @pid) - Process.detach(@pid) + def end_retest + @input&.close + @stderr&.close + @output&.close + if @pid + Process.kill('SIGHUP', @pid) + Process.detach(@pid) + end end end diff --git a/features/watchexec-ruby-app/.gitignore b/features/watchexec-ruby-app/.gitignore deleted file mode 100644 index 4e317b77..00000000 --- a/features/watchexec-ruby-app/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -.ruby-version -retest.gem -/tmp/* \ No newline at end of file diff --git a/features/watchexec-ruby-app/Dockerfile b/features/watchexec-ruby-app/Dockerfile deleted file mode 100644 index a8964376..00000000 --- a/features/watchexec-ruby-app/Dockerfile +++ /dev/null @@ -1,33 +0,0 @@ -FROM ruby:2.7-slim-bullseye - -# 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/* - -# 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 - -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 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"] \ No newline at end of file diff --git a/features/watchexec-ruby-app/Gemfile b/features/watchexec-ruby-app/Gemfile deleted file mode 100644 index d0c3b25a..00000000 --- a/features/watchexec-ruby-app/Gemfile +++ /dev/null @@ -1,3 +0,0 @@ -source 'https://rubygems.org' -gem 'minitest', '~> 5.4' -gem 'byebug' \ No newline at end of file diff --git a/features/watchexec-ruby-app/Gemfile.lock b/features/watchexec-ruby-app/Gemfile.lock deleted file mode 100644 index fd16f24d..00000000 --- a/features/watchexec-ruby-app/Gemfile.lock +++ /dev/null @@ -1,15 +0,0 @@ -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 diff --git a/features/watchexec-ruby-app/LICENSE b/features/watchexec-ruby-app/LICENSE deleted file mode 100644 index 7d5afaec..00000000 --- a/features/watchexec-ruby-app/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -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. diff --git a/features/watchexec-ruby-app/README.md b/features/watchexec-ruby-app/README.md deleted file mode 100644 index b5fbae12..00000000 --- a/features/watchexec-ruby-app/README.md +++ /dev/null @@ -1,23 +0,0 @@ -# 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/ diff --git a/features/watchexec-ruby-app/docker-compose.yml b/features/watchexec-ruby-app/docker-compose.yml deleted file mode 100644 index c474455f..00000000 --- a/features/watchexec-ruby-app/docker-compose.yml +++ /dev/null @@ -1,9 +0,0 @@ -services: - retest: - build: . - volumes: - - .:/usr/src/app - environment: - - DEFAULT_SLEEP_SECONDS=1 - - LAUNCH_SLEEP_SECONDS=1.5 - command: ruby retest/retest_test.rb diff --git a/features/watchexec-ruby-app/lib/bottles.rb b/features/watchexec-ruby-app/lib/bottles.rb deleted file mode 100644 index 48878942..00000000 --- a/features/watchexec-ruby-app/lib/bottles.rb +++ /dev/null @@ -1,119 +0,0 @@ -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 diff --git a/features/watchexec-ruby-app/retest/retest_test.rb b/features/watchexec-ruby-app/retest/retest_test.rb deleted file mode 100644 index 91b8899e..00000000 --- a/features/watchexec-ruby-app/retest/retest_test.rb +++ /dev/null @@ -1,16 +0,0 @@ -require 'retest' -require 'byebug' -require_relative 'support/test_helper' -require 'minitest/autorun' -require_relative 'retest_test/file_changes_test' -require_relative 'retest_test/setup_test' -require_relative 'retest_test/matching_unmatching_command_test' - -$stdout.sync = true - -include FileHelper -include OutputHelper - -module WatchexecRuby - COMMAND = 'retest' -end diff --git a/features/watchexec-ruby-app/retest/retest_test/file_changes_test.rb b/features/watchexec-ruby-app/retest/retest_test/file_changes_test.rb deleted file mode 100644 index 0ae71497..00000000 --- a/features/watchexec-ruby-app/retest/retest_test/file_changes_test.rb +++ /dev/null @@ -1,87 +0,0 @@ -module WatchexecRuby - class FileChangesTest < Minitest::Test - def teardown - end_retest - end - - def test_start_retest - launch_retest(COMMAND) - - assert_match <<~EXPECTED, read_output - Setup identified: [RUBY]. Using command: 'bundle exec ruby ' - Watcher: [WATCHEXEC] - Launching Retest... - Ready to refactor! You can make file changes now - EXPECTED - 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 -end \ No newline at end of file diff --git a/features/watchexec-ruby-app/retest/retest_test/matching_unmatching_command_test.rb b/features/watchexec-ruby-app/retest/retest_test/matching_unmatching_command_test.rb deleted file mode 100644 index 5f652354..00000000 --- a/features/watchexec-ruby-app/retest/retest_test/matching_unmatching_command_test.rb +++ /dev/null @@ -1,38 +0,0 @@ -module WatchexecRuby - class MatchingUnmatchingCommandTest < Minitest::Test - def teardown - end_retest - end - - def test_displaying_options_on_matching_command - 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", read_output - - modify_file('lib/bottles.rb') - assert_match <<~EXPECTED.chomp, read_output - We found few tests matching: lib/bottles.rb - - [0] - test/bottles_test.rb - [1] - test/other_bottles_test.rb - [2] - none - - Which file do you want to use? - Enter the file number now: - > - EXPECTED - - @input.write "2\n" - wait - - assert_match "Test file: foo_test.rb", read_output - - ensure - delete_file 'foo_test.rb' - delete_file('test/other_bottles_test.rb') - end - end -end diff --git a/features/watchexec-ruby-app/retest/retest_test/setup_test.rb b/features/watchexec-ruby-app/retest/retest_test/setup_test.rb deleted file mode 100644 index 5c178d1e..00000000 --- a/features/watchexec-ruby-app/retest/retest_test/setup_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -module WatchexecRuby - class SetupTest < Minitest::Test - def test_repository_setup - assert_equal :ruby, Retest::Setup.new.type - end - end -end \ No newline at end of file diff --git a/features/watchexec-ruby-app/retest/support/test_helper.rb b/features/watchexec-ruby-app/retest/support/test_helper.rb deleted file mode 100644 index 70848e6d..00000000 --- a/features/watchexec-ruby-app/retest/support/test_helper.rb +++ /dev/null @@ -1,78 +0,0 @@ -# Can be updated to all feature repositories with -# $ bin/test/reset_helpers - -module OutputHelper - def read_output(output = @output) - result = "" - loop do - result += output.read_nonblock(1024) - rescue IO::WaitReadable - break - end - - if block_given? - yield result - else - result - end - end -end - -module FileHelper - def default_sleep_seconds - Float(ENV.fetch('DEFAULT_SLEEP_SECONDS', 1)) - end - - def launch_sleep_seconds - Float(ENV.fetch('LAUNCH_SLEEP_SECONDS', 1.5)) - end - - def wait(sleep_seconds: default_sleep_seconds) - sleep sleep_seconds - end - - def modify_file(path, sleep_seconds: default_sleep_seconds) - return unless File.exist? path - - old_content = File.read(path) - File.open(path, 'w') { |file| file.write old_content } - - sleep sleep_seconds - end - - def create_file(path, should_sleep: true, sleep_seconds: default_sleep_seconds) - File.open(path, "w").tap(&:close) - - sleep sleep_seconds if should_sleep - end - - def delete_file(path) - return unless File.exist? path - - File.delete path - end - - def rename_file(path, new_path) - return unless File.exist? path - - File.rename path, new_path - end -end - -def launch_retest(command, sleep_seconds: launch_sleep_seconds) - require 'open3' - @input, @output, @stderr, @wait_thr = Open3.popen3(command) - @pid = @wait_thr[:pid] - sleep sleep_seconds -end - -def end_retest - @input&.close - @stderr&.close - @output&.close - if @pid - Process.kill('SIGHUP', @pid) - Process.detach(@pid) - end -end - diff --git a/features/watchexec-ruby-app/test/bottles_test.rb b/features/watchexec-ruby-app/test/bottles_test.rb deleted file mode 100644 index 0f0e240a..00000000 --- a/features/watchexec-ruby-app/test/bottles_test.rb +++ /dev/null @@ -1,139 +0,0 @@ -gem 'minitest', '~> 5.4' -require 'minitest/autorun' -require 'minitest/pride' -require_relative '../lib/bottles' - -module VerseRoleTest - def test_plays_verse_role - assert_respond_to @role_player, :lyrics - end -end - -class VerseFake - def self.lyrics(number) - "This is verse #{number}.\n" - end -end - -class VerseFakeTest < Minitest::Test - include VerseRoleTest - - def setup - @role_player = VerseFake - end -end - - -class BottleVerseTest < Minitest::Test - include VerseRoleTest - - def setup - @role_player = BottleVerse - end - - def test_verse_general_rule_upper_bound - expected = - "99 bottles of beer on the wall, " + - "99 bottles of beer.\n" + - "Take one down and pass it around, " + - "98 bottles of beer on the wall.\n" - assert_equal expected, BottleVerse.lyrics(99) - end - - def test_verse_general_rule_lower_bound - expected = - "3 bottles of beer on the wall, " + - "3 bottles of beer.\n" + - "Take one down and pass it around, " + - "2 bottles of beer on the wall.\n" - assert_equal expected, BottleVerse.lyrics(3) - end - - def test_verse_7 - expected = - "7 bottles of beer on the wall, " + - "7 bottles of beer.\n" + - "Take one down and pass it around, " + - "1 six-pack of beer on the wall.\n" - assert_equal expected, BottleVerse.lyrics(7) - end - - def test_verse_6 - expected = - "1 six-pack of beer on the wall, " + - "1 six-pack of beer.\n" + - "Take one down and pass it around, " + - "5 bottles of beer on the wall.\n" - assert_equal expected, BottleVerse.lyrics(6) - end - - def test_verse_2 - expected = - "2 bottles of beer on the wall, " + - "2 bottles of beer.\n" + - "Take one down and pass it around, " + - "1 bottle of beer on the wall.\n" - assert_equal expected, BottleVerse.lyrics(2) - end - - def test_verse_1 - expected = - "1 bottle of beer on the wall, " + - "1 bottle of beer.\n" + - "Take it down and pass it around, " + - "no more bottles of beer on the wall.\n" - assert_equal expected, BottleVerse.lyrics(1) - end - - def test_verse_0 - expected = - "No more bottles of beer on the wall, " + - "no more bottles of beer.\n" + - "Go to the store and buy some more, " + - "99 bottles of beer on the wall.\n" - assert_equal expected, BottleVerse.lyrics(0) - end -end - - -class CountdownSongTest < Minitest::Test - def test_verse - expected = "This is verse 500.\n" - assert_equal( - expected, - CountdownSong.new(verse_template: VerseFake) - .verse(500)) - end - - def test_verses - expected = - "This is verse 99.\n" + - "\n" + - "This is verse 98.\n" + - "\n" + - "This is verse 97.\n" - assert_equal( - expected, - CountdownSong.new(verse_template: VerseFake) - .verses(99, 97)) - end - - def test_song - expected = - "This is verse 47.\n" + - "\n" + - "This is verse 46.\n" + - "\n" + - "This is verse 45.\n" + - "\n" + - "This is verse 44.\n" + - "\n" + - "This is verse 43.\n" - assert_equal( - expected, - CountdownSong.new(verse_template: VerseFake, - max: 47, - min: 43) - .song) - end -end diff --git a/features/watchexec-ruby-app/watchexec b/features/watchexec-ruby-app/watchexec deleted file mode 100755 index 1b8b1738..00000000 Binary files a/features/watchexec-ruby-app/watchexec and /dev/null differ