Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Interactive Feature tests #234

Merged
merged 2 commits into from
Dec 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions bin/test/bundler-app
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
#!/usr/bin/env bash

FOLDER="features/bundler-app"

bundle install
bundle exec rake build
cp -R features/support features/bundler-app/retest
ls -t pkg | head -n1 | xargs -I {} mv pkg/{} features/bundler-app/retest.gem
docker compose -f features/bundler-app/docker-compose.yml up --build --exit-code-from retest
# cp -R features/support features/bundler-app/retest
ls -t pkg | head -n1 | xargs -I {} mv pkg/{} "$FOLDER/retest.gem"

if [[ "$1" == "--no-build" ]]; then
docker compose -f "$FOLDER/docker-compose.yml" up --exit-code-from retest
else
docker compose -f "$FOLDER/docker-compose.yml" up --build --exit-code-from retest
fi
1 change: 1 addition & 0 deletions features/bundler-app/lib/bundler_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require_relative "bundler_app/version"
require_relative "bundler_app/bottles"
require_relative "bundler_app/fibonacci"

module BundlerApp
class Error < StandardError; end
Expand Down
11 changes: 11 additions & 0 deletions features/bundler-app/lib/bundler_app/fibonacci.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# fibonacci.rb
class Fibonacci
def self.calculate(n)
raise ArgumentError, "Input must be a non-negative integer." unless n.is_a?(Integer) && n >= 0
return n if n <= 1

a, b = 0, 1
(n - 1).times { a, b = b, a + b }
b
end
end
4 changes: 1 addition & 3 deletions features/bundler-app/retest/retest_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
require_relative 'support/test_helper'
require 'minitest/autorun'
require_relative 'retest_test/file_changes_test'
require_relative 'retest_test/interactive_commands_test'

$stdout.sync = true

include FileHelper

32 changes: 17 additions & 15 deletions features/bundler-app/retest/retest_test/file_changes_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class FileChangesTest < Minitest::Test
include RetestHelper

def setup
@command = 'retest'
end
Expand All @@ -10,7 +12,7 @@ def teardown
def test_start_retest
launch_retest @command

assert_match <<~EXPECTED, @output.read
assert_output_matches <<~EXPECTED
Launching Retest...
Ready to refactor! You can make file changes now
EXPECTED
Expand All @@ -21,25 +23,27 @@ def test_modifying_existing_file

modify_file('lib/bundler_app/bottles.rb')

assert_match "Test file: test/bundler_app/test_bottles.rb", @output.read
assert_match "12 runs, 12 assertions, 0 failures, 0 errors, 0 skips", @output.read
assert_output_matches(
'Test file: test/bundler_app/test_bottles.rb',
'12 runs, 12 assertions, 0 failures, 0 errors, 0 skips')
end

def test_modifying_existing_test_file
launch_retest @command

modify_file('test/bundler_app/test_bottles.rb')

assert_match "Test file: test/bundler_app/test_bottles.rb", @output.read
assert_match "12 runs, 12 assertions, 0 failures, 0 errors, 0 skips", @output.read
assert_output_matches(
'Test file: test/bundler_app/test_bottles.rb',
'12 runs, 12 assertions, 0 failures, 0 errors, 0 skips')
end

def test_creating_a_new_test_file
launch_retest @command

create_file 'test/bundler_app/test_foo.rb'

assert_match "Test file: test/bundler_app/test_foo.rb", @output.read
assert_output_matches 'Test file: test/bundler_app/test_foo.rb'

ensure
delete_file 'test/bundler_app/test_foo.rb'
Expand All @@ -49,32 +53,30 @@ def test_creating_a_new_file
launch_retest @command

create_file 'lib/bundler_app/foo.rb'
assert_match <<~EXPECTED, @output.read
FileNotFound - Retest could not find a matching test file to run.
EXPECTED
assert_output_matches 'FileNotFound - Retest could not find a matching test file to run.'

create_file 'test/bundler_app/test_foo.rb'
assert_match "Test file: test/bundler_app/test_foo.rb", @output.read
assert_output_matches 'Test file: test/bundler_app/test_foo.rb'

modify_file('lib/bundler_app/bottles.rb')
assert_match "Test file: test/bundler_app/test_bottles.rb", @output.read
assert_output_matches 'Test file: test/bundler_app/test_bottles.rb'

modify_file('lib/bundler_app/foo.rb')
assert_match "Test file: test/bundler_app/test_foo.rb", @output.read
assert_output_matches 'Test file: test/bundler_app/test_foo.rb'

ensure
delete_file 'lib/bundler_app/foo.rb'
delete_file 'test/bundler_app/test_foo.rb'
end

