minitest-line 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,36 @@
1
+ module Minitest
2
+ def self.plugin_line_options(opts, options)
3
+ opts.on '-l', '--line N', Integer, "Run test at line number" do |lineno|
4
+ options[:line] = lineno
5
+ end
6
+ end
7
+
8
+ def self.plugin_line_init(options)
9
+ return unless exp_line = options[:line]
10
+
11
+ methods = Runnable.runnables.flat_map do |runnable|
12
+ runnable.runnable_methods.map do |name|
13
+ [name, runnable.instance_method(name)]
14
+ end
15
+ end.uniq
16
+
17
+ current_filename = nil
18
+ tests = {}
19
+
20
+ methods.each do |name, meth|
21
+ next unless loc = meth.source_location
22
+ current_filename ||= loc[0]
23
+ next unless current_filename == loc[0]
24
+ tests[loc[1]] = name
25
+ end
26
+
27
+ _, main_test = tests.sort_by { |k, v| -k }.detect do |line, name|
28
+ exp_line >= line
29
+ end
30
+
31
+ raise "Could not find test method after line #{exp_line}" unless main_test
32
+
33
+ options[:filter] = main_test
34
+ end
35
+ end
36
+
@@ -0,0 +1,52 @@
1
+ $LOAD_PATH << File.expand_path('../../lib', __FILE__)
2
+
3
+ require 'stringio'
4
+ require 'minitest'
5
+ require 'minitest/autorun'
6
+ require 'minitest/mock'
7
+
8
+ class LineExample < Minitest::Test
9
+ def test_hello
10
+ p :hello
11
+ end
12
+
13
+ def test_world
14
+ p :world
15
+ end
16
+ end
17
+
18
+ Minitest::Runnable.runnables.delete(LineExample)
19
+
20
+ class TestLine < Minitest::Test
21
+ def run_class(klass, args = [])
22
+ Minitest::Runnable.stub :runnables, [klass] do
23
+ $stdout = io = StringIO.new
24
+ Minitest.run(args)
25
+ $stdout = STDOUT
26
+ io.string
27
+ end
28
+ end
29
+
30
+ def test_line
31
+ (9..12).each do |line|
32
+ output = run_class LineExample, ['--line', line.to_s]
33
+ assert_match /1 runs/, output
34
+ assert_match /:hello/, output
35
+ refute_match /:world/, output
36
+ end
37
+
38
+ (13..45).each do |line|
39
+ output = run_class LineExample, ['--line', line.to_s]
40
+ assert_match /1 runs/, output
41
+ assert_match /:world/, output
42
+ refute_match /:hello/, output
43
+ end
44
+ end
45
+
46
+ def test_before
47
+ assert_raises(RuntimeError) do
48
+ run_class LineExample, ['--line', '8']
49
+ end
50
+ end
51
+ end
52
+
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: minitest-line
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Magnus Holm
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-26 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: minitest
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '5.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '5.0'
30
+ description: Focused tests for Minitest
31
+ email: judofyr@gmail.com
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - test/test_line.rb
37
+ - lib/minitest/line_plugin.rb
38
+ homepage: https://github.com/judofyr/minitest-line
39
+ licenses: []
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubyforge_project:
58
+ rubygems_version: 1.8.25
59
+ signing_key:
60
+ specification_version: 3
61
+ summary: Focused tests for Minitest
62
+ test_files:
63
+ - test/test_line.rb
64
+ has_rdoc: