From 7b3581ec9101b1c6b4ee994d6defbc028cc36087 Mon Sep 17 00:00:00 2001 From: Alexandre Barret Date: Tue, 28 Jan 2025 09:37:53 +1300 Subject: [PATCH] E2E tests for rails-app with alias rails command --- features/rails-app/bin/retest | 3 + features/rails-app/retest/retest_test.rb | 111 ++++++++++++++++++----- 2 files changed, 90 insertions(+), 24 deletions(-) create mode 100755 features/rails-app/bin/retest diff --git a/features/rails-app/bin/retest b/features/rails-app/bin/retest new file mode 100755 index 00000000..a78c59c8 --- /dev/null +++ b/features/rails-app/bin/retest @@ -0,0 +1,3 @@ +#!/usr/bin/env sh + +bin/rails test $@ diff --git a/features/rails-app/retest/retest_test.rb b/features/rails-app/retest/retest_test.rb index 6ad4ed77..ab2fec36 100644 --- a/features/rails-app/retest/retest_test.rb +++ b/features/rails-app/retest/retest_test.rb @@ -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 @@ -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 ' + 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 ' + Watcher: [LISTEN] + + Launching Retest... + Ready to refactor! You can make file changes now + OUTPUT end def test_modify_a_file @@ -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 @@ -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 @@ -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 ' --rails" 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 + + 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