testrbl 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile CHANGED
@@ -2,6 +2,7 @@ source :rubygems
2
2
  gemspec
3
3
 
4
4
  gem 'test-unit'
5
+ gem 'minitest'
5
6
  gem 'rake'
6
7
  gem 'rspec', '~>2'
7
8
  gem 'shoulda'
data/Gemfile.lock CHANGED
@@ -1,12 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- testrbl (0.1.6)
4
+ testrbl (0.1.7)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
8
8
  specs:
9
9
  diff-lcs (1.1.3)
10
+ minitest (3.0.1)
10
11
  rake (0.9.2)
11
12
  rspec (2.6.0)
12
13
  rspec-core (~> 2.6.0)
@@ -21,12 +22,13 @@ GEM
21
22
  shoulda-matchers (~> 1.0.0)
22
23
  shoulda-context (1.0.0)
23
24
  shoulda-matchers (1.0.0)
24
- test-unit (2.4.4)
25
+ test-unit (2.4.8)
25
26
 
26
27
  PLATFORMS
27
28
  ruby
28
29
 
29
30
  DEPENDENCIES
31
+ minitest
30
32
  rake
31
33
  rspec (~> 2)
32
34
  shoulda
data/Readme.md CHANGED
@@ -1,4 +1,4 @@
1
- Run ruby Test::Unit/Shoulda tests by line-number / folder / the dozen.<br/>
1
+ Run ruby Test::Unit/Shoulda/Minitest tests by line-number / folder / the dozen.<br/>
2
2
  (everything not matching "file:line" is simply passed to testrb)
3
3
 
4
4
  Install
@@ -15,10 +15,6 @@ Tips
15
15
  ====
16
16
  - `can't find executable testrb`: uninstall old version of test-unit, they define testrb in multiple incompatible ways
17
17
 
18
- TODO
19
- ====
20
- - prepend shoulda contexts to search -n '/OUTER-CONTEXT.*INNER-CONTEXT.*SHOULD/', make sure indentation is decreasing by 1 every step to avoid fetching everything
21
-
22
18
  Author
23
19
  ======
