Skip to content

Commit

Permalink
Merge pull request #105 from Shopify/improve-dev-commands
Browse files Browse the repository at this point in the history
Improve dev commands
  • Loading branch information
Mangara authored Sep 9, 2021
2 parents 350910b + 7d7c3e5 commit 84eb01a
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
32 changes: 32 additions & 0 deletions bin/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

def main
begin
command = create_command
rescue ArgumentError => e
abort(e.message)
end
puts "Running #{command.join(" ")}"
system(*command)
end

def create_command
case ARGV.length
when 0
["bundle", "exec", "rake", "test"]
when 1
filename = ARGV[0]
["bundle", "exec", "rake", "test", "TEST=#{filename}"]
when 2
filename = ARGV[0]
test_name = ARGV[1]
test_name_with_underscores = test_name.tr(" ", "_")
test_name_pattern = "/#{Regexp.escape(test_name_with_underscores)}/"
["bundle", "exec", "rake", "test", "TEST=#{filename}", "TESTOPTS=\"--name=#{test_name_pattern} -v\""]
else
raise ArgumentError, "Too many arguments. Did you forget to put the test name in quotes?"
end
end

main
38 changes: 37 additions & 1 deletion dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,40 @@ up:
met?: mysql -uroot -h job-iteration.railgun job_iteration_test -e "SELECT 1" &> /dev/null

commands:
test: bundle exec rake
test:
run: bin/test "$@"
syntax:
optional: filename testnamepattern
aliases: [t]
desc: run tests
long_desc: |
{{bold:Default}}
=======
Run the entire test suite.
Examples:
{{command:dev test}}
{{command:dev t}}
{{bold:Run all tests in a file}}
========================
Include the file path.
Example:
{{command:dev test test/unit/iteration_test.rb}}
{{bold:Run a single test in a given file}}
========================
Include the file path and the name of the test you'd like to run.
Example:
{{command:dev test test/unit/iteration_test.rb test_that_it_has_a_version_number}}
{{bold:Run all tests in a given file whose name contains a string}}
========================
Include the file path and the string that the test names should contain.
Example:
{{command:dev test test/unit/iteration_test.rb version_number}}
style:
run: bundle exec rubocop -a

0 comments on commit 84eb01a

Please sign in to comment.