Skip to content

Commit

Permalink
E2E tests for rails-app with alias rails command
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexB52 committed Jan 27, 2025
1 parent eed74a9 commit 7b3581e
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 24 deletions.
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

0 comments on commit 7b3581e

Please sign in to comment.