m 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,4 +1,3 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in wtf.gemspec
4
3
  gemspec
data/lib/m.rb CHANGED
@@ -15,14 +15,14 @@
15
15
  #If you're using Bundler, you'll need to include it in your Gemfile. Toss it into the `test` group:
16
16
  #
17
17
  # group :test do
18
- # gem 'm', '~> 1.0'
18
+ # gem 'm', '~> 1.1'
19
19
  # end
20
20
  #
21
21
  #Developing a RubyGem? Add `m` as a development dependency.
22
22
  #
23
23
  # Gem::Specification.new do |gem|
24
24
  # # ...
25
- # gem.add_development_dependency "m", "~> 1.0"
25
+ # gem.add_development_dependency "m", "~> 1.1"
26
26
  # end
27
27
  #
28
28
  #`m` is Ruby 1.9+ only. Sorry, but `method_source`, `sourcify`, and `ruby_parser`
@@ -83,8 +83,13 @@
83
83
  #
84
84
  # 1 tests, 2 assertions, 0 failures, 0 errors, 0 skips
85
85
  #
86
- #`m` also works with `ActiveSupport::TestCase` as well, so it will work great with
87
- #your Rails test suites.
86
+ #### Supports
87
+ #
88
+ #`m` works with a few Ruby test frameworks:
89
+ #
90
+ #* `Test::Unit`
91
+ #* `ActiveSupport::TestCase`
92
+ #* `MiniTest::Unit::TestCase`
88
93
  #
89
94
  ### License
90
95
  #
@@ -93,7 +98,7 @@
93
98
  ### M, your metal test runner
94
99
  # Maybe this gem should have a longer name? Metal?
95
100
  module M
96
- VERSION = "1.0.1"
101
+ VERSION = "1.1.0"
97
102
 
98
103
  # Accept arguments coming from bin/m and run tests.
99
104
  def self.run(argv)
@@ -151,8 +156,17 @@ module M
151
156
  # assemble the regexp to run these tests,
152
157
  test_names = tests_to_run.map(&:name).join('|')
153
158
 
159
+ # set up the args needed for the runner
160
+ test_arguments = ["-n", "/(#{test_names})/"]
161
+
154
162
  # directly run the tests from here and exit with the status of the tests passing or failing
155
- exit Test::Unit::AutoRunner.run(false, nil, ["-n", "/(#{test_names})/"])
163
+ if defined?(Test)
164
+ exit Test::Unit::AutoRunner.run(false, nil, test_arguments)
165
+ elsif defined?(MiniTest)
166
+ exit MiniTest::Unit.runner.run test_arguments
167
+ else
168
+ not_supported
169
+ end
156
170
  else
157
171
  # Otherwise we found no tests on this line, so you need to pick one.
158
172
  message = "No tests found on line #{@line}. Valid tests to run:\n\n"
@@ -170,8 +184,8 @@ module M
170
184
 
171
185
  # Finds all test suites in this test file, with test methods included.
172
186
  def suites
173
- # Since we're not using `ruby -Itest` to run the tests, we need to add this directory to the `LOAD_PATH`
174
- $:.unshift "./test"
187
+ # Since we're not using `ruby -Itest -Ilib` to run the tests, we need to add this directory to the `LOAD_PATH`
188
+ $:.unshift "./test", "./lib"
175
189
 
176
190
  begin
177
191
  # Fire up this Ruby file. Let's hope it actually has tests.
@@ -181,8 +195,17 @@ module M
181
195
  abort "Failed loading test file:\n#{e.message}"
182
196
  end
183
197
 
184
- # Use some janky internal test/unit API to group test methods by test suite.
185
- Test::Unit::TestCase.test_suites.inject({}) do |suites, suite_class|
198
+ # Figure out what test framework we're using
199
+ if defined?(Test)
200
+ suites = Test::Unit::TestCase.test_suites
201
+ elsif defined?(MiniTest)
202
+ suites = MiniTest::Unit::TestCase.test_suites
203
+ else
204
+ not_supported
205
+ end
206
+
207
+ # Use some janky internal APIs to group test methods by test suite.
208
+ suites.inject({}) do |suites, suite_class|
186
209
  # End up with a hash of suite class name to an array of test methods, so we can later find them and ignore empty test suites
