Created
November 2, 2010 11:29
-
-
Save icebreaker/659507 to your computer and use it in GitHub Desktop.
Run a single test from a test suite.
This file contains hidden or 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
| #!/usr/bin/ruby | |
| require 'tempfile' | |
| if ARGV.size < 3 | |
| # Example test_runner unit post "can delete" | |
| puts "usage: test_runner [type=unit,functional,integration] [testname] [testmethod]" | |
| exit | |
| end | |
| class TestRunner | |
| def initialize(options) | |
| @type = options[:type] | |
| @name = options[:name] | |
| @method = options[:method] | |
| end | |
| def run() | |
| testfile = "#{File.dirname(__FILE__)}/test/#{@type}/#{@name}_test.rb" | |
| if not File.exist?(testfile) | |
| puts "#{testfile} doesn't exist ..." | |
| return | |
| end | |
| testfile_contents = File.read(testfile) | |
| testfile_newcontents = testfile_contents.to_s | |
| testfile_contents.scan(/(test[\s].*?end)/m) do |match| | |
| unless match.to_s.match(@method) | |
| testfile_newcontents = testfile_newcontents.gsub(match.to_s,'') | |
| end | |
| end | |
| f = Tempfile.open('test') | |
| f.write(testfile_newcontents); | |
| f.close(); | |
| # pluralize | |
| type = @type.gsub("unit","units").gsub("functional","functionals") | |
| system("rake test:#{type} TEST=#{f.path}") | |
| end | |
| end | |
| test = TestRunner.new(:type=>ARGV[0],:name=>ARGV[1],:method=>ARGV[2]); | |
| test.run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment