testrbl 0.5.2 → 0.9.0
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.
- checksums.yaml +5 -5
- data/.travis.yml +7 -3
- data/Gemfile.lock +5 -2
- data/Readme.md +1 -1
- data/lib/testrbl.rb +146 -132
- data/lib/testrbl/version.rb +1 -1
- data/spec/testrbl_spec.rb +41 -6
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 49534563e8d2c43647b84e457e1fd35873167eaa70b1687a63217d6005a11c5c
|
4
|
+
data.tar.gz: e5bc529fee2b1791547b4dc0f053c7138de70a9477b325d9fd2981eb8c040e40
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1222308ab263f3098cdad5f0a99bf5abddecc6b61a7b5cb2a80066fefa1541ac88fbe1a722aa0e5182fea897df2ad6ad50a3afe20f91326a455de220e9fdb12
|
7
|
+
data.tar.gz: b5f502bcb6064306ffe14d6d9b58dd01a4e1f5c214720de65cec275047e1f60d8366c5beeb656bd71ecd172493a9924a3ae69e154340f1236d44aa147b5f31a3
|
data/.travis.yml
CHANGED
@@ -1,8 +1,12 @@
|
|
1
|
-
|
1
|
+
sudo: false
|
2
|
+
before_install:
|
2
3
|
- git config --global user.email "you@example.com"
|
3
4
|
- git config --global user.name "Your Name"
|
5
|
+
- gem install bundler
|
4
6
|
rvm:
|
5
7
|
- 1.9.3
|
6
8
|
- 2.0.0
|
7
|
-
- 2.1.
|
8
|
-
|
9
|
+
- 2.1.8
|
10
|
+
- 2.2.3
|
11
|
+
branches:
|
12
|
+
only: master
|
data/Gemfile.lock
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
testrbl (0.
|
4
|
+
testrbl (0.9.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
9
|
activesupport (2.3.14)
|
10
|
-
bump (0.
|
10
|
+
bump (0.5.2)
|
11
11
|
diff-lcs (1.1.3)
|
12
12
|
minitest (5.0.3)
|
13
13
|
rake (0.9.2.2)
|
@@ -38,3 +38,6 @@ DEPENDENCIES
|
|
38
38
|
shoulda
|
39
39
|
test-unit
|
40
40
|
testrbl!
|
41
|
+
|
42
|
+
BUNDLED WITH
|
43
|
+
2.1.4
|
data/Readme.md
CHANGED
@@ -20,7 +20,7 @@ Usage
|
|
20
20
|
testrbl test/unit/xxx_test.rb:123 # test by line number
|
21
21
|
testrbl test/unit # everything _test.rb in a folder (on 1.8 this would be test/unit/*)
|
22
22
|
testrbl xxx_test.rb yyy_test.rb # multiple files
|
23
|
-
testrbl --changed # run changed tests
|
23
|
+
testrbl --changed # run changed tests or files in last commit
|
24
24
|
```
|
25
25
|
|
26
26
|
Tips
|
data/lib/testrbl.rb
CHANGED
@@ -2,175 +2,189 @@ require 'testrbl/version'
|
|
2
2
|
|
3
3
|
module Testrbl
|
4
4
|
PATTERNS = [
|
5
|
-
/^(\s+)(should|test|it)\s
|
6
|
-
/^(\s+)(context|describe)\s
|
7
|
-
/^(\s+)def\s+(test_)([a-z_\d]+)\s*(?:#.*)?$/
|
5
|
+
/^(\s+)(should|test|it)(\s+|\s*\(\s*)['"](.*)['"](\s*\))?\s+do\s*(?:#.*)?$/,
|
6
|
+
/^(\s+)(context|describe)(\s+|\s*\(\s*)['"]?(.*?)['"]?(\s*\))?\s+do\s*(?:#.*)?$/,
|
7
|
+
/^(\s+)def(\s+)(test_)([a-z_\d]+)\s*(?:#.*)?$/
|
8
8
|
]
|
9
9
|
|
10
|
-
OPTION_WITH_ARGUMENT = ["-I", "-r", "-n", "-e", "--seed"]
|
10
|
+
OPTION_WITH_ARGUMENT = ["-I", "-r", "-n", "--name", "-e", "--exclude", "-s", "--seed"]
|
11
11
|
INTERPOLATION = /\\\#\\\{.*?\\\}/
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
13
|
+
class << self
|
14
|
+
def run_from_cli(argv)
|
15
|
+
files, options = partition_argv(argv)
|
16
|
+
files.concat(changed_files) if options.delete("--changed")
|
17
|
+
files = files.map { |f| localize(f) }
|
18
|
+
load_options, options = partition_options(options)
|
19
|
+
|
20
|
+
if files.size == 1 and files.first =~ /^(\S+):(\d+)$/
|
21
|
+
file = $1
|
22
|
+
line = $2
|
23
|
+
run(ruby + load_options + line_pattern_option(file, line) + options)
|
24
|
+
else
|
25
|
+
if files.size == 1 and File.file?(files.first)
|
26
|
+
run(ruby + load_options + files + options)
|
27
|
+
elsif options.none? { |arg| arg =~ /^-n/ }
|
28
|
+
seed = if seed = options.index("--seed")
|
29
|
+
["--"] + options.slice!(seed, 2)
|
30
|
+
else
|
31
|
+
[]
|
32
|
+
end
|
33
|
+
files = files.map { |f| File.directory?(f) ? all_test_files_in(f) : f }.flatten
|
34
|
+
run(ruby + load_options + files.map { |f| "-r#{f}" } + options + ["-e", ""] + seed)
|
35
|
+
else # pass though
|
36
|
+
# no bundle exec: projects with mini and unit-test do not run well via bundle exec testrb
|
37
|
+
run ["testrb"] + argv
|
31
38
|
end
|
32
|
-
files = files.map { |f| File.directory?(f) ? all_test_files_in(f) : f }.flatten
|
33
|
-
run(ruby + load_options + files.map { |f| "-r#{f}" } + options + ["-e", ""] + seed)
|
34
|
-
else # pass though
|
35
|
-
# no bundle exec: projects with mini and unit-test do not run well via bundle exec testrb
|
36
|
-
run ["testrb"] + argv
|
37
39
|
end
|
38
40
|
end
|
39
|
-
end
|
40
41
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
42
|
+
# overwritten by maxitest to just return line
|
43
|
+
def line_pattern_option(file, line)
|
44
|
+
[file, "-n", "/#{pattern_from_file(File.readlines(file), line)}/"]
|
45
|
+
end
|
45
46
|
|
46
|
-
|
47
|
-
|
48
|
-
|
47
|
+
# usable via external tools like zeus
|
48
|
+
def pattern_from_file(lines, line)
|
49
|
+
possible_lines = lines[0..(line.to_i-1)].reverse
|
49
50
|
|
50
|
-
|
51
|
+
found = possible_lines.map { |line| test_pattern_from_line(line) || block_start_from_line(line) }.compact
|
51
52
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
53
|
+
# pattern and the groups it is nested under (like describe - describe - it)
|
54
|
+
last_spaces = " " * 100
|
55
|
+
patterns = found.select do |spaces, name|
|
56
|
+
last_spaces = spaces if spaces.size < last_spaces.size
|
57
|
+
end.map(&:last).compact
|
57
58
|
|
58
|
-
|
59
|
+
return filter_duplicate_final(patterns).reverse.join(".*") if found.size > 0
|
59
60
|
|
60
|
-
|
61
|
-
|
61
|
+
raise "no test found before line #{line}"
|
62
|
+
end
|
62
63
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
64
|
+
# only keep 1 pattern that stops matching via $
|
65
|
+
def filter_duplicate_final(patterns)
|
66
|
+
found_final = 0
|
67
|
+
patterns.reject { |p| p.end_with?("$") and (found_final += 1) > 1 }
|
68
|
+
end
|
68
69
|
|
69
|
-
|
70
|
+
private
|
70
71
|
|
71
|
-
|
72
|
-
|
73
|
-
|
72
|
+
def all_test_files_in(folder)
|
73
|
+
Dir[File.join(folder, "{**/,}*_{test,spec}.rb")].uniq
|
74
|
+
end
|
74
75
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
true
|
81
|
-
else
|
82
|
-
if option =~ /^-(r|I)/
|
83
|
-
next_is_before = (option.size == 2)
|
76
|
+
def partition_options(options)
|
77
|
+
next_is_before = false
|
78
|
+
options.partition do |option|
|
79
|
+
if next_is_before
|
80
|
+
next_is_before = false
|
84
81
|
true
|
85
82
|
else
|
86
|
-
|
83
|
+
if option =~ /^-(r|I)/
|
84
|
+
next_is_before = (option.size == 2)
|
85
|
+
true
|
86
|
+
else
|
87
|
+
false
|
88
|
+
end
|
87
89
|
end
|
88
90
|
end
|
89
91
|
end
|
90
|
-
end
|
91
92
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
93
|
+
# fix 1.9 not being able to load local files
|
94
|
+
def localize(file)
|
95
|
+
file =~ /^[-a-z\d_]/ ? "./#{file}" : file
|
96
|
+
end
|
96
97
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
else
|
103
|
-
if arg =~ /^-.$/ or arg =~ /^--/ # single letter option followed by argument like -I test or long options like --verbose
|
104
|
-
next_is_option = true if OPTION_WITH_ARGUMENT.include?(arg)
|
105
|
-
false
|
106
|
-
elsif arg =~ /^-/ # multi letter option like -Itest
|
107
|
-
false
|
98
|
+
def partition_argv(argv)
|
99
|
+
next_is_option = false
|
100
|
+
argv.partition do |arg|
|
101
|
+
if next_is_option
|
102
|
+
next_is_option = false
|
108
103
|
else
|
109
|
-
|
104
|
+
if arg =~ /^-.$/ or arg =~ /^--/ # single letter option followed by argument like -I test or long options like --verbose
|
105
|
+
next_is_option = true if OPTION_WITH_ARGUMENT.include?(arg)
|
106
|
+
false
|
107
|
+
elsif arg =~ /^-/ # multi letter option like -Itest
|
108
|
+
false
|
109
|
+
else
|
110
|
+
true
|
111
|
+
end
|
110
112
|
end
|
111
113
|
end
|
112
114
|
end
|
113
|
-
end
|
114
115
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
116
|
+
def changed_files
|
117
|
+
changed_files = sh("git status -s").split("\n").map { |l| l.strip.split(/\s+/, 2)[1] }
|
118
|
+
|
119
|
+
if changed_files.empty?
|
120
|
+
# user wants to test last commit and not current diff
|
121
|
+
changed_files = sh("git show --name-only").split("\n\n").last.split("\n")
|
122
|
+
end
|
120
123
|
|
121
|
-
|
122
|
-
|
123
|
-
["ruby", "-rbundler/setup"] # faster then bundle exec ruby
|
124
|
-
else
|
125
|
-
["ruby"]
|
124
|
+
# we only want test files that were added or changed (not deleted)
|
125
|
+
changed_files.select { |f| f =~ /_(test|spec)\.rb$/ && File.exist?(f) }
|
126
126
|
end
|
127
|
-
end
|
128
127
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
128
|
+
def sh(command)
|
129
|
+
result = `#{command}`
|
130
|
+
raise "Failed: #{command} -> #{result}" unless $?.success?
|
131
|
+
result
|
132
|
+
end
|
134
133
|
|
135
|
-
|
136
|
-
|
137
|
-
|
134
|
+
def ruby
|
135
|
+
if File.file?("Gemfile")
|
136
|
+
["ruby", "-rbundler/setup"] # faster then bundle exec ruby
|
137
|
+
else
|
138
|
+
["ruby"]
|
139
|
+
end
|
138
140
|
end
|
139
|
-
end
|
140
141
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
return [whitespace, test_pattern_from_match(method, test_name)]
|
142
|
+
def run(command)
|
143
|
+
puts command.join(" ")
|
144
|
+
STDOUT.flush # if exec fails horribly we at least see some output
|
145
|
+
Kernel.exec *command
|
146
146
|
end
|
147
|
-
nil
|
148
|
-
end
|
149
147
|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
regex
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
148
|
+
def block_start_from_line(line)
|
149
|
+
if line =~ /^(\s*).* do( \|.*\|)?$/
|
150
|
+
[$1, nil]
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_pattern_from_line(line)
|
155
|
+
PATTERNS.each do |r|
|
156
|
+
next unless line =~ r
|
157
|
+
whitespace, method, test_name = $1, $2, $4
|
158
|
+
return [whitespace, test_pattern_from_match(method, test_name)]
|
159
|
+
end
|
160
|
+
nil
|
161
|
+
end
|
162
|
+
|
163
|
+
def test_pattern_from_match(method, test_name)
|
164
|
+
regex = Regexp.escape(test_name).gsub("\\ "," ").gsub(INTERPOLATION, ".*")
|
165
|
+
|
166
|
+
regex = if method == "test"
|
167
|
+
# test "xxx -_ yyy"
|
168
|
+
# test-unit: "test: xxx -_ yyy"
|
169
|
+
# activesupport: "test_xxx_-__yyy"
|
170
|
+
"^test(: |_)#{regex.gsub(" ", ".")}$"
|
171
|
+
elsif method == "describe" || (method == "context" && !via_shoulda?)
|
172
|
+
"#{regex}(::)?"
|
173
|
+
elsif method == "should" && via_shoulda?
|
174
|
+
optional_test_name = "(?:\(.*\))?"
|
175
|
+
"#{method} #{regex}\. #{optional_test_name}$"
|
176
|
+
elsif ["it", "should"].include?(method) # minitest aliases for shoulda
|
177
|
+
"#test_\\d+_#{regex}$"
|
178
|
+
else
|
179
|
+
regex
|
180
|
+
end
|
171
181
|
|
172
|
-
|
173
|
-
|
174
|
-
|
182
|
+
regex.gsub("'", ".")
|
183
|
+
end
|
184
|
+
|
185
|
+
def via_shoulda?
|
186
|
+
return @via_shoulda if defined?(@via_shoulda)
|
187
|
+
@via_shoulda = !File.exist?("Gemfile.lock") || File.read("Gemfile.lock").include?(" shoulda-context ")
|
188
|
+
end
|
175
189
|
end
|
176
190
|
end
|
data/lib/testrbl/version.rb
CHANGED
data/spec/testrbl_spec.rb
CHANGED
@@ -89,6 +89,11 @@ describe Testrbl do
|
|
89
89
|
result.should include "1234"
|
90
90
|
end
|
91
91
|
|
92
|
+
it "seeds with -s" do
|
93
|
+
result = testrbl "0_test.rb:6 -s 1234"
|
94
|
+
result.should include "1234"
|
95
|
+
end
|
96
|
+
|
92
97
|
it "seeds multiple files" do
|
93
98
|
result = Bundler.with_clean_env { testrbl "0_test.rb 1_test.rb --seed 1234" } # adding --seed triggers minitest to be loaded in a weird way and then the second version is loaded via bundler :/
|
94
99
|
result.should include "1234"
|
@@ -341,6 +346,16 @@ describe Testrbl do
|
|
341
346
|
it "b./_-d" do
|
342
347
|
puts "-EFG-"
|
343
348
|
end
|
349
|
+
|
350
|
+
it("f-g") do
|
351
|
+
puts "-HIJ-"
|
352
|
+
end
|
353
|
+
end
|
354
|
+
|
355
|
+
describe("h-j") do
|
356
|
+
it "i-k" do
|
357
|
+
puts "-KLM-"
|
358
|
+
end
|
344
359
|
end
|
345
360
|
RUBY
|
346
361
|
end
|
@@ -365,6 +380,14 @@ describe Testrbl do
|
|
365
380
|
it "runs nested it" do
|
366
381
|
run_line("13").should == ["CDE"]
|
367
382
|
end
|
383
|
+
|
384
|
+
it "runs it with parens" do
|
385
|
+
run_line("28").should == ["HIJ"]
|
386
|
+
end
|
387
|
+
|
388
|
+
it "runs describe with parens" do
|
389
|
+
run_line("33").should == ["KLM"]
|
390
|
+
end
|
368
391
|
end
|
369
392
|
|
370
393
|
context "multiple files / folders" do
|
@@ -515,6 +538,12 @@ describe Testrbl do
|
|
515
538
|
result.should include "DEF"
|
516
539
|
result.should_not include "ABC"
|
517
540
|
end
|
541
|
+
|
542
|
+
it "runs last commit when no files are changed" do
|
543
|
+
result = testrbl("--changed")
|
544
|
+
result.should include "ABC"
|
545
|
+
result.should include "BCD"
|
546
|
+
end
|
518
547
|
end
|
519
548
|
|
520
549
|
describe ".test_pattern_from_file" do
|
@@ -552,7 +581,7 @@ describe Testrbl do
|
|
552
581
|
|
553
582
|
describe ".test_pattern_from_line" do
|
554
583
|
def call(line)
|
555
|
-
Testrbl.test_pattern_from_line
|
584
|
+
Testrbl.send(:test_pattern_from_line, line)
|
556
585
|
end
|
557
586
|
|
558
587
|
it "finds simple tests" do
|
@@ -603,12 +632,18 @@ describe Testrbl do
|
|
603
632
|
call(" context \"c\#{111}b\" do\n").should == [" ", "c.*b"]
|
604
633
|
end
|
605
634
|
|
606
|
-
|
607
|
-
|
608
|
-
|
635
|
+
describe "minitest id do" do
|
636
|
+
it "finds simple" do
|
637
|
+
call(" it \"xx xx\" do\n").should == [" ", "#test_\\d+_xx xx$"]
|
638
|
+
end
|
609
639
|
|
610
|
-
|
611
|
-
|
640
|
+
it "finds complex" do
|
641
|
+
call(" it \"xX ._-.. ___ Xx\" do\n").should == [" ", "#test_\\d+_xX \\._\\-\\.\\. ___ Xx$"]
|
642
|
+
end
|
643
|
+
|
644
|
+
it "finds with special characters" do
|
645
|
+
call(" it \"hmm? it's weird\\\"?\" do\n").should == [" ", "#test_\\d+_hmm\\? it.s weird\\\\\"\\?$"]
|
646
|
+
end
|
612
647
|
end
|
613
648
|
|
614
649
|
it "finds minitest describe do calls" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: testrbl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Grosser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email: michael@grosser.it
|
@@ -47,8 +47,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
47
47
|
- !ruby/object:Gem::Version
|
48
48
|
version: '0'
|
49
49
|
requirements: []
|
50
|
-
|
51
|
-
rubygems_version: 2.2.2
|
50
|
+
rubygems_version: 3.1.3
|
52
51
|
signing_key:
|
53
52
|
specification_version: 4
|
54
53
|
summary: Run ruby Test::Unit/Shoulda tests by line-number / folder / the dozen
|