187
210
  suites[suite_class] = suite_class.test_methods if suite_class.test_methods.size > 0
188
211
  suites
@@ -206,5 +229,10 @@ module M
206
229
  end
207
230
  end
208
231
  end
232
+
233
+ # Fail loudly if this isn't supported
234
+ def not_supported
235
+ abort "This test framework is not supported! Please open up an issue at https://github.com/qrush/m !"
236
+ end
209
237
  end
210
238
  end
data/m.gemspec CHANGED
@@ -17,6 +17,7 @@ Gem::Specification.new do |gem|
17
17
  gem.add_development_dependency "activesupport"
18
18
  gem.add_development_dependency "rdiscount"
19
19
  gem.add_development_dependency "rocco"
20
+ gem.add_development_dependency "minitest"
20
21
 
21
22
  gem.required_ruby_version = "~> 1.9"
22
23
 
@@ -3,7 +3,7 @@ require 'test_helper'
3
3
  class EverythingTest < MTest
4
4
  def test_runs_entire_test_suite_with_no_arguments
5
5
  output = m('')
6
- assert_output /10 tests/, output
6
+ assert_output /12 tests/, output
7
7
  end
8
8
 
9
9
  def test_missing_file_gives_a_decent_error_message
@@ -18,6 +18,6 @@ class EverythingTest < MTest
18
18
  assert_output /3 tests/, output
19
19
 
20
20
  output = m('examples')
21
- assert_output /10 tests/, output
21
+ assert_output /12 tests/, output
22
22
  end
23
23
  end
