diff --git a/README.md b/README.md index 0981f61..8336853 100644 --- a/README.md +++ b/README.md @@ -48,8 +48,10 @@ retest --diff origin/main # Test changes from a branch Stay in control with an interactive shell for test management. Start Retest and enter `h` to explore available commands. ``` -Setup identified: [RAKE]. Using command: 'bundle exec rake test TEST=' +Setup: [RAKE] +Command: 'bundle exec rake test TEST=' Watcher: [WATCHEXEC] + Launching Retest... Ready to refactor! You can make file changes now diff --git a/exe/retest b/exe/retest index ce30715..a5962af 100755 --- a/exe/retest +++ b/exe/retest @@ -39,25 +39,39 @@ program = Retest::Program.new( runner: runner ) +# === LOGGING === +case command +when Retest::Command::Rspec then puts "Setup: [RSPEC]" +when Retest::Command::Rails then puts "Setup: [RAILS]" +when Retest::Command::Rake then puts "Setup: [RAKE]" +when Retest::Command::Ruby then puts "Setup: [RUBY]" +else puts "Setup: [UNKNOWN]" +end + +puts "Command: '#{command}'" + +# === DIFF ACTION === if options.params[:diff] + puts program.diff(options.params[:diff]) return end +# === LOGGING === if watcher == Retest::Watcher::Watchexec puts "Watcher: [WATCHEXEC]" else puts "Watcher: [LISTEN]" end -launching_message = "Launching Retest..." +launching_message = "\nLaunching Retest..." if options.force_polling? launching_message = "Launching Retest with polling method..." end -# Main action - puts launching_message + +# === MAIN ACTION === Retest.listen(options, listener: watcher) do |modified, added, removed| begin repository.sync(added: added, removed: removed) diff --git a/features/bundler-app/retest/retest_test/interactive_commands_test.rb b/features/bundler-app/retest/retest_test/interactive_commands_test.rb index 2e8b91c..5616b1b 100644 --- a/features/bundler-app/retest/retest_test/interactive_commands_test.rb +++ b/features/bundler-app/retest/retest_test/interactive_commands_test.rb @@ -13,8 +13,10 @@ def test_start_help launch_retest @command assert_output_matches <<~EXPECTED.chomp - Setup identified: [RAKE]. Using command: 'bundle exec rake test TEST=' + Setup: [RAKE] + Command: 'bundle exec rake test TEST=' Watcher: [LISTEN] + Launching Retest... Ready to refactor! You can make file changes now diff --git a/features/hanami-app/retest/retest_test.rb b/features/hanami-app/retest/retest_test.rb index 699f5a3..a9e6a3f 100644 --- a/features/hanami-app/retest/retest_test.rb +++ b/features/hanami-app/retest/retest_test.rb @@ -75,8 +75,10 @@ def test_with_no_command launch_retest 'retest' assert_output_matches <<~OUTPUT - Setup identified: [RAKE]. Using command: 'bundle exec rake test TEST=' + Setup: [RAKE] + Command: 'bundle exec rake test TEST=' Watcher: [LISTEN] + Launching Retest... Ready to refactor! You can make file changes now OUTPUT @@ -86,8 +88,10 @@ def test_with_no_command_all launch_retest 'retest --all' assert_output_matches <<~OUTPUT - Setup identified: [RAKE]. Using command: 'bundle exec rake test' + Setup: [RAKE] + Command: 'bundle exec rake test' Watcher: [LISTEN] + Launching Retest... Ready to refactor! You can make file changes now OUTPUT diff --git a/features/rails-app/retest/retest_test.rb b/features/rails-app/retest/retest_test.rb index bca6534..6ad4ed7 100644 --- a/features/rails-app/retest/retest_test.rb +++ b/features/rails-app/retest/retest_test.rb @@ -85,8 +85,10 @@ def test_with_no_command launch_retest 'retest' assert_output_matches <<~OUTPUT - Setup identified: [RAILS]. Using command: 'bin/rails test ' + Setup: [RAILS] + Command: 'bin/rails test ' Watcher: [LISTEN] + Launching Retest... Ready to refactor! You can make file changes now OUTPUT @@ -96,8 +98,10 @@ def test_with_no_command_all launch_retest 'retest --all' assert_output_matches <<~OUTPUT - Setup identified: [RAILS]. Using command: 'bin/rails test' + Setup: [RAILS] + Command: 'bin/rails test' Watcher: [LISTEN] + Launching Retest... Ready to refactor! You can make file changes now OUTPUT @@ -142,7 +146,9 @@ def test_diffs_from_other_branch launch_retest 'retest --diff=main' assert_output_matches <<~EXPECTED, "7 runs, 9 assertions, 0 failures, 0 errors, 0 skips" - Setup identified: [RAILS]. Using command: 'bin/rails test ' + Setup: [RAILS] + Command: 'bin/rails test ' + Tests selected: - test/controllers/books_controller_test.rb - test/models/book_test.rb diff --git a/features/rspec-rails/retest/retest_test.rb b/features/rspec-rails/retest/retest_test.rb index 4b08d87..a8c1095 100644 --- a/features/rspec-rails/retest/retest_test.rb +++ b/features/rspec-rails/retest/retest_test.rb @@ -85,8 +85,10 @@ def test_with_no_command launch_retest 'retest' assert_output_matches <<~OUTPUT - Setup identified: [RSPEC]. Using command: 'bundle exec rspec ' + Setup: [RSPEC] + Command: 'bundle exec rspec ' Watcher: [LISTEN] + Launching Retest... Ready to refactor! You can make file changes now OUTPUT @@ -96,8 +98,10 @@ def test_with_no_command_all launch_retest 'retest --all' assert_output_matches <<~OUTPUT - Setup identified: [RSPEC]. Using command: 'bundle exec rspec' + Setup: [RSPEC] + Command: 'bundle exec rspec' Watcher: [LISTEN] + Launching Retest... Ready to refactor! You can make file changes now OUTPUT diff --git a/features/rspec-ruby/retest/retest_test/flags_test.rb b/features/rspec-ruby/retest/retest_test/flags_test.rb index b611657..4f775dc 100644 --- a/features/rspec-ruby/retest/retest_test/flags_test.rb +++ b/features/rspec-ruby/retest/retest_test/flags_test.rb @@ -12,8 +12,10 @@ def test_with_no_command launch_retest 'retest' assert_output_matches <<~OUTPUT - Setup identified: [RSPEC]. Using command: 'bundle exec rspec ' + Setup: [RSPEC] + Command: 'bundle exec rspec ' Watcher: [LISTEN] + Launching Retest... Ready to refactor! You can make file changes now OUTPUT diff --git a/features/ruby-app/retest/retest_test.rb b/features/ruby-app/retest/retest_test.rb index e5d76b5..ddba31f 100644 --- a/features/ruby-app/retest/retest_test.rb +++ b/features/ruby-app/retest/retest_test.rb @@ -24,8 +24,10 @@ def test_start_retest launch_retest(@command) assert_output_matches <<~EXPECTED - Setup identified: [RUBY]. Using command: 'bundle exec ruby ' + Setup: [RUBY] + Command: 'bundle exec ruby ' Watcher: [LISTEN] + Launching Retest... Ready to refactor! You can make file changes now EXPECTED @@ -47,8 +49,10 @@ def test_start_retest launch_retest(@command) assert_output_matches <<~EXPECTED - Setup identified: [RUBY]. Using command: 'bundle exec ruby ' + Setup: [RUBY] + Command: 'bundle exec ruby ' Watcher: [WATCHEXEC] + Launching Retest... Ready to refactor! You can make file changes now EXPECTED @@ -70,8 +74,10 @@ def test_uses_watchexec_when_installed launch_retest(@command) assert_output_matches <<~EXPECTED - Setup identified: [RUBY]. Using command: 'bundle exec ruby ' + Setup: [RUBY] + Command: 'bundle exec ruby ' Watcher: [WATCHEXEC] + Launching Retest... Ready to refactor! You can make file changes now EXPECTED diff --git a/features/ruby-bare/retest/scenarios/auto_flag.rb b/features/ruby-bare/retest/scenarios/auto_flag.rb index aaa2af3..a7ee605 100644 --- a/features/ruby-bare/retest/scenarios/auto_flag.rb +++ b/features/ruby-bare/retest/scenarios/auto_flag.rb @@ -9,8 +9,10 @@ def test_start_retest launch_retest 'retest' assert_output_matches <<~OUTPUT - Setup identified: [RUBY]. Using command: 'ruby ' + Setup: [RUBY] + Command: 'ruby ' Watcher: [LISTEN] + Launching Retest... Ready to refactor! You can make file changes now OUTPUT diff --git a/lib/retest/command.rb b/lib/retest/command.rb index 0269179..6eec1fd 100644 --- a/lib/retest/command.rb +++ b/lib/retest/command.rb @@ -9,22 +9,21 @@ module Retest class Command extend Forwardable - def self.for_options(options, stdout: $stdout) - new(options: options, stdout: stdout).command + def self.for_options(options) + new(options: options).command end - def_delegator :setup, :type def_delegators :options, :params, :full_suite?, :auto? - attr_accessor :options, :setup - def initialize(options: Options.new, setup: Setup.new, stdout: $stdout) + attr_accessor :options, :setup, :setup_identified + def initialize(options: Options.new, setup: Setup.new) @options = options @setup = setup - @stdout = stdout + @setup_identified = nil end def command - options_command || default_command + options_command || setup_command end private @@ -38,13 +37,8 @@ def options_command end end - def default_command - log "Setup identified: [#{type.upcase}]. Using command: '#{setup_command}'" - setup_command - end - def setup_command - case type + case setup.type when :rake then rake_command when :rspec then rspec_command when :rails then rails_command @@ -53,10 +47,6 @@ def setup_command end end - def log(message) - @stdout&.puts(message) - end - def hardcoded_command(command) Hardcoded.new(command: command) end diff --git a/test/retest/command/auto_flag.rb b/test/retest/command/auto_flag.rb index ddd87c2..94a0fe0 100644 --- a/test/retest/command/auto_flag.rb +++ b/test/retest/command/auto_flag.rb @@ -4,9 +4,7 @@ class AutoFlagTest < MiniTest::Test def setup @setup = SetupFake.new - @out = StringIO.new - - @subject = Command.new(setup: @setup, stdout: @out) + @subject = Command.new(setup: @setup) end def output @@ -15,47 +13,27 @@ def output def test_for_rspec_setup @setup.type = :rspec - assert_equal 'bundle exec rspec ', @subject.command.to_s - assert_equal(<<~OUTPUT, output) - Setup identified: [RSPEC]. Using command: 'bundle exec rspec ' - OUTPUT end def test_for_rails_setup @setup.type = :rails - assert_equal 'bundle exec rails test ', @subject.command.to_s - assert_equal(<<~OUTPUT, output) - Setup identified: [RAILS]. Using command: 'bundle exec rails test ' - OUTPUT end def test_for_ruby_setup @setup.type = :ruby - assert_equal 'bundle exec ruby ', @subject.command.to_s - assert_equal(<<~OUTPUT, output) - Setup identified: [RUBY]. Using command: 'bundle exec ruby ' - OUTPUT end def test_for_rake_setup @setup.type = :rake - assert_equal 'bundle exec rake test TEST=', @subject.command.to_s - assert_equal(<<~OUTPUT, output) - Setup identified: [RAKE]. Using command: 'bundle exec rake test TEST=' - OUTPUT end def test_for_unknown_setup @setup.type = :unknown - assert_equal 'bundle exec ruby ', @subject.command.to_s - assert_equal(<<~OUTPUT, output) - Setup identified: [UNKNOWN]. Using command: 'bundle exec ruby ' - OUTPUT end end @@ -64,12 +42,10 @@ class AutoAllFlagTest < MiniTest::Test def setup @setup = SetupFake.new - @out = StringIO.new - @subject = Command.new( options: Options.new(['--all']), - setup: @setup, - stdout: @out) + setup: @setup + ) end def output @@ -78,47 +54,27 @@ def output def test_for_rspec_setup @setup.type = :rspec - assert_equal 'bundle exec rspec', @subject.command.to_s - assert_equal(<<~OUTPUT, output) - Setup identified: [RSPEC]. Using command: 'bundle exec rspec' - OUTPUT end def test_for_rails_setup @setup.type = :rails - assert_equal 'bundle exec rails test', @subject.command.to_s - assert_equal(<<~OUTPUT, output) - Setup identified: [RAILS]. Using command: 'bundle exec rails test' - OUTPUT end def test_for_ruby_setup @setup.type = :ruby - assert_equal 'bundle exec ruby ', @subject.command.to_s - assert_equal(<<~OUTPUT, output) - Setup identified: [RUBY]. Using command: 'bundle exec ruby ' - OUTPUT end def test_for_rake_setup @setup.type = :rake - assert_equal 'bundle exec rake test', @subject.command.to_s - assert_equal(<<~OUTPUT, output) - Setup identified: [RAKE]. Using command: 'bundle exec rake test' - OUTPUT end def test_for_unknown_setup @setup.type = :unknown - assert_equal 'bundle exec ruby ', @subject.command.to_s - assert_equal(<<~OUTPUT, output) - Setup identified: [UNKNOWN]. Using command: 'bundle exec ruby ' - OUTPUT end end end \ No newline at end of file diff --git a/test/retest/command_test.rb b/test/retest/command_test.rb index f36aa02..8f8ab1b 100644 --- a/test/retest/command_test.rb +++ b/test/retest/command_test.rb @@ -4,7 +4,7 @@ module Retest class OptionsCommandTest < MiniTest::Test def setup - @subject = Command.new stdout: StringIO.new + @subject = Command.new end def test_hardcoded_command @@ -58,37 +58,28 @@ def test_mixed_options class SetupCommandTest < MiniTest::Test FakeSetup = Struct.new(:type) - def read_output - @output.tap(&:rewind).read - end - def setup - @output = StringIO.new - @subject = Command.new stdout: @output + @subject = Command.new end def test_setup_command_with_rake @subject.setup = FakeSetup.new(:rake) assert_equal 'bundle exec rake test TEST=', @subject.command.to_s - assert_equal %Q{Setup identified: [RAKE]. Using command: 'bundle exec rake test TEST='\n}, read_output end def test_setup_command_with_rails @subject.setup = FakeSetup.new(:rails) assert_equal 'bundle exec rails test ', @subject.command.to_s - assert_equal %Q{Setup identified: [RAILS]. Using command: 'bundle exec rails test '\n}, read_output end def test_setup_command_with_rspec @subject.setup = FakeSetup.new(:rspec) assert_equal 'bundle exec rspec ', @subject.command.to_s - assert_equal %Q{Setup identified: [RSPEC]. Using command: 'bundle exec rspec '\n}, read_output end def test_setup_command_with_ruby @subject.setup = FakeSetup.new(:ruby) assert_equal 'bundle exec ruby ', @subject.command.to_s - assert_equal %Q{Setup identified: [RUBY]. Using command: 'bundle exec ruby '\n}, read_output end end end \ No newline at end of file