maxitest 1.5.3 → 1.5.4

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
2
  SHA1:
3
- metadata.gz: 762f7f18cf39bd8543ca82c2285fbbddc581413d
4
- data.tar.gz: 16220c358d60e86e53c69042c3b2688ae1a2c0e0
3
+ metadata.gz: 7db9e9766430fc0c6600b33feed4c231238b6b9d
4
+ data.tar.gz: 0b4915abe95300cb7d2c1406e742cd0393130565
5
5
  SHA512:
6
- metadata.gz: e739f73c1e4c97fa9161d43f43475a63b1bd467358fe7f5b3a96cf901da2f1ad9bc3f46c3757271c3f6f34356f00bc9dcdb4b66e99f0eef803323004b14d3dab
7
- data.tar.gz: c93a3b274ac3c0ae61f291699cff90b4aa4cf2ec48e1ef4b38608cd01d66d5ba79a805d2a2b0c8ba61cf6addff4f7860dc5cafbda61632d8f26d569885eef2ae
6
+ metadata.gz: 8b25f64c7b30d48c4f2e95b6dfc6f1fd1d0c3310330c8ed83bb03ceee8ae970dc7cf092d6e7b49bdfb8ac47a9b5c05403587340149b27140a96c5ac90993ece4
7
+ data.tar.gz: e0c6750d5f66a53d5e28b25beae1659418e19a502ccd39b6d8e0dabe1a5e9198328703c127d09adc9bcaf90c792ee3781300c0a01a801fd5798eabf0bcbb3ddc
@@ -1,11 +1,17 @@
1
1
  module Maxitest
2
2
  module Pending
3
3
  def pending(reason=nil)
4
- yield
5
- rescue Minitest::Assertion
6
- skip reason
7
- else
8
- raise "Fixed"
4
+ if block_given?
5
+ begin
6
+ yield
7
+ rescue StandardError, Minitest::Assertion
8
+ skip reason
9
+ else
10
+ raise "Fixed"
11
+ end
12
+ else
13
+ raise ArgumentError, "Need a block to execute"
14
+ end
9
15
  end
10
16
  end
11
17
  end
@@ -13,168 +13,170 @@ module Maxitest
13
13
  OPTION_WITH_ARGUMENT = ["-I", "-r", "-n", "-e", "--seed"]
14
14
  INTERPOLATION = /\\\#\\\{.*?\\\}/
15
15
 
16
- def self.run_from_cli(argv)
17
- files, options = partition_argv(argv)
18
- files.concat(changed_files) if options.delete("--changed")
19
- files = files.map { |f| localize(f) }
20
- load_options, options = partition_options(options)
21
-
22
- if files.size == 1 and files.first =~ /^(\S+):(\d+)$/
23
- file = $1
24
- line = $2
25
- run(ruby + load_options + line_pattern_option(file, line) + options)
26
- else
27
- if files.size == 1 and File.file?(files.first)
28
- run(ruby + load_options + files + options)
29
- elsif options.none? { |arg| arg =~ /^-n/ }
30
- seed = if seed = options.index("--seed")
31
- ["--"] + options.slice!(seed, 2)
32
- else
33
- []
16
+ class << self
17
+ def run_from_cli(argv)
18
+ files, options = partition_argv(argv)
19
+ files.concat(changed_files) if options.delete("--changed")
20
+ files = files.map { |f| localize(f) }
21
+ load_options, options = partition_options(options)
22
+
23
+ if files.size == 1 and files.first =~ /^(\S+):(\d+)$/
24
+ file = $1
25
+ line = $2
26
+ run(ruby + load_options + line_pattern_option(file, line) + options)
27
+ else
28
+ if files.size == 1 and File.file?(files.first)
29
+ run(ruby + load_options + files + options)
30
+ elsif options.none? { |arg| arg =~ /^-n/ }
31
+ seed = if seed = options.index("--seed")
32
+ ["--"] + options.slice!(seed, 2)
33
+ else
34
+ []
35
+ end
36
+ files = files.map { |f| File.directory?(f) ? all_test_files_in(f) : f }.flatten
37
+ run(ruby + load_options + files.map { |f| "-r#{f}" } + options + ["-e", ""] + seed)
38
+ else # pass though
39
+ # no bundle exec: projects with mini and unit-test do not run well via bundle exec testrb
40
+ run ["testrb"] + argv
34
41
  end
35
- files = files.map { |f| File.directory?(f) ? all_test_files_in(f) : f }.flatten
36
- run(ruby + load_options + files.map { |f| "-r#{f}" } + options + ["-e", ""] + seed)
37
- else # pass though
38
- # no bundle exec: projects with mini and unit-test do not run well via bundle exec testrb
39
- run ["testrb"] + argv
40
42
  end
41
43
  end
42
- end
43
44
 
