diff --git a/exe/retest b/exe/retest index 891430f2..fc748b58 100755 --- a/exe/retest +++ b/exe/retest @@ -55,7 +55,12 @@ Retest.listen(options) do |modified, added, removed| end end $stdout.puts "Ready to refactor! You can make file changes now" +$stdout.puts "Press [Enter] to run all tests" -# not blocking - -sleep +loop do + input = $stdin.getc + if ["\r", "\n"].include?(input) + puts "Enter pressed, running all tests" + program.run_all + end +end diff --git a/lib/retest/command.rb b/lib/retest/command.rb index 5131cadc..fdb29282 100644 --- a/lib/retest/command.rb +++ b/lib/retest/command.rb @@ -7,8 +7,8 @@ module Retest class Command extend Forwardable - def self.for_options(options) - new(options: options).command + def self.for_options(options, quiet: false) + new(options: options, quiet: quiet).command end def self.for_setup(setup) @@ -19,10 +19,11 @@ def self.for_setup(setup) def_delegators :options, :params, :full_suite?, :auto? attr_accessor :options, :setup - def initialize(options: Options.new, setup: Setup.new, stdout: $stdout) + def initialize(options: Options.new, setup: Setup.new, stdout: $stdout, quiet: false) @options = options @setup = setup @stdout = stdout + @quiet = quiet end def command @@ -51,7 +52,7 @@ def setup_command end def default_command - @stdout.puts "Setup identified: [#{type.upcase}]. Using command: '#{setup_command}'" + @stdout.puts "Setup identified: [#{type.upcase}]. Using command: '#{setup_command}'" unless @quiet setup_command end @@ -73,4 +74,4 @@ def ruby_command Ruby.new(all: full_suite?) end end -end \ No newline at end of file +end diff --git a/lib/retest/command/rails.rb b/lib/retest/command/rails.rb index c754a5d5..b9b6bb17 100644 --- a/lib/retest/command/rails.rb +++ b/lib/retest/command/rails.rb @@ -10,7 +10,7 @@ def initialize(all:, file_system: FileSystem) def to_s return "#{root_command} " unless all - root_command + "#{root_command}:all" end def format_batch(*files) diff --git a/lib/retest/program.rb b/lib/retest/program.rb index 655d4d61..5453d084 100644 --- a/lib/retest/program.rb +++ b/lib/retest/program.rb @@ -1,10 +1,13 @@ module Retest class Program - attr_accessor :runner, :repository, :command + attr_accessor :runner, :repository, :command, :all_runner def initialize(runner: nil, repository: nil, command: nil) @runner = runner @repository = repository @command = command + @all_runner = Retest::Runners.runner_for( + Retest::Command.for_options(Retest::Options.new(["--all"]), quiet: true).to_s + ) end def run(modified, added, removed) @@ -15,6 +18,12 @@ def run(modified, added, removed) runner.run (modified + added).first, repository: repository end + def run_all + system('clear 2>/dev/null') || system('cls 2>/dev/null') + + all_runner.run + end + def diff(branch) raise "Git not installed" unless VersionControl::Git.installed? test_files = repository.find_tests VersionControl::Git.diff_files(branch) diff --git a/test/retest/command/auto_flag.rb b/test/retest/command/auto_flag.rb index ddd87c26..ffe11256 100644 --- a/test/retest/command/auto_flag.rb +++ b/test/retest/command/auto_flag.rb @@ -88,9 +88,9 @@ def test_for_rspec_setup def test_for_rails_setup @setup.type = :rails - assert_equal 'bundle exec rails test', @subject.command.to_s + assert_equal 'bundle exec rails test:all', @subject.command.to_s assert_equal(<<~OUTPUT, output) - Setup identified: [RAILS]. Using command: 'bundle exec rails test' + Setup identified: [RAILS]. Using command: 'bundle exec rails test:all' OUTPUT end @@ -121,4 +121,4 @@ def test_for_unknown_setup OUTPUT end end -end \ No newline at end of file +end diff --git a/test/retest/command/rails_test.rb b/test/retest/command/rails_test.rb index 2811eef7..cba5c534 100644 --- a/test/retest/command/rails_test.rb +++ b/test/retest/command/rails_test.rb @@ -11,13 +11,13 @@ def setup include CommandInterface def test_to_s - assert_equal 'bin/rails test', Rails.new(all: true, file_system: FakeFS.new(['bin/rails'])).to_s - assert_equal 'bundle exec rails test', Rails.new(all: true, file_system: FakeFS.new([])).to_s + assert_equal 'bin/rails test:all', Rails.new(all: true, file_system: FakeFS.new(['bin/rails'])).to_s + assert_equal 'bundle exec rails test:all', Rails.new(all: true, file_system: FakeFS.new([])).to_s assert_equal 'bin/rails test ', Rails.new(all: false, file_system: FakeFS.new(['bin/rails'])).to_s assert_equal 'bundle exec rails test ', Rails.new(all: false, file_system: FakeFS.new([])).to_s # take into account gem repository which doesn't have a bin file assert_equal 'bundle exec rails test ', Rails.new(all: false).to_s - assert_equal 'bundle exec rails test', Rails.new(all: true).to_s + assert_equal 'bundle exec rails test:all', Rails.new(all: true).to_s end def test_format_with_one_file @@ -29,4 +29,4 @@ def test_format_with_multiple_files end end end -end \ No newline at end of file +end diff --git a/test/retest/command_test.rb b/test/retest/command_test.rb index f36aa028..d46beed1 100644 --- a/test/retest/command_test.rb +++ b/test/retest/command_test.rb @@ -37,7 +37,7 @@ def test_all_options assert_equal 'bundle exec rspec', @subject.command.to_s @subject.options = Options.new(['--rails', '--all']) - assert_equal 'bundle exec rails test', @subject.command.to_s + assert_equal 'bundle exec rails test:all', @subject.command.to_s @subject.options = Options.new(['--rake', '--all']) assert_equal 'bundle exec rake test', @subject.command.to_s @@ -91,4 +91,4 @@ def test_setup_command_with_ruby assert_equal %Q{Setup identified: [RUBY]. Using command: 'bundle exec ruby '\n}, read_output end end -end \ No newline at end of file +end