Skip to content

Commit 6b901ef

Browse files
committed
Create watchexec feature tests
1 parent 32a4397 commit 6b901ef

File tree

17 files changed

+595
-0
lines changed

17 files changed

+595
-0
lines changed

bin/test/watchexec-ruby-app

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
3+
bundle install
4+
bundle exec rake build
5+
cp -R features/support features/watchexec-ruby-app/retest
6+
ls -t pkg | head -n1 | xargs -I {} mv pkg/{} features/watchexec-ruby-app/retest.gem
7+
docker compose -f features/watchexec-ruby-app/docker-compose.yml up --build --exit-code-from retest
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.ruby-version
2+
retest.gem
3+
/tmp/*
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
FROM ruby:2.5.9-alpine3.13
2+
3+
ARG BUILD_PACKAGES="build-base git"
4+
5+
RUN apk update && \
6+
apk upgrade && \
7+
apk add --update --no-cache $BUILD_PACKAGES && \
8+
rm -rf /var/cache/apk/*
9+
10+
# throw errors if Gemfile has been modified since Gemfile.lock
11+
RUN bundle config --global frozen 1
12+
13+
WORKDIR /usr/src/app
14+
15+
ENV LANG C.UTF-8
16+
ENV BUNDLER_VERSION 2.1
17+
18+
ENV GEM_HOME="/usr/local/bundle"
19+
ENV PATH $GEM_HOME/bin:$GEM_HOME/gems/bin:$PATH
20+
21+
COPY watchexec /usr/bin/
22+
23+
COPY Gemfile Gemfile.lock retest.gem ./
24+
RUN gem update --system 3.2.3
25+
RUN gem install bundler -v 2.1.4
26+
RUN bundle config --delete frozen
27+
RUN bundle install
28+
RUN gem install retest.gem
29+
30+
COPY . /usr/src/app
31+
32+
CMD ["retest", "--ruby"]

features/watchexec-ruby-app/Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
source 'https://rubygems.org'
2+
gem 'minitest', '~> 5.4'
3+
gem 'byebug'
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
byebug (11.1.3)
5+
minitest (5.14.0)
6+
7+
PLATFORMS
8+
ruby
9+
10+
DEPENDENCIES
11+
byebug
12+
minitest (~> 5.4)
13+
14+
BUNDLED WITH
15+
2.4.21

features/watchexec-ruby-app/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Alexandre Barret
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

features/watchexec-ruby-app/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# 99 Bottles
2+
3+
## Installing Ruby
4+
5+
### Windows
6+
7+
There's an installer, it's easy.
8+
http://rubyinstaller.org/
9+
10+
### Mac
11+
12+
Newer macs ship with a usable version of Ruby.
13+
14+
Try `ruby -v` in a terminal window, and if it's 1.9.x or 2.x you're fine.
15+
16+
http://www.railstutorial.org/book/beginning#sec-install_ruby
17+
http://tutorials.jumpstartlab.com/topics/environment/environment.html
18+
http://docs.railsbridge.org/installfest/macintosh
19+
20+
### Linux
21+
22+
Ubuntu: http://docs.railsbridge.org/installfest/linux
23+
https://www.ruby-lang.org/en/installation/
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
services:
2+
retest:
3+
build: .
4+
volumes:
5+
- .:/usr/src/app
6+
environment:
7+
- DEFAULT_SLEEP_SECONDS=1
8+
- LAUNCH_SLEEP_SECONDS=1.5
9+
command: ruby retest/retest_test.rb
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
class CountdownSong
2+
attr_reader :verse_template, :max, :min
3+
4+
def initialize(verse_template:, max: 999999, min: 0)
5+
@verse_template = verse_template
6+
@max, @min = max, min
7+
end
8+
9+
def song
10+
verses(max, min)
11+
end
12+
13+
def verses(upper, lower)
14+
upper.downto(lower).collect {|i| verse(i)}.join("\n")
15+
end
16+
17+
def verse(number)
18+
verse_template.lyrics(number)
19+
end
20+
end
21+
22+
23+
class BottleVerse
24+
def self.lyrics(number)
25+
new(BottleNumber.for(number)).lyrics
26+
end
27+
28+
attr_reader :bottle_number
29+
30+
def initialize(bottle_number)
31+
@bottle_number = bottle_number
32+
end
33+
34+
def lyrics
35+
"#{bottle_number} of beer on the wall, ".capitalize +
36+
"#{bottle_number} of beer.\n" +
37+
"#{bottle_number.action}, " +
38+
"#{bottle_number.successor} of beer on the wall.\n"
39+
end
40+
end
41+
42+
43+
class BottleNumber
44+
def self.for(number)
45+
case number
46+
when 0
47+
BottleNumber0
48+
when 1
49+
BottleNumber1
50+
when 6
51+
BottleNumber6
52+
else
53+
BottleNumber
54+
end.new(number)
55+
end
56+
57+
attr_reader :number
58+
def initialize(number)
59+
@number = number
60+
end
61+
62+
def to_s
63+
"#{quantity} #{container}"
64+
end
65+
66+
def quantity
67+
number.to_s
68+
end
69+
70+
def container
71+
"bottles"
72+
end
73+
74+
def action
75+
"Take #{pronoun} down and pass it around"
76+
end
77+
78+
def pronoun
79+
"one"
80+
end
81+
82+
def successor
83+
BottleNumber.for(number - 1)
84+
end
85+
end
86+
87+
class BottleNumber0 < BottleNumber
88+
def quantity
89+
"no more"
90+
end
91+
92+
def action
93+
"Go to the store and buy some more"
94+
end
95+
96+
def successor
97+
BottleNumber.for(99)
98+
end
99+
end
100+
101+
class BottleNumber1 < BottleNumber
102+
def container
103+
"bottle"
104+
end
105+
106+
def pronoun
107+
"it"
108+
end
109+
end
110+
111+
class BottleNumber6 < BottleNumber
112+
def quantity
113+
"1"
114+
end
115+
116+
def container
117+
"six-pack"
118+
end
119+
end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
require 'retest'
2+
require_relative 'support/test_helper'
3+
require 'minitest/autorun'
4+
require_relative 'retest_test/file_changes_test'
5+
require_relative 'retest_test/setup_test'
6+
require_relative 'retest_test/matching_unmatching_command_test'
7+
8+
$stdout.sync = true
9+
10+
include FileHelper
11+
12+
module WatchexecRuby
13+
14+
COMMAND = 'retest -l watchexec'
15+
end
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
module WatchexecRuby
2+
class FileChangesTest < Minitest::Test
3+
def teardown
4+
end_retest
5+
end
6+
7+
def test_start_retest
8+
launch_retest(COMMAND)
9+
10+
assert_match <<~EXPECTED, @output.read
11+
Launching Retest...
12+
Ready to refactor! You can make file changes now
13+
EXPECTED
14+
end
15+
16+
def test_modifying_existing_file
17+
launch_retest @command
18+
19+
modify_file('lib/bottles.rb')
20+
21+
assert_match "Test file: test/bottles_test.rb", @output.read
22+
assert_match "12 runs, 12 assertions, 0 failures, 0 errors, 0 skips", @output.read
23+
end
24+
25+
def test_modifying_existing_test_file
26+
launch_retest @command
27+
28+
modify_file('test/bottles_test.rb')
29+
30+
assert_match "Test file: test/bottles_test.rb", @output.read
31+
assert_match "12 runs, 12 assertions, 0 failures, 0 errors, 0 skips", @output.read
32+
end
33+
34+
def test_creating_a_new_test_file
35+
launch_retest @command
36+
37+
create_file 'foo_test.rb'
38+
39+
assert_match "Test file: foo_test.rb", @output.read
40+
41+
ensure
42+
delete_file 'foo_test.rb'
43+
end
44+
45+
def test_creating_a_new_file
46+
launch_retest @command
47+
48+
create_file 'foo.rb'
49+
assert_match <<~EXPECTED, @output.read
50+
FileNotFound - Retest could not find a matching test file to run.
51+
EXPECTED
52+
53+
create_file 'foo_test.rb'
54+
assert_match "Test file: foo_test.rb", @output.read
55+
56+
modify_file('lib/bottles.rb')
57+
assert_match "Test file: test/bottles_test.rb", @output.read
58+
59+
modify_file('foo.rb')
60+
assert_match "Test file: foo_test.rb", @output.read
61+
62+
ensure
63+
delete_file 'foo.rb'
64+
delete_file 'foo_test.rb'
65+
end
66+
67+
def test_untracked_file
68+
create_file 'foo.rb', should_sleep: false
69+
create_file 'foo_test.rb', should_sleep: false
70+
71+
launch_retest @command
72+
73+
modify_file 'foo.rb'
74+
assert_match "Test file: foo_test.rb", @output.read
75+
76+
ensure
77+
delete_file 'foo.rb'
78+
delete_file 'foo_test.rb'
79+
end
80+
end
81+
end
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
module WatchexecRuby
2+
class MatchingUnmatchingCommandTest < Minitest::Test
3+
def teardown
4+
end_retest
5+
end
6+
7+
def test_displaying_options_on_matching_command
8+
create_file('test/other_bottles_test.rb', should_sleep: false)
9+
10+
launch_retest(COMMAND)
11+
12+
create_file 'foo_test.rb'
13+
assert_match "Test file: foo_test.rb", @output.read
14+
15+
modify_file('lib/bottles.rb')
16+
assert_match <<~EXPECTED.chomp, @output.read
17+
We found few tests matching: lib/bottles.rb
18+
19+
[0] - test/bottles_test.rb
20+
[1] - test/other_bottles_test.rb
21+
[2] - none
22+
23+
Which file do you want to use?
24+
Enter the file number now:
25+
>
26+
EXPECTED
27+
28+
@input.write "2\n"
29+
wait
30+
31+
assert_match "Test file: foo_test.rb", @output.read
32+
33+
ensure
34+
delete_file 'foo_test.rb'
35+
delete_file('test/other_bottles_test.rb')
36+
end
37+
end
38+
end
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module WatchexecRuby
2+
class SetupTest < Minitest::Test
3+
def test_repository_setup
4+
assert_equal :ruby, Retest::Setup.new.type
5+
end
6+
end
7+
end

0 commit comments

Comments
 (0)