Skip to content

Instantly share code, notes, and snippets.

@kizzx2
Created May 10, 2014 05:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kizzx2/29b703488367ee852af2 to your computer and use it in GitHub Desktop.
Save kizzx2/29b703488367ee852af2 to your computer and use it in GitHub Desktop.
Run single test with Spring in Rails 4.1
require 'optparse'
$: << Rails.root.join('test')
options = {}
OptionParser.new do |opts|
opts.on('-n TEST_NAME') do |n|
options[:test_name] = n
end
opts.on('-e ENVIRONMENT') do |e|
raise ArgumentError.new("Must run in test environment") if e != 'test'
end
end.parse!
test_files = ARGV.dup
ARGV.clear
if options[:test_name]
ARGV << "-n" << options[:test_name]
end
test_files.each do |f|
Dir[f].each do |f1|
load f1
end
end
@kizzx2
Copy link
Author

kizzx2 commented May 10, 2014

Usage is almost like the good old ruby -I test way:

$ bin/rails r -e test script/test.rb test/controllers/my_controler_test.rb -n test_my_case
$ bin/rails r -e test script/test.rb test/controllers/**/*.rb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment