m 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
@@ -0,0 +1 @@
1
+ 1.9.3-p0
@@ -0,0 +1,2 @@
1
+ rvm:
2
+ - 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in wtf.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -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.
@@ -0,0 +1,74 @@
1
+ # m [![m ci](https://secure.travis-ci.org/qrush/m.png)](http://travis-ci.org/qrush/m)
2
+
3
+ `m` stands for :metal: (metal), which is a better test/unit test runner. @sferik took `t` so this was the next best option.
4
+
5
+ ![Rush is a heavy metal band. Look it up on Wikipedia.](https://raw.github.com/qrush/m/master/rush.jpg)
6
+
7
+ <sub>[Rush at the Bristol Colston Hall May 1979](http://www.flickr.com/photos/8507625@N02/3468299995/)</sub>
8
+
9
+ ## Install
10
+
11
+ Install via:
12
+
13
+ gem install m
14
+
15
+ `m` is Ruby 1.9+ only. Sorry, but `method_source`, `sourcify`, and `ruby_parser` all have trouble with 1.8 so I'm giving up and only supporting 1.9 for now. Patches are welcome!
16
+
17
+ ## Usage
18
+
19
+ Basically, I was sick of using the `-n` flag to grab one test to run, like RSpec's test runner works.
20
+
21
+ Given this file:
22
+
23
+ $ cat -n test/example_test.rb
24
+ 1 require 'test/unit'
25
+ 2
26
+ 3 class ExampleTest < Test::Unit::TestCase
27
+ 4 def test_apple
28
+ 5 assert_equal 1, 1
29
+ 6 end
30
+ 7
31
+ 8 def test_banana
32
+ 9 assert_equal 1, 1
33
+ 10 end
34
+ 11 end
35
+
36
+ You can run a test by line number, using format `m TEST_FILE:LINE_NUMBER_OF_TEST`:
37
+
38
+ $ m test/example_test.rb:4
39
+ Run options: -n /test_apple/
40
+
41
+ # Running tests:
42
+
43
+ .
44
+
45
+ Finished tests in 0.000525s, 1904.7619 tests/s, 1904.7619 assertions/s.
46
+
47
+ 1 tests, 1 assertions, 0 failures, 0 errors, 0 skips
48
+
49
+ Hit the wrong line number? No problem, `m` helps you out:
50
+
51
+ $ m test/example_test.rb:2
52
+ No tests found on line 2. Valid tests to run:
53
+
54
+ test_apple: m test/examples/test_unit_example_test.rb:4
55
+ test_banana: m test/examples/test_unit_example_test.rb:8
56
+
57
+ Want to run the whole test? Just leave off the line number.
58
+
59
+ $ m test/example_test.rb
60
+ Run options:
61
+
62
+ # Running tests:
63
+
64
+ ..
65
+
66
+ Finished tests in 0.001293s, 1546.7904 tests/s, 3093.5808 assertions/s.
67
+
68
+ 1 tests, 2 assertions, 0 failures, 0 errors, 0 skips
69
+
70
+ `m` also works with `ActiveSupport::TestCase` as well, so it will work great with your Rails test suites.
71
+
72
+ ## License
73
+
74
+ This gem is MIT licensed, please see `LICENSE` for more information.
@@ -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
data/bin/m ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'm'
4
+ M.run(ARGV)
@@ -0,0 +1,15 @@
1
+ require "forwardable"
2
+ require "ostruct"
3
+
4
+ require "method_source"
5
+
6
+ require "m/runner"
7
+ require "m/test_collection"
8
+ require "m/test_method"
9
+ require "m/version"
10
+
11
+ module M
12
+ def self.run(argv)
13
+ Runner.new(argv).run
14
+ end
15
+ end
@@ -0,0 +1,46 @@
1
+ module M
2
+ class Runner
3
+ def initialize(argv)
4
+ @file, line = argv.first.split(':')
5
+ @line = line.to_i
6
+ end
7
+
8
+ def run
9
+ tests_to_run = tests.within(@line)
10
+
11
+ if tests_to_run.size > 0
12
+ test_names = tests_to_run.map(&:name).join('|')
13
+ exit Test::Unit::AutoRunner.run(false, nil, ["-n", "/(#{test_names})/"])
14
+ else
15
+ message = "No tests found on line #{@line}. Valid tests to run:\n\n"
16
+ tests.by_line_number do |test|
17
+ message << "#{sprintf("%0#{tests.column_size}s", test.name)}: m #{@file}:#{test.start_line}\n"
18
+ end
19
+ abort message
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def suites
26
+ $:.unshift "./test"
27
+ load @file
28
+ Test::Unit::TestCase.test_suites.inject({}) do |suites, suite_class|
29
+ suites[suite_class] = suite_class.test_methods unless suite_class.test_methods.empty?
30
+ suites
31
+ end
32
+ end
33
+
34
+ def tests
35
+ @tests ||= begin
36
+ collection = TestCollection.new
37
+ suites.each do |suite_class, test_methods|
38
+ test_methods.each do |test_method|
39
+ collection << TestMethod.create(suite_class, test_method)
40
+ end
41
+ end
42
+ collection
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,25 @@
1
+ module M
2
+ class TestCollection
3
+ include Enumerable
4
+ extend Forwardable
5
+ def_delegators :@collection, :size, :<<, :each
6
+
7
+ def initialize(collection = nil)
8
+ @collection = collection || []
9
+ end
10
+
11
+ def within(line)
12
+ self.class.new(select do |test|
13
+ line.zero? || (test.start_line..test.end_line).include?(line)
14
+ end)
15
+ end
16
+
17
+ def column_size
18
+ @column_size ||= map { |test| test.name.to_s.size }.max
19
+ end
20
+
21
+ def by_line_number(&block)
22
+ sort_by(&:start_line).each(&block)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,11 @@
1
+ module M
2
+ class TestMethod < Struct.new(:name, :start_line, :end_line)
3
+ def self.create(suite_class, test_method)
4
+ method = suite_class.instance_method(test_method)
5
+ start_line = method.source_location.last
6
+ end_line = method.source.split("\n").size + start_line - 1
7
+
8
+ new(test_method, start_line, end_line)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module M
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,20 @@
1
+ Gem::Specification.new do |gem|
2
+ gem.authors = ["Nick Quaranto"]
3
+ gem.email = ["nick@quaran.to"]
4
+ gem.homepage = "https://github.com/qrush/m"
5
+
6
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
7
+ gem.files = `git ls-files`.split("\n")
8
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
9
+ gem.name = "m"
10
+ gem.require_paths = ["lib"]
11
+ gem.version = "0.0.1"
12
+
13
+ gem.add_runtime_dependency "method_source", "~> 0.6.7"
14
+ gem.add_development_dependency "rake"
15
+ gem.add_development_dependency "activesupport"
16
+
17
+ gem.required_ruby_version = "~> 1.9"
18
+
19
+ gem.summary = description = %q{Run test/unit tests by line number. Metal!}
20
+ end
Binary file
@@ -0,0 +1,48 @@
1
+ require 'test_helper'
2
+
3
+ class ActiveSupportTest < MTest
4
+ def test_run_simple_test_by_line_number
5
+ output = m('test/examples/active_support_example_test.rb:11')
6
+ assert_output /1 tests, 1 assertions/, output
7
+ end
8
+
9
+ def test_runs_entire_test_without_line_number
10
+ output = m('test/examples/active_support_example_test.rb')
11
+ assert_output /4 tests/, output
12
+ end
13
+
14
+ def test_run_inside_of_test
15
+ output = m('test/examples/active_support_example_test.rb:12')
16
+ assert_output /1 tests, 1 assertions/, output
17
+ end
18
+
19
+ def test_run_on_end_of_test
20
+ output = m('test/examples/active_support_example_test.rb:13')
21
+ assert_output /1 tests, 1 assertions/, output
22
+ end
23
+
24
+ def test_run_inside_big_test
25
+ output = m('test/examples/active_support_example_test.rb:17')
26
+ assert_output /1 tests, 3 assertions/, output
27
+ end
28
+
29
+ def test_run_on_blank_line_orders_tests_by_line_number
30
+ output = m('test/examples/active_support_example_test.rb:2')
31
+
32
+ assert !$?.success?
33
+ expected = <<-EOF
34
+ No tests found on line 2. Valid tests to run:
35
+
36
+ test_normal: m test/examples/active_support_example_test.rb:7
37
+ test_carrot: m test/examples/active_support_example_test.rb:11
38
+ test_daikon: m test/examples/active_support_example_test.rb:15
39
+ test_eggplant_fig: m test/examples/active_support_example_test.rb:21
40
+ EOF
41
+ assert_equal expected.strip, output
42
+ end
43
+
44
+ def test_run_on_test_with_spaces
45
+ output = m('test/examples/active_support_example_test.rb:21')
46
+ assert_output /1 tests, 1 assertions/, output
47
+ end
48
+ end
@@ -0,0 +1,24 @@
1
+ require 'test_helper'
2
+
3
+ class ActiveSupportExampleTest < ActiveSupport::TestCase
4
+ setup do
5
+ end
6
+
7
+ def test_normal
8
+ assert_equal 1, 1
9
+ end
10
+
11
+ test "carrot" do
12
+ assert_equal 1, 1
13
+ end
14
+
15
+ test "daikon" do
16
+ assert_equal 1, 1
17
+ assert_equal 2, 2
18
+ assert_equal 3, 3
19
+ end
20
+
21
+ test "eggplant fig" do
22
+ assert_equal 4, 4
23
+ end
24
+ end
@@ -0,0 +1,13 @@
1
+ require 'test_helper'
2
+
3
+ class MultipleExampleTest < ActiveSupport::TestCase
4
+ %w(grape habanero iceplant).each do |fruit|
5
+ test "#{fruit} is a fruit" do
6
+ assert_equal 1, 1
7
+ end
8
+ end
9
+
10
+ def test_normal
11
+ assert_equal 1, 1
12
+ end
13
+ end
@@ -0,0 +1,16 @@
1
+ require 'test_helper'
2
+
3
+ class TestUnitExampleTest < Test::Unit::TestCase
4
+ def setup
5
+ end
6
+
7
+ def test_apple
8
+ assert_equal 1, 1
9
+ end
10
+
11
+ def test_banana
12
+ assert_equal 1, 1
13
+ assert_equal 2, 2
14
+ assert_equal 3, 3
15
+ end
16
+ end
@@ -0,0 +1,18 @@
1
+ require 'test_helper'
2
+
3
+ class MultipleTest < MTest
4
+ def test_run_simple_test_by_line_number
5
+ output = m('test/examples/multiple_example_test.rb:11')
6
+ assert_output /1 tests, 1 assertions/, output
7
+ end
8
+
9
+ def test_runs_entire_test_without_line_number
10
+ output = m('test/examples/multiple_example_test.rb')
11
+ assert_output /4 tests/, output
12
+ end
13
+
14
+ def test_runs_all_tests_on_given_line_number
15
+ output = m('test/examples/multiple_example_test.rb:6')
16
+ assert_output /3 tests/, output
17
+ end
18
+ end
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'active_support/test_case'
4
+
5
+ class MTest < Test::Unit::TestCase
6
+ def m(arguments)
7
+ `ruby -Ilib ./bin/m #{arguments} 2>&1`.strip
8
+ end
9
+
10
+ def assert_output(regexp, output)
11
+ assert $?.success?, "Execution failed, output:\n\n#{output}"
12
+ assert_match regexp, output
13
+ end
14
+ end
@@ -0,0 +1,37 @@
1
+ require 'test_helper'
2
+
3
+ class TestUnitTest < MTest
4
+ def test_run_simple_test_by_line_number
5
+ output = m('test/examples/test_unit_example_test.rb:7')
6
+ assert_output /1 tests, 1 assertions/, output
7
+ end
8
+
9
+ def test_runs_entire_test_without_line_number
10
+ output = m('test/examples/test_unit_example_test.rb')
11
+ assert_output /2 tests/, output
12
+ end
13
+
14
+ def test_run_inside_of_test
15
+ output = m('test/examples/test_unit_example_test.rb:8')
16
+ assert_output /1 tests, 1 assertions/, output
17
+ end
18
+
19
+ def test_run_on_end_of_test
20
+ output = m('test/examples/test_unit_example_test.rb:9')
21
+ assert_output /1 tests, 1 assertions/, output
22
+ end
23
+
24
+ def test_run_inside_big_test
25
+ output = m('test/examples/test_unit_example_test.rb:14')
26
+ assert_output /1 tests, 3 assertions/, output
27
+ end
28
+
29
+ def test_run_on_blank_line
30
+ output = m('test/examples/test_unit_example_test.rb:2')
31
+
32
+ assert !$?.success?
33
+ assert_match /No tests found on line 2. Valid tests to run:/, output
34
+ assert_match %r{ test_apple: m test/examples/test_unit_example_test\.rb:7}, output
35
+ assert_match %r{test_banana: m test/examples/test_unit_example_test\.rb:11}, output
36
+ end
37
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: m
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Nick Quaranto
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-12-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: method_source
16
+ requirement: &70285743667140 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.6.7
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70285743667140
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake
27
+ requirement: &70285743666240 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70285743666240
36
+ - !ruby/object:Gem::Dependency
37
+ name: activesupport
38
+ requirement: &70285743664500 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70285743664500
47
+ description:
48
+ email:
49
+ - nick@quaran.to
50
+ executables:
51
+ - m
52
+ extensions: []
53
+ extra_rdoc_files: []
54
+ files:
55
+ - .gitignore
56
+ - .rbenv-version
57
+ - .travis.yml
58
+ - Gemfile
59
+ - Gemfile.lock
60
+ - LICENSE
61
+ - README.md
62
+ - Rakefile
63
+ - bin/m
64
+ - lib/m.rb
65
+ - lib/m/runner.rb
66
+ - lib/m/test_collection.rb
67
+ - lib/m/test_method.rb
68
+ - lib/m/version.rb
69
+ - m.gemspec
70
+ - rush.jpg
71
+ - test/active_support_test.rb
72
+ - test/examples/active_support_example_test.rb
73
+ - test/examples/multiple_example_test.rb
74
+ - test/examples/test_unit_example_test.rb
75
+ - test/multiple_test.rb
76
+ - test/test_helper.rb
77
+ - test/test_unit_test.rb
78
+ homepage: https://github.com/qrush/m
79
+ licenses: []
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: '1.9'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 1.8.11
99
+ signing_key:
100
+ specification_version: 3
101
+ summary: Run test/unit tests by line number. Metal!
102
+ test_files:
103
+ - test/active_support_test.rb
104
+ - test/examples/active_support_example_test.rb
105
+ - test/examples/multiple_example_test.rb
106
+ - test/examples/test_unit_example_test.rb
107
+ - test/multiple_test.rb
108
+ - test/test_helper.rb
109
+ - test/test_unit_test.rb