Navigation Menu

Skip to content

Commit

Permalink
proper gem setup, test it out too
Browse files Browse the repository at this point in the history
  • Loading branch information
qrush committed Dec 24, 2011
1 parent 84d307b commit 2fd8797
Show file tree
Hide file tree
Showing 13 changed files with 196 additions and 32 deletions.
1 change: 1 addition & 0 deletions .rbenv-version
@@ -0,0 +1 @@
1.9.3-p0
4 changes: 4 additions & 0 deletions Gemfile
@@ -0,0 +1,4 @@
source 'https://rubygems.org'

# Specify your gem's dependencies in wtf.gemspec
gemspec
20 changes: 20 additions & 0 deletions Gemfile.lock
@@ -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
20 changes: 20 additions & 0 deletions 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.
39 changes: 39 additions & 0 deletions README.md
@@ -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.
10 changes: 10 additions & 0 deletions Rakefile
@@ -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
36 changes: 19 additions & 17 deletions 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
38 changes: 38 additions & 0 deletions lib/m.rb
@@ -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
3 changes: 3 additions & 0 deletions lib/m/version.rb
@@ -0,0 +1,3 @@
module M
VERSION = "0.0.1"
end
17 changes: 17 additions & 0 deletions m.gemspec
@@ -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
16 changes: 1 addition & 15 deletions test/example_test.rb
@@ -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
Expand All @@ -12,14 +9,3 @@ def test_banana
assert_equal 1, 1
end
end

#class Wtf
# def zomg
#
# end
#
# def lol(*args)
#
# end
#
#end
17 changes: 17 additions & 0 deletions test/run_by_line_number_test.rb
@@ -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
7 changes: 7 additions & 0 deletions test/test_helper.rb
@@ -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.