Skip to content

Commit 2fd8797

Browse files
committedDec 24, 2011
proper gem setup, test it out too
1 parent 84d307b commit 2fd8797

13 files changed

+196
-32
lines changed
 

‎.rbenv-version

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.9.3-p0

‎Gemfile

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
source 'https://rubygems.org'
2+
3+
# Specify your gem's dependencies in wtf.gemspec
4+
gemspec

‎Gemfile.lock

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
PATH
2+
remote: .
3+
specs:
4+
m (0.0.1)
5+
ruby_parser (~> 2.3.1)
6+
7+
GEM
8+
remote: https://rubygems.org/
9+
specs:
10+
rake (0.9.2.2)
11+
ruby_parser (2.3.1)
12+
sexp_processor (~> 3.0)
13+
sexp_processor (3.0.9)
14+
15+
PLATFORMS
16+
ruby
17+
18+
DEPENDENCIES
19+
m!
20+
rake

‎LICENSE

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright (c) 2011 Nick Quaranto
2+
3+
Permission is hereby granted, free of charge, to any person obtaining
4+
a copy of this software and associated documentation files (the
5+
"Software"), to deal in the Software without restriction, including
6+
without limitation the rights to use, copy, modify, merge, publish,
7+
distribute, sublicense, and/or sell copies of the Software, and to
8+
permit persons to whom the Software is furnished to do so, subject to
9+
the following conditions:
10+
11+
The above copyright notice and this permission notice shall be
12+
included in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

‎README.md

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# m
2+
3+
`m` stands :metal: (metal), which is a better test/unit test runner. @sferik took `t` so this was the next best option.
4+
5+
## Usage
6+
7+
Basically, I was sick of using the `-n` flag to grab one test to run, like RSpec's test runner works.
8+
9+
Given this file:
10+
11+
$ cat -n test/example_test.rb
12+
1 require 'test/unit'
13+
2
14+
3 class ExampleTest < Test::Unit::TestCase
15+
4 def test_apple
16+
5 assert_equal 1, 1
17+
6 end
18+
7
19+
8 def test_banana
20+
9 assert_equal 1, 1
21+
10 end
22+
11 end
23+
24+
You can run a test by line number, using format `m TEST_FILE:LINE_NUMBER_OF_TEST`:
25+
26+
$ m test/example_test.rb:4
27+
Run options: -n /test_apple/
28+
29+
# Running tests:
30+
31+
.
32+
33+
Finished tests in 0.000525s, 1904.7619 tests/s, 1904.7619 assertions/s.
34+
35+
1 tests, 1 assertions, 0 failures, 0 errors, 0 skips
36+
37+
## License
38+
39+
This gem is MIT licensed, please see `LICENSE` for more information.

‎Rakefile

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env rake
2+
require "bundler/gem_tasks"
3+
require "rake/testtask"
4+
5+
task :default => :test
6+
7+
Rake::TestTask.new do |t|
8+
t.libs << 'test'
9+
t.pattern = 'test/*_test.rb'
10+
end

‎bin/m

+19-17
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
#!/usr/bin/env ruby
22

3-
require 'ruby_parser'
4-
require 'pp'
5-
6-
file, line = ARGV.first.split(':')
7-
8-
if line
9-
parser = RubyParser.new
10-
r = parser.parse(File.read(file))
11-
r.each_of_type(:defn) do |s|
12-
if s.line == line.to_i
13-
method_name = s.sexp_body.first
14-
exec "ruby -Itest #{file} -n '/#{method_name}/'"
15-
end
16-
end
17-
else
18-
exec "ruby -Itest #{file}"
19-
end
3+
require 'm'
4+
M.run(ARGV)
5+
#require 'ruby_parser'
6+
#require 'pp'
7+
#
8+
#file, line = ARGV.first.split(':')
9+
#
10+
#if line
11+
# parser = RubyParser.new
12+
# r = parser.parse(File.read(file))
13+
# r.each_of_type(:defn) do |s|
14+
# if s.line == line.to_i
15+
# method_name = s.sexp_body.first
16+
# exec "ruby -Itest #{file} -n '/#{method_name}/'"
17+
# end
18+
# end
19+
#else
20+
# exec "ruby -Itest #{file}"
21+
#end

‎lib/m.rb

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
require "ruby_parser"
2+
3+
require "m/version"
4+
5+
module M
6+
class Runner
7+
def initialize(argv)
8+
@file, @line = argv.first.split(':')
9+
end
10+
11+
def run
12+
if @line
13+
parser = RubyParser.new
14+
sexps = parser.parse(File.read(@file))
15+
sexps.each_of_type(:defn) do |sexp|
16+
if sexp.line == @line.to_i
17+
method_name = sexp.sexp_body.first
18+
run_tests method_name
19+
end
20+
end
21+
else
22+
run_tests
23+
end
24+
end
25+
26+
private
27+
28+
def run_tests(method_name = nil)
29+
command = "ruby -Itest #{@file}"
30+
command << " -n '/#{method_name}/'" if method_name
31+
exec command
32+
end
33+
end
34+
35+
def self.run(argv)
36+
Runner.new(argv).run
37+
end
38+
end

‎lib/m/version.rb

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module M
2+
VERSION = "0.0.1"
3+
end

‎m.gemspec

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Gem::Specification.new do |gem|
2+
gem.authors = ["Nick Quaranto"]
3+
gem.email = ["nick@quaran.to"]
4+
gem.description = %q{TODO: Write a gem description}
5+
gem.summary = %q{TODO: Write a gem summary}
6+
gem.homepage = ""
7+
8+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
9+
gem.files = `git ls-files`.split("\n")
10+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
11+
gem.name = "m"
12+
gem.require_paths = ["lib"]
13+
gem.version = "0.0.1"
14+
15+
gem.add_runtime_dependency "ruby_parser", "~> 2.3.1"
16+
gem.add_development_dependency "rake"
17+
end

‎test/example_test.rb

+1-15
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
require 'test/unit'
1+
require 'test_helper'
22

33
class ExampleTest < Test::Unit::TestCase
4-
def setup
5-
end
6-
74
def test_apple
85
assert_equal 1, 1
96
end
@@ -12,14 +9,3 @@ def test_banana
129
assert_equal 1, 1
1310
end
1411
end
15-
16-
#class Wtf
17-
# def zomg
18-
#
19-
# end
20-
#
21-
# def lol(*args)
22-
#
23-
# end
24-
#
25-
#end

‎test/run_by_line_number_test.rb

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
require 'test_helper'
2+
3+
class RunByLineNumberTest < MTest
4+
def test_run_simple_test_by_line_number
5+
output = m('test/example_test.rb:4')
6+
7+
assert $?.success?, "Execution failed, output:\n\n#{output}"
8+
assert_match /1 tests, 1 assertions/, output
9+
end
10+
11+
def test_runs_entire_test_without_line_number
12+
output = m('test/example_test.rb')
13+
14+
assert $?.success?, "Execution failed, output:\n\n#{output}"
15+
assert_match /2 tests, 2 assertions/, output
16+
end
17+
end

‎test/test_helper.rb

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require 'test/unit'
2+
3+
class MTest < Test::Unit::TestCase
4+
def m(arguments)
5+
`ruby -Ilib ./bin/m #{arguments}`.strip
6+
end
7+
end

0 commit comments

Comments
 (0)
Please sign in to comment.