44
- # overwritten by maxitest to just return line
45
- def self.line_pattern_option(file, line)
46
- [file, "-n", "/#{pattern_from_file(File.readlines(file), line)}/"]
47
- end
45
+ # overwritten by maxitest to just return line
46
+ def line_pattern_option(file, line)
47
+ [file, "-n", "/#{pattern_from_file(File.readlines(file), line)}/"]
48
+ end
48
49
 
49
- # usable via external tools like zeus
50
- def self.pattern_from_file(lines, line)
51
- possible_lines = lines[0..(line.to_i-1)].reverse
50
+ # usable via external tools like zeus
51
+ def pattern_from_file(lines, line)
52
+ possible_lines = lines[0..(line.to_i-1)].reverse
52
53
 
53
- found = possible_lines.map { |line| test_pattern_from_line(line) || block_start_from_line(line) }.compact
54
+ found = possible_lines.map { |line| test_pattern_from_line(line) || block_start_from_line(line) }.compact
54
55
 
55
- # pattern and the groups it is nested under (like describe - describe - it)
56
- last_spaces = " " * 100
57
- patterns = found.select do |spaces, name|
58
- last_spaces = spaces if spaces.size < last_spaces.size
59
- end.map(&:last).compact
56
+ # pattern and the groups it is nested under (like describe - describe - it)
57
+ last_spaces = " " * 100
58
+ patterns = found.select do |spaces, name|
59
+ last_spaces = spaces if spaces.size < last_spaces.size
60
+ end.map(&:last).compact
60
61
 
61
- return filter_duplicate_final(patterns).reverse.join(".*") if found.size > 0
62
+ return filter_duplicate_final(patterns).reverse.join(".*") if found.size > 0
62
63
 
63
- raise "no test found before line #{line}"
64
- end
64
+ raise "no test found before line #{line}"
65
+ end
65
66
 
66
- # only keep 1 pattern that stops matching via $
67
- def self.filter_duplicate_final(patterns)
68
- found_final = 0
69
- patterns.reject { |p| p.end_with?("$") and (found_final += 1) > 1 }
70
- end
67
+ # only keep 1 pattern that stops matching via $
68
+ def filter_duplicate_final(patterns)
69
+ found_final = 0
70
+ patterns.reject { |p| p.end_with?("$") and (found_final += 1) > 1 }
71
+ end
71
72
 
72
- private
73
+ private
73
74
 
74
- def self.all_test_files_in(folder)
75
- Dir[File.join(folder, "{**/,}*_{test,spec}.rb")].uniq
76
- end
75
+ def all_test_files_in(folder)
76
+ Dir[File.join(folder, "{**/,}*_{test,spec}.rb")].uniq
77
+ end
77
78
 
78
- def self.partition_options(options)
79
- next_is_before = false
80
- options.partition do |option|
81
- if next_is_before
82
- next_is_before = false
83
- true
84
- else
85
- if option =~ /^-(r|I)/
86
- next_is_before = (option.size == 2)
79
+ def partition_options(options)
80
+ next_is_before = false
81
+ options.partition do |option|
82
+ if next_is_before
83
+ next_is_before = false
87
84
  true
88
85
  else
89
- false
86
+ if option =~ /^-(r|I)/
87
+ next_is_before = (option.size == 2)
88
+ true
89
+ else
90
+ false
91
+ end
90
92
  end
91
93
  end
92
94
  end
93
- end
94
95
 
95
- # fix 1.9 not being able to load local files
96
- def self.localize(file)
97
- file =~ /^[-a-z\d_]/ ? "./#{file}" : file
98
- end
96
+ # fix 1.9 not being able to load local files
97
+ def localize(file)
98
+ file =~ /^[-a-z\d_]/ ? "./#{file}" : file
99
+ end
99
100
 
100
- def self.partition_argv(argv)
101
- next_is_option = false
102
- argv.partition do |arg|
103
- if next_is_option
104
- next_is_option = false
105
- else
106
- if arg =~ /^-.$/ or arg =~ /^--/ # single letter option followed by argument like -I test or long options like --verbose
107
- next_is_option = true if OPTION_WITH_ARGUMENT.include?(arg)
108
- false
109
- elsif arg =~ /^-/ # multi letter option like -Itest
110
- false
101
+ def partition_argv(argv)
102
+ next_is_option = false
103
+ argv.partition do |arg|
104
+ if next_is_option
105
+ next_is_option = false
111
106
  else
112
- true
107
+ if arg =~ /^-.$/ or arg =~ /^--/ # single letter option followed by argument like -I test or long options like --verbose
108
+ next_is_option = true if OPTION_WITH_ARGUMENT.include?(arg)
109
+ false
110
+ elsif arg =~ /^-/ # multi letter option like -Itest
111
+ false
112
+ else
113
+ true
114
+ end
113
115
  end
114
116
  end
115
117
  end
116
- end
117
118
 