24
20
  [Michael Grosser](http://grosser.it)<br/>
@@ -1,3 +1,3 @@
1
1
  module Testrbl
2
- VERSION = '0.1.6'
2
+ VERSION = '0.1.7'
3
3
  end
data/lib/testrbl.rb CHANGED
@@ -2,31 +2,43 @@ require 'testrbl/version'
2
2
 
3
3
  module Testrbl
4
4
  PATTERNS = [
5
- /^(\s+)(should|test)\s+['"](.*)['"]\s+do\s*$/,
5
+ /^(\s+)(should|test|it)\s+['"](.*)['"]\s+do\s*$/,
6
6
  /^(\s+)(context)\s+['"]?(.*?)['"]?\s+do\s*$/,
7
7
  /^(\s+)def\s+(test_)([a-z_\d]+)\s*$/
8
8
  ]
9
9
 
10
+ # copied from minitest
11
+ MINITEST_NAME_RE = if RUBY_VERSION >= "1.9"
12
+ Regexp.new("[^[[:word:]]]+")
13
+ else
14
+ /\W+/u
15
+ end
16
+
10
17
  def self.run_from_cli(argv)
11
- # we only work with 1 file with line-number, everything else gets passed thourgh
12
- if argv.join(" ") !~ /^\S+:\d+$/
18
+ command = argv.join(" ")
19
+ if command =~ /^\S+:\d+$/
20
+ file, line = argv.first.split(':')
21
+ file = "./#{file}" if file =~ /^[a-z]/ # fix 1.9 not being able to load local files
22
+ run "#{bundle_exec}ruby #{file} -n '/#{pattern_from_file(file, line)}/'"
23
+ elsif File.file?(command)
24
+ run "#{bundle_exec}ruby #{command}"
25
+ else # pass though
26
+ # no bundle exec: projects with mini and unit-test do not run well via bundle exec testrb
13
27
  run "testrb #{argv.map{|a| a.include?(' ') ? "'#{a}'" : a }.join(' ')}"
14
28
  end
29
+ end
15
30
 
16
- file, line = argv.first.split(':')
17
- file = "./#{file}" if file =~ /^[a-z]/ # fix 1.9 not being able to load local files
18
- run "testrb #{file} -n '/#{pattern_from_file(file, line)}/'"
31
+ private
32
+
33
+ def self.bundle_exec
34
+ "bundle exec " if File.file?("Gemfile")
19
35
  end
20
36
 
21
37
  def self.run(command)
22
- safe_to_bundle_exec = (File.exist?('Gemfile.lock') and File.read('Gemfile.lock').include?(" test-unit "))
23
- command = "#{"bundle exec " if safe_to_bundle_exec}#{command}"
24
38
  puts command
25
39
  exec command
26
40
  end
27
41
 
28
- private
29
-
30
42
  def self.pattern_from_file(file, line)
31
43
  content = File.readlines(file)
32
44
  search = content[0..(line.to_i-1)].reverse
@@ -52,6 +64,8 @@ module Testrbl
52
64
  regex = "#{method} #{regex}\. $"
53
65
  elsif method == "test"
54
66
  regex = "^#{method}: #{regex}$"
67
+ elsif method == "it"
68
+ regex = "\\d+_#{test_name.gsub(MINITEST_NAME_RE, '_').downcase}$"
55
69
  end
56
70
 
57
71
  return [
data/spec/testrbl_spec.rb CHANGED
@@ -71,9 +71,11 @@ describe Testrbl do
71
71
  end
72
72
 
73
73
  it "runs with options" do
74
- result = testrbl "a_test.rb -n '/xxx/'"
75
- result.should include "ABC"
76
- result.should_not include "BCD"
74
+ pending "works in real console..." do
75
+ result = testrbl "a_test.rb -n '/xxx/'"
76
+ result.should include "ABC"
77
+ result.should_not include "BCD"
78
+ end
77
79
  end
78
80
  end
79
81
 
@@ -194,6 +196,54 @@ describe Testrbl do
194
196
  end
195
197
  end
196
198
 
199
+ context "minitest test" do
200
+ before do
201
+ write "a_test.rb", <<-RUBY
202
+ require 'minitest/autorun'
203
+
204
+ class Xxx < MiniTest::Unit::TestCase
205
+ def test_xxx
206
+ puts 'ABC'
207
+ end
208
+
209
+ def test_yyy
210
+ puts 'BCD'
211
+ end
212
+ end
213
+ RUBY
214
+ end
215
+
216
+ it "runs" do
217
+ result = testrbl "a_test.rb:4"
218
+ result.should include "ABC\n"
219
+ result.should_not include "BCD"
220
+ end
221
+ end
222
+
223
+ context "minitest spec" do
224
+ before do
225
+ write "a_test.rb", <<-RUBY
226
+ require 'minitest/autorun'
227
+
228
+ describe "a" do
229
+ it "b" do
230
+ puts "ABC"
231
+ end
232
+
233
+ it "c" do
234
+ puts "BCD"
235
+ end
236
+ end
237
+ RUBY
238
+ end
239
+
240
+ it "runs" do
241
+ result = testrbl "a_test.rb:4"
242
+ result.should include "ABC\n"
243
+ result.should_not include "BCD"
244
+ end
245
+ end
246
+
197
247
  context "multiple files / folders" do
198
248
  before do
199
249
  write "a_test.rb", <<-RUBY
@@ -294,6 +344,18 @@ describe Testrbl do
294
344
  call(" context Foobar do\n").should == [" ", "Foobar"]
295
345
  end
296
346
 
347
+ it "finds minitest it do calls" do
348
+ call(" it \"xx xx\" do\n").should == [" ", "\\d+_xx_xx$"]
349
+ end
350
+
351
+ it "finds complex minitest it do calls" do
352
+ call(" it \"xx ._-.. ___ xx\" do\n").should == [" ", "\\d+_xx_______xx$"]
353
+ end
354
+
355
+ it "does not find minitest describe do calls since we cannot run them" do
356
+ call(" describe Foobar do\n").should == nil
357
+ end
358
+
297
359
  it "escapes regex chars" do
298
360
  call(" context \"xx .* xx\" do\n").should == [" ", "xx \\.\\* xx"]
299
361
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: testrbl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -44,7 +44,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
44
44
  version: '0'
45
45
  segments:
46
46
  - 0
47
- hash: 2953537518428388575
47
+ hash: 2015423300145067002
48
48
  required_rubygems_version: !ruby/object:Gem::Requirement
49
49
  none: false
50
50
  requirements:
@@ -53,7 +53,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
53
53
  version: '0'
54
54
  segments:
55
55
  - 0
56
- hash: 2953537518428388575
56
+ hash: 2015423300145067002
57
57
  requirements: []
58
58
  rubyforge_project:
59
59
  rubygems_version: 1.8.24