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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 6512a4285a824c0bb92db42df4dc797a4df84254
4
- data.tar.gz: 53b3b9c920952bf895f889d937a37d380db6efe4
2
+ SHA256:
3
+ metadata.gz: 49534563e8d2c43647b84e457e1fd35873167eaa70b1687a63217d6005a11c5c
4
+ data.tar.gz: e5bc529fee2b1791547b4dc0f053c7138de70a9477b325d9fd2981eb8c040e40
5
5
  SHA512:
6
- metadata.gz: a7330868c50baf797bcf4c02e0218240281f20f2d5a16ef477f43f1af5c3170035036da6ecca33a6fad9b75b972cceeae71e394f91ba5bffc8da8575d2d2b5dd
7
- data.tar.gz: 10729f1d80db2d57a8bf07ad4acb3f1ce67a71723a5118ae1a5bc9afa53e129ae247d5be5ec726a2cd4527bc72ac59ed7f19f1dc2ca079beef601f3beba4ec07
6
+ metadata.gz: d1222308ab263f3098cdad5f0a99bf5abddecc6b61a7b5cb2a80066fefa1541ac88fbe1a722aa0e5182fea897df2ad6ad50a3afe20f91326a455de220e9fdb12
7
+ data.tar.gz: b5f502bcb6064306ffe14d6d9b58dd01a4e1f5c214720de65cec275047e1f60d8366c5beeb656bd71ecd172493a9924a3ae69e154340f1236d44aa147b5f31a3
@@ -1,8 +1,12 @@
1
- before_script:
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.0
8
-
9
+ - 2.1.8
10
+ - 2.2.3
11
+ branches:
12
+ only: master
@@ -1,13 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- testrbl (0.5.2)
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.3.3)
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
@@ -2,175 +2,189 @@ require 'testrbl/version'
2
2
 
3
3
  module Testrbl