@@ -0,0 +1,28 @@
1
+ require 'minitest/unit'
2
+
3
+ class Meme
4
+ def i_can_has_cheezburger?
5
+ "OHAI!"
6
+ end
7
+
8
+ def will_it_blend?
9
+ "YES!"
10
+ end
11
+ end
12
+
13
+
14
+ class TestMeme < MiniTest::Unit::TestCase
15
+ def setup
16
+ @meme = Meme.new
17
+ end
18
+
19
+ def test_that_kitty_can_eat
20
+ assert_equal "OHAI!", @meme.i_can_has_cheezburger?
21
+ end
22
+
23
+ def test_that_it_will_not_blend
24
+ refute_match /^maybe/i, @meme.will_it_blend?
25
+ refute_match /^no/i, @meme.will_it_blend?
26
+ refute_match /^lolz/i, @meme.will_it_blend?
27
+ end
28
+ end
@@ -0,0 +1,38 @@
1
+ require 'test_helper'
2
+
3
+ class MinitestTest < MTest
4
+ def test_run_simple_test_by_line_number
5
+ output = m('examples/minitest_example_test.rb:19')
6
+ assert_output /1 tests, 1 assertions/, output
7
+ end
8
+
9
+ def test_runs_entire_test_without_line_number
10
+ output = m('examples/minitest_example_test.rb')
11
+ assert_output /2 tests/, output
12
+ end
13
+
14
+ def test_run_inside_of_test
15
+ output = m('examples/minitest_example_test.rb:20')
16
+ assert_output /1 tests, 1 assertions/, output
17
+ end
18
+
19
+ def test_run_on_end_of_test
20
+ output = m('examples/minitest_example_test.rb:21')
21
+ assert_output /1 tests, 1 assertions/, output
22
+ end
23
+
24
+ def test_run_inside_big_test
25
+ output = m('examples/minitest_example_test.rb:25')
26
+ assert_output /1 tests, 6 assertions/, output
27
+ end
28
+
29
+ def test_run_on_blank_line
30
+ output = m('examples/minitest_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_that_kitty_can_eat: m examples/minitest_example_test\.rb:19}, output
35
+ assert_match %r{test_that_it_will_not_blend: m examples/minitest_example_test\.rb:23}, output
36
+ end
37
+ end
38
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: m
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-24 00:00:00.000000000 Z
12
+ date: 2012-04-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: method_source
16
- requirement: &70258225055260 !ruby/object:Gem::Requirement
16
+ requirement: &70312941477320 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.6.7
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70258225055260
24
+ version_requirements: *70312941477320
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &70258225054420 !ruby/object:Gem::Requirement
27
+ requirement: &70312941476520 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -35,10 +35,10 @@ dependencies:
35
35
  version: 1.0.0
36
36
  type: :runtime
37
37
  prerelease: false
38
- version_requirements: *70258225054420
38
+ version_requirements: *70312941476520
39
39
  - !ruby/object:Gem::Dependency
40
40
  name: activesupport
41
- requirement: &70258225069800 !ruby/object:Gem::Requirement
41
+ requirement: &70312941475560 !ruby/object:Gem::Requirement
42
42
  none: false
43
43
  requirements:
44
44
  - - ! '>='
@@ -46,10 +46,10 @@ dependencies:
46
46
  version: '0'
47
47
  type: :development
48
48
  prerelease: false
49
- version_requirements: *70258225069800
49
+ version_requirements: *70312941475560
50
50
  - !ruby/object:Gem::Dependency
51
51
  name: rdiscount
52
- requirement: &70258225069260 !ruby/object:Gem::Requirement
52
+ requirement: &70312941510320 !ruby/object:Gem::Requirement
53
53
  none: false
54
54
  requirements:
55
55
  - - ! '>='
@@ -57,10 +57,10 @@ dependencies:
57
57
  version: '0'
58
58
  type: :development
59
59
  prerelease: false
60
- version_requirements: *70258225069260
60
+ version_requirements: *70312941510320
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: rocco
63
- requirement: &70258225068840 !ruby/object:Gem::Requirement
63
+ requirement: &70312941509900 !ruby/object:Gem::Requirement
64
64
  none: false
65
65
  requirements:
66
66
  - - ! '>='
@@ -68,7 +68,18 @@ dependencies:
68
68
  version: '0'
69
69
  type: :development
70
70
  prerelease: false
71
- version_requirements: *70258225068840
71
+ version_requirements: *70312941509900
72
+ - !ruby/object:Gem::Dependency
73
+ name: minitest
74
+ requirement: &70312941509480 !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ type: :development
81
+ prerelease: false
82
+ version_requirements: *70312941509480
72
83
  description:
73
84
  email:
74
85
  - nick@quaran.to
@@ -96,11 +107,13 @@ files:
96
107
  - test/bench.rb
97
108
  - test/everything_test.rb
98
109
  - test/examples/active_support_example_test.rb
110
+ - test/examples/minitest_example_test.rb
99
111
  - test/examples/multiple_example_test.rb
100
112
  - test/examples/subdir/a_test.rb
101
113
  - test/examples/subdir/b_test.rb
102
114
  - test/examples/subdir/c_test.rb
103
115
  - test/examples/test_unit_example_test.rb
116
+ - test/minitest_test.rb
104
117
  - test/multiple_test.rb
105
118
  - test/test_helper.rb
106
119
  - test/test_unit_test.rb
@@ -134,11 +147,13 @@ test_files:
134
147
  - test/bench.rb
135
148
  - test/everything_test.rb
136
149
  - test/examples/active_support_example_test.rb
150
+ - test/examples/minitest_example_test.rb
137
151
  - test/examples/multiple_example_test.rb
138
152
  - test/examples/subdir/a_test.rb
139
153
  - test/examples/subdir/b_test.rb
140
154
  - test/examples/subdir/c_test.rb
141
155
  - test/examples/test_unit_example_test.rb
156
+ - test/minitest_test.rb
142
157
  - test/multiple_test.rb
143
158
  - test/test_helper.rb
144
159
  - test/test_unit_test.rb