118
- def self.changed_files
119
- changed_files = `git status -s`.split("\n").map { |l| l.strip.split(/\s+/, 2)[1] }
120
- raise "Failed: #{changed_files}" unless $?.success?
121
- changed_files.select { |f| f =~ /_(test|spec)\.rb$/ && File.exist?(f) }
122
- end
123
-
124
- def self.ruby
125
- if File.file?("Gemfile")
126
- ["ruby", "-rbundler/setup"] # faster then bundle exec ruby
127
- else
128
- ["ruby"]
119
+ def changed_files
120
+ changed_files = `git status -s`.split("\n").map { |l| l.strip.split(/\s+/, 2)[1] }
121
+ raise "Failed: #{changed_files}" unless $?.success?
122
+ changed_files.select { |f| f =~ /_(test|spec)\.rb$/ && File.exist?(f) }
129
123
  end
130
- end
131
124
 
132
- def self.run(command)
133
- puts command.join(" ")
134
- STDOUT.flush # if exec fails horribly we at least see some output
135
- Kernel.exec *command
136
- end
125
+ def ruby
126
+ if File.file?("Gemfile")
127
+ ["ruby", "-rbundler/setup"] # faster then bundle exec ruby
128
+ else
129
+ ["ruby"]
130
+ end
131
+ end
137
132
 
138
- def self.block_start_from_line(line)
139
- if line =~ /^(\s*).* do( \|.*\|)?$/
140
- [$1, nil]
133
+ def run(command)
134
+ puts command.join(" ")
135
+ STDOUT.flush # if exec fails horribly we at least see some output
136
+ Kernel.exec *command
141
137
  end
142
- end
143
138
 
144
- def self.test_pattern_from_line(line)
145
- PATTERNS.each do |r|
146
- next unless line =~ r
147
- whitespace, method, test_name = $1, $2, $3
148
- return [whitespace, test_pattern_from_match(method, test_name)]
139
+ def block_start_from_line(line)
140
+ if line =~ /^(\s*).* do( \|.*\|)?$/
141
+ [$1, nil]
142
+ end
149
143
  end
150
- nil
151
- end
152
144
 
153
- def self.test_pattern_from_match(method, test_name)
154
- regex = Regexp.escape(test_name).gsub("\\ "," ").gsub(INTERPOLATION, ".*")
155
-
156
- regex = if method == "test"
157
- # test "xxx -_ yyy"
158
- # test-unit: "test: xxx -_ yyy"
159
- # activesupport: "test_xxx_-__yyy"
160
- "^test(: |_)#{regex.gsub(" ", ".")}$"
161
- elsif method == "describe" || (method == "context" && !via_shoulda?)
162
- "#{test_name}(::)?"
163
- elsif method == "should" && via_shoulda?
164
- optional_test_name = "(?:\(.*\))?"
165
- "#{method} #{regex}\. #{optional_test_name}$"
166
- elsif ["it", "should"].include?(method) # minitest aliases for shoulda
167
- "#test_\\d+_#{test_name}$"
168
- else
169
- regex
145
+ def test_pattern_from_line(line)
146
+ PATTERNS.each do |r|
147
+ next unless line =~ r
148
+ whitespace, method, test_name = $1, $2, $3
149
+ return [whitespace, test_pattern_from_match(method, test_name)]
150
+ end
151
+ nil
170
152
  end
171
153
 
172
- regex.gsub("'", ".")
173
- end
154
+ def test_pattern_from_match(method, test_name)
155
+ regex = Regexp.escape(test_name).gsub("\\ "," ").gsub(INTERPOLATION, ".*")
156
+
157
+ regex = if method == "test"
158
+ # test "xxx -_ yyy"
159
+ # test-unit: "test: xxx -_ yyy"
160
+ # activesupport: "test_xxx_-__yyy"
161
+ "^test(: |_)#{regex.gsub(" ", ".")}$"
162
+ elsif method == "describe" || (method == "context" && !via_shoulda?)
163
+ "#{regex}(::)?"
164
+ elsif method == "should" && via_shoulda?
165
+ optional_test_name = "(?:\(.*\))?"
166
+ "#{method} #{regex}\. #{optional_test_name}$"
167
+ elsif ["it", "should"].include?(method) # minitest aliases for shoulda
168
+ "#test_\\d+_#{regex}$"
169
+ else
170
+ regex
171
+ end
172
+
173
+ regex.gsub("'", ".")
174
+ end
174
175
 
175
- def self.via_shoulda?
176
- return @via_shoulda if defined?(@via_shoulda)
177
- @via_shoulda = !File.exist?("Gemfile.lock") || File.read("Gemfile.lock").include?(" shoulda-context ")
176
+ def via_shoulda?
177
+ return @via_shoulda if defined?(@via_shoulda)
178
+ @via_shoulda = !File.exist?("Gemfile.lock") || File.read("Gemfile.lock").include?(" shoulda-context ")
179
+ end
178
180
  end
179
181
  end
180
182
  end
@@ -1,3 +1,3 @@
1
1
  module Maxitest
2
- VERSION = "1.5.3"
2
+ VERSION = "1.5.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maxitest
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.3
4
+ version: 1.5.4
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-08-14 00:00:00.000000000 Z
11
+ date: 2015-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest