Skip to content

Commit

Permalink
Allow official command to be aliased (#246)
Browse files Browse the repository at this point in the history
Fixes #245

* Allow hardcoded command as aliases for all framework commands
* Refactor commands
* Rename one_command to batched_command with references
* E2E tests with alias commands
  • Loading branch information
AlexB52 authored Jan 27, 2025
1 parent d817bf3 commit a97dd1c
Show file tree
Hide file tree
Showing 26 changed files with 492 additions and 217 deletions.
3 changes: 1 addition & 2 deletions exe/retest
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ program = Retest::Program.new(

# === LOGGING ===
case command
when Retest::Command::Rspec then puts "Setup: [RSPEC]"
when Retest::Command::Rails then puts "Setup: [RAILS]"
when Retest::Command::Rspec then puts "Setup: [RSPEC]"
when Retest::Command::Rake then puts "Setup: [RAKE]"
when Retest::Command::Ruby then puts "Setup: [RUBY]"
else puts "Setup: [UNKNOWN]"
Expand All @@ -52,7 +52,6 @@ puts "Command: '#{command}'"

# === DIFF ACTION ===
if options.params[:diff]
puts
program.diff(options.params[:diff])
return
end
Expand Down
3 changes: 3 additions & 0 deletions features/rails-app/bin/retest
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env sh

bin/rails test $@
111 changes: 87 additions & 24 deletions features/rails-app/retest/retest_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@

$stdout.sync = true

class MatchingTestsCommandTest < Minitest::Test
class SetupTest < Minitest::Test
def test_repository_setup
assert_equal :rails, Retest::Setup.new.type
end
end

class TestRailsOption < Minitest::Test
include RetestHelper

def setup
Expand All @@ -18,16 +24,39 @@ def teardown
def test_start_retest
launch_retest @command

assert_output_matches <<~EXPECTED
assert_output_matches <<~OUTPUT
Setup: [RAILS]
Command: 'bin/rails test <test>'
Watcher: [LISTEN]
Launching Retest...
Ready to refactor! You can make file changes now
EXPECTED
OUTPUT
end
end

write_input("\n") # Trigger last command when no command was run
class TestDefaultCommand < Minitest::Test
include RetestHelper

assert_output_matches <<~EXPECTED
Error - Not enough information to run a command. Please trigger a run first.
EXPECTED
def setup
@command = 'retest'
end

def teardown
end_retest
end

def test_start_retest
launch_retest @command

assert_output_matches <<~OUTPUT
Setup: [RAILS]
Command: 'bin/rails test <test>'
Watcher: [LISTEN]
Launching Retest...
Ready to refactor! You can make file changes now
OUTPUT
end

def test_modify_a_file
Expand All @@ -39,13 +68,25 @@ def test_modify_a_file
"Test file: test/models/post_test.rb",
"1 runs, 1 assertions, 0 failures, 0 errors, 0 skips")
end

def test_interactive_commands
launch_retest @command

assert_output_matches("Ready to refactor! You can make file changes now")

write_input("\n") # Trigger last command when no command was run

assert_output_matches <<~EXPECTED
Error - Not enough information to run a command. Please trigger a run first.
EXPECTED
end
end

class AllTestsCommandTest < Minitest::Test
class TestAllRailsCommand < Minitest::Test
include RetestHelper

def setup
@command = 'retest --rails --all'
@command = 'retest --all'
end

def teardown
Expand All @@ -55,10 +96,20 @@ def teardown
def test_start_retest
launch_retest @command

assert_output_matches <<~EXPECTED
assert_output_matches <<~OUTPUT
Setup: [RAILS]
Command: 'bin/rails test'
Watcher: [LISTEN]
Launching Retest...
Ready to refactor! You can make file changes now
EXPECTED
OUTPUT
end

def test_interactive_commands
launch_retest @command

assert_output_matches("Ready to refactor! You can make file changes now")

write_input("\n") # Trigger all command when no command was run

Expand All @@ -74,47 +125,59 @@ def test_modify_a_file
end
end

class AutoFlagTest < Minitest::Test
class TestRailsAliasCommand < Minitest::Test
include RetestHelper

def teardown
end_retest
end

def test_with_no_command
launch_retest 'retest'
def test_start_retest_with_placeholder
launch_retest "retest 'bin/retest <test>' --rails"

assert_output_matches <<~OUTPUT
Setup: [RAILS]
Command: 'bin/rails test <test>'
Command: 'bin/retest <test>'
Watcher: [LISTEN]
Launching Retest...
Ready to refactor! You can make file changes now
OUTPUT

write_input("\n") # Trigger last command when no command was run

assert_output_matches("Error - Not enough information to run a command. Please trigger a run first.")

modify_file 'app/models/post.rb'

assert_output_matches(
"Test file: test/models/post_test.rb",
"1 runs, 1 assertions, 0 failures, 0 errors, 0 skips")
end

def test_with_no_command_all
launch_retest 'retest --all'
def test_start_retest_without_placeholder
launch_retest "retest --rails 'bin/retest'"

assert_output_matches <<~OUTPUT
Setup: [RAILS]
Command: 'bin/rails test'
Command: 'bin/retest'
Watcher: [LISTEN]
Launching Retest...
Ready to refactor! You can make file changes now
OUTPUT
end
end

class SetupTest < Minitest::Test
def test_repository_setup
assert_equal :rails, Retest::Setup.new.type
write_input("\n") # Trigger last command when no command was run

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

modify_file 'app/models/post.rb'

assert_output_matches "8 runs, 10 assertions, 0 failures, 0 errors, 0 skips"
end
end

class DiffOptionTest < Minitest::Test
class TestDiffOption < Minitest::Test
include RetestHelper

def setup
Expand Down
3 changes: 3 additions & 0 deletions features/rspec-ruby/bin/retest
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env sh

bundle exec rspec $@
71 changes: 68 additions & 3 deletions features/rspec-ruby/retest/retest_test.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,74 @@
require 'retest'
require_relative 'support/test_helper'
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/file_changes'

$stdout.sync = true

class TestDefaultCommand < Minitest::Test
include RetestHelper
include FileChanges

def setup
@command = "retest"
end

def teardown
end_retest
end

def test_repository_setup
assert_equal :rspec, Retest::Setup.new.type
end

def test_starting_details
launch_retest @command

assert_output_matches <<~OUTPUT
Setup: [RSPEC]
Command: 'bundle exec rspec <test>'
Watcher: [LISTEN]
Launching Retest...
Ready to refactor! You can make file changes now
OUTPUT

modify_file('lib/bottles.rb')

assert_output_matches "Test file: spec/bottles_spec.rb"
end
end

class TestAliasCommand < Minitest::Test
include RetestHelper
include FileChanges

def setup
@command = "retest --rspec 'bin/retest <test>'"
end

def teardown
end_retest
end

def test_repository_setup
assert_equal :rspec, Retest::Setup.new.type
end

def test_starting_details
launch_retest @command

assert_output_matches <<~OUTPUT
Setup: [RSPEC]
Command: 'bin/retest <test>'
Watcher: [LISTEN]
Launching Retest...
Ready to refactor! You can make file changes now
OUTPUT

modify_file('lib/bottles.rb')

assert_output_matches "Test file: spec/bottles_spec.rb"
end
end
Original file line number Diff line number Diff line change
@@ -1,22 +1,8 @@
class FileChangesTest < Minitest::Test
include RetestHelper

def setup
@command = 'retest --rspec'
end

def teardown
end_retest
end

def test_start_retest
launch_retest @command

assert_output_matches <<~EXPECTED
Launching Retest...
Ready to refactor! You can make file changes now
EXPECTED
end
module FileChanges
# Don't forget to end_retest in the class
# def teardown
# end_retest
# end

def test_modifying_existing_file
launch_retest @command
Expand Down
27 changes: 0 additions & 27 deletions features/rspec-ruby/retest/retest_test/flags_test.rb

This file was deleted.

5 changes: 0 additions & 5 deletions features/rspec-ruby/retest/retest_test/setup_test.rb

This file was deleted.

6 changes: 1 addition & 5 deletions features/ruby-app/retest/retest_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,8 @@ def test_start_retest
end
end

class TestDefaultWatcher < Minitest::Test
class TestDefaultWatcher < Minitest::Test # only test the correct watcher is set
include RetestHelper
include Setup
include ExplicitMatching
include FileChanges
include InteractiveCommands

def setup
@command = 'retest'
Expand Down
2 changes: 1 addition & 1 deletion features/ruby-app/retest/shared/interactive_commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ def test_run_all_logs_proper_error_message

write_input("ra\n") # Trigger run all

assert_output_matches("Command::AllTestsNotSupported - All tests run not supported for 'bundle exec ruby <test>'")
assert_output_matches("Command::AllTestsNotSupported - All tests run not supported for Ruby command: 'bundle exec ruby <test>'")
end
end
Loading

0 comments on commit a97dd1c

Please sign in to comment.