Permalink
Browse files

proper gem setup, test it out too

  • Loading branch information...
1 parent 84d307b commit 2fd879754e8e6fd3681be6bedf360b389547894b @qrush committed Dec 24, 2011
Showing with 196 additions and 32 deletions.
  1. +1 −0 .rbenv-version
  2. +4 −0 Gemfile
  3. +20 −0 Gemfile.lock
  4. +20 −0 LICENSE
  5. +39 −0 README.md
  6. +10 −0 Rakefile
  7. +19 −17 bin/m
  8. +38 −0 lib/m.rb
  9. +3 −0 lib/m/version.rb
  10. +17 −0 m.gemspec
  11. +1 −15 test/example_test.rb
  12. +17 −0 test/run_by_line_number_test.rb
  13. +7 −0 test/test_helper.rb
View
@@ -0,0 +1 @@
+1.9.3-p0
View
@@ -0,0 +1,4 @@
+source 'https://rubygems.org'
+
+# Specify your gem's dependencies in wtf.gemspec
+gemspec
View
@@ -0,0 +1,20 @@
+PATH
+ remote: .
+ specs:
+ m (0.0.1)
+ ruby_parser (~> 2.3.1)
+
+GEM
+ remote: https://rubygems.org/
+ specs:
+ rake (0.9.2.2)
+ ruby_parser (2.3.1)
+ sexp_processor (~> 3.0)
+ sexp_processor (3.0.9)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ m!
+ rake
View
20 LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2011 Nick Quaranto
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
@@ -0,0 +1,39 @@
+# m
+
+`m` stands :metal: (metal), which is a better test/unit test runner. @sferik took `t` so this was the next best option.
+
+## Usage
+
+Basically, I was sick of using the `-n` flag to grab one test to run, like RSpec's test runner works.
+
+Given this file:
+
+ $ cat -n test/example_test.rb
+ 1 require 'test/unit'
+ 2
+ 3 class ExampleTest < Test::Unit::TestCase
+ 4 def test_apple
+ 5 assert_equal 1, 1
+ 6 end
+ 7
+ 8 def test_banana
+ 9 assert_equal 1, 1
+ 10 end
+ 11 end
+
+You can run a test by line number, using format `m TEST_FILE:LINE_NUMBER_OF_TEST`:
+
+ $ m test/example_test.rb:4
+ Run options: -n /test_apple/
+
+ # Running tests:
+
+ .
+
+ Finished tests in 0.000525s, 1904.7619 tests/s, 1904.7619 assertions/s.
+
+ 1 tests, 1 assertions, 0 failures, 0 errors, 0 skips
+
+## License
+
+This gem is MIT licensed, please see `LICENSE` for more information.
View
@@ -0,0 +1,10 @@
+#!/usr/bin/env rake
+require "bundler/gem_tasks"
+require "rake/testtask"
+
+task :default => :test
+
+Rake::TestTask.new do |t|
+ t.libs << 'test'
+ t.pattern = 'test/*_test.rb'
+end
View
36 bin/m
@@ -1,19 +1,21 @@
#!/usr/bin/env ruby
-require 'ruby_parser'
-require 'pp'
-
-file, line = ARGV.first.split(':')
-
-if line
- parser = RubyParser.new
- r = parser.parse(File.read(file))
- r.each_of_type(:defn) do |s|
- if s.line == line.to_i
- method_name = s.sexp_body.first
- exec "ruby -Itest #{file} -n '/#{method_name}/'"
- end
- end
-else
- exec "ruby -Itest #{file}"
-end
+require 'm'
+M.run(ARGV)
+#require 'ruby_parser'
+#require 'pp'
+#
+#file, line = ARGV.first.split(':')
+#
+#if line
+# parser = RubyParser.new
+# r = parser.parse(File.read(file))
+# r.each_of_type(:defn) do |s|
+# if s.line == line.to_i
+# method_name = s.sexp_body.first
+# exec "ruby -Itest #{file} -n '/#{method_name}/'"
+# end
+# end
+#else
+# exec "ruby -Itest #{file}"
+#end
View
@@ -0,0 +1,38 @@
+require "ruby_parser"
+
+require "m/version"
+
+module M
+ class Runner
+ def initialize(argv)
+ @file, @line = argv.first.split(':')
+ end
+
+ def run
+ if @line
+ parser = RubyParser.new
+ sexps = parser.parse(File.read(@file))
+ sexps.each_of_type(:defn) do |sexp|
+ if sexp.line == @line.to_i
+ method_name = sexp.sexp_body.first
+ run_tests method_name
+ end
+ end
+ else
+ run_tests
+ end
+ end
+
+ private
+
+ def run_tests(method_name = nil)
+ command = "ruby -Itest #{@file}"
+ command << " -n '/#{method_name}/'" if method_name
+ exec command
+ end
+ end
+
+ def self.run(argv)
+ Runner.new(argv).run
+ end
+end
View
@@ -0,0 +1,3 @@
+module M
+ VERSION = "0.0.1"
+end
View
@@ -0,0 +1,17 @@
+Gem::Specification.new do |gem|
+ gem.authors = ["Nick Quaranto"]
+ gem.email = ["nick@quaran.to"]
+ gem.description = %q{TODO: Write a gem description}
+ gem.summary = %q{TODO: Write a gem summary}
+ gem.homepage = ""
+
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ gem.files = `git ls-files`.split("\n")
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ gem.name = "m"
+ gem.require_paths = ["lib"]
+ gem.version = "0.0.1"
+
+ gem.add_runtime_dependency "ruby_parser", "~> 2.3.1"
+ gem.add_development_dependency "rake"
+end
View
@@ -1,9 +1,6 @@
-require 'test/unit'
+require 'test_helper'
class ExampleTest < Test::Unit::TestCase
- def setup
- end
-
def test_apple
assert_equal 1, 1
end
@@ -12,14 +9,3 @@ def test_banana
assert_equal 1, 1
end
end
-
-#class Wtf
-# def zomg
-#
-# end
-#
-# def lol(*args)
-#
-# end
-#
-#end
@@ -0,0 +1,17 @@
+require 'test_helper'
+
+class RunByLineNumberTest < MTest
+ def test_run_simple_test_by_line_number
+ output = m('test/example_test.rb:4')
+
+ assert $?.success?, "Execution failed, output:\n\n#{output}"
+ assert_match /1 tests, 1 assertions/, output
+ end
+
+ def test_runs_entire_test_without_line_number
+ output = m('test/example_test.rb')
+
+ assert $?.success?, "Execution failed, output:\n\n#{output}"
+ assert_match /2 tests, 2 assertions/, output
+ end
+end
View
@@ -0,0 +1,7 @@
+require 'test/unit'
+
+class MTest < Test::Unit::TestCase
+ def m(arguments)
+ `ruby -Ilib ./bin/m #{arguments}`.strip
+ end
+end

0 comments on commit 2fd8797

Please sign in to comment.