-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Extract Command from Options class * Move tests from options to command class * Refactor Command class * Cleanup Options class * Update command retrievel in executable * Prototype RSpec command * Prototype Rails command * Remove keyword init from Struct because it is a 2.5 ruby feature * Check for rails setup within gemflock file * Prototype Rake command * Prototype Ruby command * Move setup command to their own file * Fix rails feature specs to use bin/rails instead * Refactor command tests
- Loading branch information
Showing
15 changed files
with
348 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
require_relative 'command/rails' | ||
require_relative 'command/rake' | ||
require_relative 'command/rspec' | ||
require_relative 'command/ruby' | ||
|
||
module Retest | ||
class Command | ||
extend Forwardable | ||
|
||
def self.for_options(options) | ||
new(options: options).command | ||
end | ||
|
||
def self.for_setup(setup) | ||
new(setup: setup).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, output_stream: STDOUT) | ||
@options = options | ||
@setup = setup | ||
@output_stream = output_stream | ||
end | ||
|
||
def command | ||
return default_command if auto? | ||
options_command || default_command | ||
end | ||
|
||
def options_command | ||
return params[:command] if params[:command] | ||
|
||
if params[:rspec] then rspec_command | ||
elsif params[:rails] then rails_command | ||
elsif params[:ruby] then ruby_command | ||
elsif params[:rake] then rake_command | ||
else | ||
end | ||
end | ||
|
||
def setup_command | ||
case type | ||
when :rake then rake_command | ||
when :rspec then rspec_command | ||
when :rails then rails_command | ||
when :ruby then ruby_command | ||
else ruby_command | ||
end | ||
end | ||
|
||
def default_command | ||
@output_stream.puts "Setup identified: [#{type.upcase}]. Using command: '#{setup_command}'" | ||
setup_command | ||
end | ||
|
||
private | ||
|
||
def rspec_command | ||
Rspec.command(all: full_suite?) | ||
end | ||
|
||
def rails_command | ||
Rails.command(all: full_suite?) | ||
end | ||
|
||
def rake_command | ||
Rake.command(all: full_suite?) | ||
end | ||
|
||
def ruby_command | ||
Ruby.command(all: full_suite?) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module Retest | ||
class Command | ||
Rails = Struct.new(:all, :bin_file) do | ||
def self.command(all:, bin_file: File.exist?('bin/rails')) | ||
new(all, bin_file).command | ||
end | ||
|
||
def command | ||
return "#{root_command} <test>" unless all | ||
root_command | ||
end | ||
|
||
private | ||
|
||
def root_command | ||
return 'bin/rails test' if bin_file | ||
|
||
'bundle exec rails test' | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module Retest | ||
class Command | ||
Rake = Struct.new(:all, :bin_file) do | ||
def self.command(all:, bin_file: File.exist?('bin/rake')) | ||
new(all, bin_file).command | ||
end | ||
|
||
def command | ||
return "#{root_command} TEST=<test>" unless all | ||
root_command | ||
end | ||
|
||
private | ||
|
||
def root_command | ||
return 'bin/rake test' if bin_file | ||
|
||
'bundle exec rake test' | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module Retest | ||
class Command | ||
Rspec = Struct.new(:all, :bin_file) do | ||
def self.command(all:, bin_file: File.exist?('bin/rspec')) | ||
new(all, bin_file).command | ||
end | ||
|
||
def command | ||
return "#{root_command} <test>" unless all | ||
root_command | ||
end | ||
|
||
private | ||
|
||
def root_command | ||
return 'bin/rspec' if bin_file | ||
|
||
'bundle exec rspec' | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module Retest | ||
class Command | ||
Ruby = Struct.new(:all, :bin_file) do | ||
def self.command(all: false, bin_file: false) | ||
new(false, false).command | ||
end | ||
|
||
def command | ||
'bundle exec ruby <test>' | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,7 @@ def rspec? | |
end | ||
|
||
def rails? | ||
File.exist? 'bin/rails' | ||
has_gem? 'rails' | ||
end | ||
|
||
def rake? | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
module Retest | ||
class Command | ||
class RspecTest < MiniTest::Test | ||
def test_command | ||
assert_equal 'bin/rspec', Rspec.command(all: true, bin_file: true) | ||
assert_equal 'bundle exec rspec', Rspec.command(all: true, bin_file: false) | ||
assert_equal 'bin/rspec <test>', Rspec.command(all: false, bin_file: true) | ||
assert_equal 'bundle exec rspec <test>', Rspec.command(all: false, bin_file: false) | ||
|
||
# take into account gem repository which doesn't have a bin/rspec file | ||
assert_equal 'bundle exec rspec <test>', Rspec.command(all: false) | ||
assert_equal 'bundle exec rspec', Rspec.command(all: true) | ||
end | ||
end | ||
|
||
class RailsTest < MiniTest::Test | ||
def test_command | ||
assert_equal 'bin/rails test', Rails.command(all: true, bin_file: true) | ||
assert_equal 'bundle exec rails test', Rails.command(all: true, bin_file: false) | ||
assert_equal 'bin/rails test <test>', Rails.command(all: false, bin_file: true) | ||
assert_equal 'bundle exec rails test <test>', Rails.command(all: false, bin_file: false) | ||
|
||
# take into account gem repository which doesn't have a bin file | ||
assert_equal 'bundle exec rails test <test>', Rails.command(all: false) | ||
assert_equal 'bundle exec rails test', Rails.command(all: true) | ||
end | ||
end | ||
|
||
class RakeTest < MiniTest::Test | ||
def test_command | ||
assert_equal 'bin/rake test', Rake.command(all: true, bin_file: true) | ||
assert_equal 'bundle exec rake test', Rake.command(all: true, bin_file: false) | ||
assert_equal 'bin/rake test TEST=<test>', Rake.command(all: false, bin_file: true) | ||
assert_equal 'bundle exec rake test TEST=<test>', Rake.command(all: false, bin_file: false) | ||
|
||
# take into account gem repository which doesn't have a bin file | ||
assert_equal 'bundle exec rake test TEST=<test>', Rake.command(all: false) | ||
assert_equal 'bundle exec rake test', Rake.command(all: true) | ||
end | ||
end | ||
|
||
class RubyTest < MiniTest::Test | ||
def test_command | ||
assert_equal 'bundle exec ruby <test>', Ruby.command(all: true, bin_file: true) | ||
assert_equal 'bundle exec ruby <test>', Ruby.command(all: true, bin_file: false) | ||
assert_equal 'bundle exec ruby <test>', Ruby.command(all: false, bin_file: true) | ||
assert_equal 'bundle exec ruby <test>', Ruby.command(all: false, bin_file: false) | ||
|
||
# take into account gem repository which doesn't have a bin file | ||
assert_equal 'bundle exec ruby <test>', Ruby.command(all: false) | ||
assert_equal 'bundle exec ruby <test>', Ruby.command(all: true) | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.