Skip to content

Commit d334295

Browse files
committed
Update the watchexec feature specs
1 parent 4bb9be4 commit d334295

File tree

6 files changed

+57
-57
lines changed

6 files changed

+57
-57
lines changed

features/watchexec-ruby-app/Dockerfile

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
FROM ruby:2.5.9-alpine3.13
1+
FROM rust:1.83.0-slim-bullseye
22

3-
ARG BUILD_PACKAGES="build-base git"
3+
ARG BUILD_PACKAGES="build-essentials git"
44

5-
RUN apk update && \
6-
apk upgrade && \
7-
apk add --update --no-cache $BUILD_PACKAGES && \
8-
rm -rf /var/cache/apk/*
5+
RUN apt-get update -qq && \
6+
apt-get install --no-install-recommends -y build-essential git ruby ruby-dev
7+
8+
RUN cargo install cargo-binstall
9+
RUN cargo binstall watchexec-cli
910

1011
# throw errors if Gemfile has been modified since Gemfile.lock
12+
RUN gem install bundler
1113
RUN bundle config --global frozen 1
1214

1315
WORKDIR /usr/src/app
@@ -18,11 +20,8 @@ ENV BUNDLER_VERSION 2.1
1820
ENV GEM_HOME="/usr/local/bundle"
1921
ENV PATH $GEM_HOME/bin:$GEM_HOME/gems/bin:$PATH
2022

21-
COPY watchexec /usr/bin/
22-
2323
COPY Gemfile Gemfile.lock retest.gem ./
24-
RUN gem update --system 3.2.3
25-
RUN gem install bundler -v 2.1.4
24+
2625
RUN bundle config --delete frozen
2726
RUN bundle install
2827
RUN gem install retest.gem

features/watchexec-ruby-app/retest/retest_test.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'retest'
2+
require 'byebug'
23
require_relative 'support/test_helper'
34
require 'minitest/autorun'
45
require_relative 'retest_test/file_changes_test'
@@ -8,6 +9,7 @@
89
$stdout.sync = true
910

1011
include FileHelper
12+
include OutputHelper
1113

1214
module WatchexecRuby
1315
COMMAND = 'retest'

features/watchexec-ruby-app/retest/retest_test/file_changes_test.rb

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def teardown
77
def test_start_retest
88
launch_retest(COMMAND)
99

10-
assert_match <<~EXPECTED, @output.read
10+
assert_match <<~EXPECTED, read_output
1111
Setup identified: [RUBY]. Using command: 'bundle exec ruby <test>'
1212
Watcher: [WATCHEXEC]
1313
Launching Retest...
@@ -16,50 +16,54 @@ def test_start_retest
1616
end
1717

1818
def test_modifying_existing_file
19-
launch_retest @command
19+
launch_retest(COMMAND)
2020

2121
modify_file('lib/bottles.rb')
2222

23-
assert_match "Test file: test/bottles_test.rb", @output.read
24-
assert_match "12 runs, 12 assertions, 0 failures, 0 errors, 0 skips", @output.read
23+
read_output do |output|
24+
assert_match "Test file: test/bottles_test.rb", output
25+
assert_match "12 runs, 12 assertions, 0 failures, 0 errors, 0 skips", output
26+
end
2527
end
2628

2729
def test_modifying_existing_test_file
28-
launch_retest @command
30+
launch_retest(COMMAND)
2931

3032
modify_file('test/bottles_test.rb')
3133

32-
assert_match "Test file: test/bottles_test.rb", @output.read
33-
assert_match "12 runs, 12 assertions, 0 failures, 0 errors, 0 skips", @output.read
34+
read_output do |output|
35+
assert_match "Test file: test/bottles_test.rb", output
36+
assert_match "12 runs, 12 assertions, 0 failures, 0 errors, 0 skips", output
37+
end
3438
end
3539

3640
def test_creating_a_new_test_file
37-
launch_retest @command
41+
launch_retest(COMMAND)
3842

3943
create_file 'foo_test.rb'
4044

41-
assert_match "Test file: foo_test.rb", @output.read
45+
assert_match "Test file: foo_test.rb", read_output
4246

4347
ensure
4448
delete_file 'foo_test.rb'
4549
end
4650

4751
def test_creating_a_new_file
48-
launch_retest @command
52+
launch_retest(COMMAND)
4953

5054
create_file 'foo.rb'
51-
assert_match <<~EXPECTED, @output.read
55+
assert_match <<~EXPECTED, read_output
5256
FileNotFound - Retest could not find a matching test file to run.
5357
EXPECTED
5458

5559
create_file 'foo_test.rb'
56-
assert_match "Test file: foo_test.rb", @output.read
60+
assert_match "Test file: foo_test.rb", read_output
5761

5862
modify_file('lib/bottles.rb')
59-
assert_match "Test file: test/bottles_test.rb", @output.read
63+
assert_match "Test file: test/bottles_test.rb", read_output
6064

6165
modify_file('foo.rb')
62-
assert_match "Test file: foo_test.rb", @output.read
66+
assert_match "Test file: foo_test.rb", read_output
6367

6468
ensure
6569
delete_file 'foo.rb'
@@ -70,10 +74,10 @@ def test_untracked_file
7074
create_file 'foo.rb', should_sleep: false
7175
create_file 'foo_test.rb', should_sleep: false
7276

73-
launch_retest @command
77+
launch_retest(COMMAND)
7478

7579
modify_file 'foo.rb'
76-
assert_match "Test file: foo_test.rb", @output.read
80+
assert_match "Test file: foo_test.rb", read_output
7781

7882
ensure
7983
delete_file 'foo.rb'

features/watchexec-ruby-app/retest/retest_test/matching_unmatching_command_test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ def test_displaying_options_on_matching_command
1010
launch_retest(COMMAND)
1111

1212
create_file 'foo_test.rb'
13-
assert_match "Test file: foo_test.rb", @output.read
13+
assert_match "Test file: foo_test.rb", read_output
1414

1515
modify_file('lib/bottles.rb')
16-
assert_match <<~EXPECTED.chomp, @output.read
16+
assert_match <<~EXPECTED.chomp, read_output
1717
We found few tests matching: lib/bottles.rb
1818
1919
[0] - test/bottles_test.rb
@@ -28,7 +28,7 @@ def test_displaying_options_on_matching_command
2828
@input.write "2\n"
2929
wait
3030

31-
assert_match "Test file: foo_test.rb", @output.read
31+
assert_match "Test file: foo_test.rb", read_output
3232

3333
ensure
3434
delete_file 'foo_test.rb'

features/watchexec-ruby-app/retest/support/output_file.rb

Lines changed: 0 additions & 21 deletions
This file was deleted.

features/watchexec-ruby-app/retest/support/test_helper.rb

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
11
# Can be updated to all feature repositories with
22
# $ bin/test/reset_helpers
33

4-
require_relative 'output_file'
4+
module OutputHelper
5+
def read_output(output = @output)
6+
result = ""
7+
loop do
8+
result += output.read_nonblock(1024)
9+
rescue IO::WaitReadable
10+
break
11+
end
12+
13+
if block_given?
14+
yield result
15+
else
16+
result
17+
end
18+
end
19+
end
520

621
module FileHelper
722
def default_sleep_seconds
@@ -45,18 +60,19 @@ def rename_file(path, new_path)
4560
end
4661

4762
def launch_retest(command, sleep_seconds: launch_sleep_seconds)
48-
@rd, @input = IO.pipe
49-
@output = OutputFile.new
50-
@pid = Process.spawn command, out: @output.path, in: @rd
63+
require 'open3'
64+
@input, @output, @stderr, @wait_thr = Open3.popen3(command)
65+
@pid = @wait_thr[:pid]
5166
sleep sleep_seconds
5267
end
5368

54-
def end_retest(file = nil, pid = nil)
55-
@output&.delete
56-
@rd&.close
69+
def end_retest
5770
@input&.close
71+
@stderr&.close
72+
@output&.close
5873
if @pid
5974
Process.kill('SIGHUP', @pid)
6075
Process.detach(@pid)
6176
end
6277
end
78+

0 commit comments

Comments
 (0)