4
4
  PATTERNS = [
5
- /^(\s+)(should|test|it)\s+['"](.*)['"]\s+do\s*(?:#.*)?$/,
6
- /^(\s+)(context|describe)\s+['"]?(.*?)['"]?\s+do\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
- def self.run_from_cli(argv)
14
- files, options = partition_argv(argv)
15
- files.concat(changed_files) if options.delete("--changed")
16
- files = files.map { |f| localize(f) }
17
- load_options, options = partition_options(options)
18
-
19
- if files.size == 1 and files.first =~ /^(\S+):(\d+)$/
20
- file = $1
21
- line = $2
22
- run(ruby + load_options + line_pattern_option(file, line) + options)
23
- else
24
- if files.size == 1 and File.file?(files.first)
25
- run(ruby + load_options + files + options)
26
- elsif options.none? { |arg| arg =~ /^-n/ }
27
- seed = if seed = options.index("--seed")
28
- ["--"] + options.slice!(seed, 2)
29
- else
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
- # overwritten by maxitest to just return line
42
- def self.line_pattern_option(file, line)
43
- [file, "-n", "/#{pattern_from_file(File.readlines(file), line)}/"]
44
- end
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
- # usable via external tools like zeus
47
- def self.pattern_from_file(lines, line)
48
- possible_lines = lines[0..(line.to_i-1)].reverse
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
- found = possible_lines.map { |line| test_pattern_from_line(line) || block_start_from_line(line) }.compact
51
+ found = possible_lines.map { |line| test_pattern_from_line(line) || block_start_from_line(line) }.compact
51
52
 
52
- # pattern and the groups it is nested under (like describe - describe - it)
53
- last_spaces = " " * 100
54
- patterns = found.select do |spaces, name|
55
- last_spaces = spaces if spaces.size < last_spaces.size
56
- end.map(&:last).compact
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
- return filter_duplicate_final(patterns).reverse.join(".*") if found.size > 0
59
+ return filter_duplicate_final(patterns).reverse.join(".*") if found.size > 0
59
60
 
60
- raise "no test found before line #{line}"
61
- end
61
+ raise "no test found before line #{line}"
62
+ end
62
63
 
63
- # only keep 1 pattern that stops matching via $
64
- def self.filter_duplicate_final(patterns)
65
- found_final = 0
66
- patterns.reject { |p| p.end_with?("$") and (found_final += 1) > 1 }
67
- end
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
- private
70
+ private
70
71
 
71
- def self.all_test_files_in(folder)
72
- Dir[File.join(folder, "{**/,}*_{test,spec}.rb")].uniq
73
- end
72
+ def all_test_files_in(folder)
73
+ Dir[File.join(folder, "{**/,}*_{test,spec}.rb")].uniq
74
+ end
74
75
 
75
- def self.partition_options(options)
76
- next_is_before = false
77
- options.partition do |option|
78
- if next_is_before
79
- next_is_before = false
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
- false
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
- # fix 1.9 not being able to load local files
93
- def self.localize(file)
94
- file =~ /^[-a-z\d_]/ ? "./#{file}" : file
95
- end
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
- def self.partition_argv(argv)
98
- next_is_option = false
99
- argv.partition do |arg|
100
- if next_is_option
101
- next_is_option = false
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
- true
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
- def self.changed_files
116
- changed_files = `git status -s`.split("\n").map { |l| l.strip.split(/\s+/, 2)[1] }
117
- raise "Failed: #{changed_files}" unless $?.success?
118
- changed_files.select { |f| f =~ /_(test|spec)\.rb$/ && File.exist?(f) }
119
- end
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
- def self.ruby
122
- if File.file?("Gemfile")
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
- def self.run(command)
130
- puts command.join(" ")
131
- STDOUT.flush # if exec fails horribly we at least see some output
132
- Kernel.exec *command
133
- end
128
+ def sh(command)
129
+ result = `#{command}`
130
+ raise "Failed: #{command} -> #{result}" unless $?.success?
131
+ result
132
+ end
134
133
 
135
- def self.block_start_from_line(line)
136
- if line =~ /^(\s*).* do( \|.*\|)?$/
137
- [$1, nil]
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
- def self.test_pattern_from_line(line)
142
- PATTERNS.each do |r|
143
- next unless line =~ r
144
- whitespace, method, test_name = $1, $2, $3
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
- def self.test_pattern_from_match(method, test_name)
151
- regex = Regexp.escape(test_name).gsub("\\ "," ").gsub(INTERPOLATION, ".*")
152
-
153
- regex = if method == "test"
154
- # test "xxx -_ yyy"
155
- # test-unit: "test: xxx -_ yyy"
156
- # activesupport: "test_xxx_-__yyy"
157
- "^test(: |_)#{regex.gsub(" ", ".")}$"
158
- elsif method == "describe" || (method == "context" && !via_shoulda?)
159
- "#{test_name}(::)?"
160
- elsif method == "should" && via_shoulda?
161
- optional_test_name = "(?:\(.*\))?"
162
- "#{method} #{regex}\. #{optional_test_name}$"
163
- elsif ["it", "should"].include?(method) # minitest aliases for shoulda
164
- "#test_\\d+_#{test_name}$"
165
- else
166
- regex
167
- end
168
-
169
- regex.gsub("'", ".")
170
- end
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
- def self.via_shoulda?
173
- return @via_shoulda if defined?(@via_shoulda)
174
- @via_shoulda = !File.exist?("Gemfile.lock") || File.read("Gemfile.lock").include?(" shoulda-context ")
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
@@ -1,3 +1,3 @@
1
1
  module Testrbl
2
- VERSION = '0.5.2'
2
+ VERSION = '0.9.0'
3
3
  end
@@ -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(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
- it "finds minitest it do calls" do
607
- call(" it \"xx xx\" do\n").should == [" ", "#test_\\d+_xx xx$"]
608
- end
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
- it "finds complex minitest it do calls" do
611
- call(" it \"xX ._-.. ___ Xx\" do\n").should == [" ", "#test_\\d+_xX ._-.. ___ Xx$"]
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.5.2
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: 2015-03-06 00:00:00.000000000 Z
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
- rubyforge_project:
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