Skip to content

Commit

Permalink
Create -all Flag (#37)
Browse files Browse the repository at this point in the history
* Add --all flag to CLI

* Add feature spec for --rake --all
  • Loading branch information
AlexB52 authored Nov 26, 2020
1 parent 8f68cf7 commit 135c034
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 16 deletions.
5 changes: 5 additions & 0 deletions features/retest_flags.feature
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ Feature: FixtureProject
"""

Scenario: I can run retest with a --rake --all flag
Given I run retest with "exe/retest --rake --all"
And I modify file "test/fixtures/files/ruby/file.rb"
Then the logger should output a successful run

Scenario: I can run retest with a --ruby flag
Given I run retest with "exe/retest --ruby"
And I modify file "test/fixtures/files/ruby/file.rb"
Expand Down
4 changes: 4 additions & 0 deletions features/support/steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
refute_match doc_string, @file.read
end

Then('the logger should output a successful run') do
assert_match /\d+ runs, \d+ assertions, 0 failures, 0 errors, 0 skips/, @file.read
end

Then('the logger should output the help') do
assert_match File.read('test/retest/options/help.txt'), @file.read
end
30 changes: 20 additions & 10 deletions lib/retest/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ class Options
RUBY_COMMAND = "bundle exec ruby <test>"
NO_COMMAND = "echo You have no command assigned"

ALL_RAKE_COMMAND = "bundle exec rake test"
ALL_RAILS_COMMAND = "bundle exec rails test"
ALL_RSPEC_COMMAND = "bundle exec rspec"

usage do
program "retest"

Expand All @@ -26,6 +30,7 @@ class Options
example <<~EOS
Runs all rails tests after a file change
$ retest 'bundle exec rails test'
$ retest --rails --all
EOS

example <<~EOS
Expand All @@ -39,6 +44,17 @@ class Options
desc "The test command to rerun when a file changes"
end

flag :all do
long "--all"
desc "Run all the specs of a specificied ruby setup"
end

flag :help do
short "-h"
long "--help"
desc "Print usage"
end

flag :rspec do
long "--rspec"
desc "Shortcut for '#{RSPEC_COMMAND}'"
Expand All @@ -59,12 +75,6 @@ class Options
desc "Shortcut for '#{RUBY_COMMAND}'"
end

flag :help do
short "-h"
long "--help"
desc "Print usage"
end

attr_reader :args

def self.command(args)
Expand All @@ -77,13 +87,13 @@ def initialize(args = [])

def command
if params[:rspec]
RSPEC_COMMAND
params[:all] ? ALL_RSPEC_COMMAND : RSPEC_COMMAND
elsif params[:rake]
RAKE_COMMAND
params[:all] ? ALL_RAKE_COMMAND : RAKE_COMMAND
elsif params[:rails]
RAILS_COMMAND
params[:all] ? ALL_RAILS_COMMAND : RAILS_COMMAND
elsif params[:ruby]
RUBY_COMMAND
params[:all] ? NO_COMMAND : RUBY_COMMAND
else
params[:command] || NO_COMMAND
end
Expand Down
2 changes: 2 additions & 0 deletions test/retest/options/help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Arguments:
COMMAND The test command to rerun when a file changes

Options:
--all Run all the specs of a specificied ruby setup
-h, --help Print usage
--rails Shortcut for 'bundle exec rails test <test>'
--rake Shortcut for 'bundle exec rake test TEST=<test>'
Expand All @@ -19,6 +20,7 @@ Examples:

Runs all rails tests after a file change
$ retest 'bundle exec rails test'
$ retest --rails --all

Runs a hardcoded command after a file change
$ retest 'ruby lib/bottles_test.rb'
30 changes: 24 additions & 6 deletions test/retest/options_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ def setup
@subject = Options.new
end

def test_default_options
@subject.args = ["echo hello world"]

assert_equal 'echo hello world', @subject.command
end

def test_empty_options
@subject.args = []

assert_equal 'echo You have no command assigned', @subject.command
end

def test_rake_flag
@subject.args = ['--rake']

Expand All @@ -30,14 +42,20 @@ def test_ruby_flag
assert_equal 'bundle exec ruby <test>', @subject.command
end

def test_default_options
@subject.args = ["echo hello world"]
def test_all_flag
@subject.args = ['--rake', '--all']

assert_equal 'echo hello world', @subject.command
end
assert_equal 'bundle exec rake test', @subject.command

def test_empty_options
@subject.args = []
@subject.args = ['--rails', '--all']

assert_equal 'bundle exec rails test', @subject.command

@subject.args = ['--rspec', '--all']

assert_equal 'bundle exec rspec', @subject.command

@subject.args = ['--ruby', '--all']

assert_equal 'echo You have no command assigned', @subject.command
end
Expand Down

0 comments on commit 135c034

Please sign in to comment.