def test_untracked_file
create_file 'lib/bundler_app/foo.rb', should_sleep: false
create_file 'test/bundler_app/test_foo.rb', should_sleep: false
create_file 'lib/bundler_app/foo.rb', sleep_for: 0
create_file 'test/bundler_app/test_foo.rb', sleep_for: 0

launch_retest @command

modify_file 'lib/bundler_app/foo.rb'
assert_match "Test file: test/bundler_app/test_foo.rb", @output.read
assert_output_matches 'Test file: test/bundler_app/test_foo.rb'

ensure
delete_file 'lib/bundler_app/foo.rb'
Expand Down
141 changes: 141 additions & 0 deletions features/bundler-app/retest/retest_test/interactive_commands_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
class InteractiveCommandTest < Minitest::Test
include RetestHelper

def setup
@command = 'retest'
end

def teardown
end_retest
end

def test_start_help
launch_retest @command

assert_output_matches <<~EXPECTED.chomp
Setup identified: [RAKE]. Using command: 'bundle exec rake test TEST=<test>'
Watcher: [LISTEN]
Launching Retest...
Ready to refactor! You can make file changes now

Type interactive command and press enter. Enter 'h' for help.
>\s
EXPECTED

write_input("h\n")

assert_output_matches <<~EXPECTED.chomp
* 'h', 'help' # Prints help.
* 'p', 'pause' # Pauses Retest. Tests aren't run on file change events until unpaused.
* 'u', 'unpause' # Unpauses Retest.
* <ENTER> # Runs last changed triggered command.
* 'ra, 'run all' # Runs all tests.
* 'f', 'force' # Forces a selection of test to run on every file change.
* 'r', 'reset' # Disables forced selection.
* 'd', 'diff' [GIT BRANCH] # Runs matching specs that changed from a target branch.
* 'e', 'exit' # Exits Retest.

Type interactive command and press enter. Enter 'h' for help.
>\s
EXPECTED
end

def test_pause_unpause
launch_retest @command

modify_file('lib/bundler_app/bottles.rb')

assert_output_matches(
"Test file: test/bundler_app/test_bottles.rb",
"12 runs, 12 assertions, 0 failures, 0 errors, 0 skips"
)

write_input("p\n")

assert_output_matches "Program is paused"

modify_file('lib/bundler_app/bottles.rb')

assert_output_matches <<~EXPECTED
File changed: lib/bundler_app/bottles.rb
Main program paused. Please resume program first.
EXPECTED

write_input("\n") # Manually run previous test

assert_output_matches(
"Running last command: 'bundle exec rake test TEST=test/bundler_app/test_bottles.rb'",
"12 runs, 12 assertions, 0 failures, 0 errors, 0 skips"
)

write_input("u\n")

modify_file('lib/bundler_app/bottles.rb')

assert_output_matches(
"Test file: test/bundler_app/test_bottles.rb",
"12 runs, 12 assertions, 0 failures, 0 errors, 0 skips"
)
end

def test_force_reset
launch_retest @command

write_input("f\n")

assert_output_matches "What test files do you want to run when saving a file? (min. 1)"

write_input("fib\s\n")

assert_output_matches <<~EXPECTED
Forced selection enabled.
Reset to default settings by typing 'r' in the interactive console.

Tests selected:
- test/bundler_app/test_fibonacci.rb
EXPECTED

assert_output_matches "8 runs, 9 assertions, 0 failures, 0 errors, 0 skips"

modify_file('lib/bundler_app/bottles.rb')

assert_output_matches <<~EXPECTED
Forced selection enabled.
Reset to default settings by typing 'r' in the interactive console.

Tests selected:
- test/bundler_app/test_fibonacci.rb
EXPECTED

write_input("\n") # Manually run previous test

assert_output_matches(
"Running last command: 'bundle exec rake test TEST=test/bundler_app/test_fibonacci.rb'",
"8 runs, 9 assertions, 0 failures, 0 errors, 0 skips"
)

write_input("r\n")

modify_file('lib/bundler_app/bottles.rb')

assert_output_matches(
"Test file: test/bundler_app/test_bottles.rb",
"12 runs, 12 assertions, 0 failures, 0 errors, 0 skips")
end

def test_run_all
launch_retest @command

write_input("ra\n")

assert_output_matches(
"Running all tests",
"21 runs, 22 assertions, 0 failures, 0 errors, 0 skips")

write_input("\n") # Manually run previous test

assert_output_matches(
"Running last command: 'bundle exec rake test",
"21 runs, 22 assertions, 0 failures, 0 errors, 0 skips")
end
end
21 changes: 0 additions & 21 deletions features/bundler-app/retest/support/output_file.rb

This file was deleted.

Loading
Loading