Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run all tests on Enter press #209

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions exe/retest
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 6 additions & 5 deletions lib/retest/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -73,4 +74,4 @@ def ruby_command
Ruby.new(all: full_suite?)
end
end
end
end
2 changes: 1 addition & 1 deletion lib/retest/command/rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def initialize(all:, file_system: FileSystem)

def to_s
return "#{root_command} <test>" unless all
root_command
"#{root_command}:all"
end

def format_batch(*files)
Expand Down
11 changes: 10 additions & 1 deletion lib/retest/program.rb
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions test/retest/command/auto_flag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -121,4 +121,4 @@ def test_for_unknown_setup
OUTPUT
end
end
end
end
8 changes: 4 additions & 4 deletions test/retest/command/rails_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 <test>', Rails.new(all: false, file_system: FakeFS.new(['bin/rails'])).to_s
assert_equal 'bundle exec rails test <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 <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
Expand All @@ -29,4 +29,4 @@ def test_format_with_multiple_files
end
end
end
end
end
4 changes: 2 additions & 2 deletions test/retest/command_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -91,4 +91,4 @@ def test_setup_command_with_ruby
assert_equal %Q{Setup identified: [RUBY]. Using command: 'bundle exec ruby <test>'\n}, read_output
end
end
end
end