single_cov 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 06235003ba998e10cd4a9fad6029c016bdad7527
4
- data.tar.gz: 2855a2c0d6e7ee11d5d9282bbd2eb5a04b1fbc2c
3
+ metadata.gz: a1eed48907c72cdc169cf0a1102214a19aba7d04
4
+ data.tar.gz: a03c0a381e3c943ae9f4d8b0ddeaa6e70323a422
5
5
  SHA512:
6
- metadata.gz: 350df9d73f335976a8c412b1c56d7166a0dffbfb2bf04159830a5552cd1a2e4d5b346a79d2b473be562a77bcfc7c3fbeee220599d61e3216b0b9af472a263aae
7
- data.tar.gz: 0dadb5853bc51f7dd9d26f07706904e3f8247bfb674532ddc30a85fffd877a0693142e2b3b1c0ced69d01fd8f06e1a11616d13b8595d6689aa03e2cbf860ebd1
6
+ metadata.gz: 7e0f571ad1defd8f2fa00f5aaf6e152b9e84caf0b89ccec6bd8b9c38b5459387fef00a9945760613b9cac779bfa23dafd66387c74a8454535cdd12209e0528b2
7
+ data.tar.gz: 417af607d91795747bcee02325a1ae2f97786197a66cb44bb452958e433d226a4729de71f1f06dd1e15176632562f4b10deb800c0a1b115af1fe1173deadc97e
@@ -1,3 +1,3 @@
1
1
  module SingleCov
2
- VERSION = "0.2.2"
2
+ VERSION = "0.3.0"
3
3
  end
data/lib/single_cov.rb CHANGED
@@ -19,7 +19,7 @@ module SingleCov
19
19
 
20
20
  def all_covered?(result)
21
21
  errors = COVERAGES.map do |file, expected_uncovered|
22
- if coverage = result[File.expand_path(file)]
22
+ if coverage = result["#{root}/#{file}"]
23
23
  uncovered_lines = coverage.each_with_index.map { |c, i| "#{file}:#{i+1}" if c == 0 }.compact
24
24
  next if uncovered_lines.size == expected_uncovered
25
25
  warn_about_bad_coverage(file, expected_uncovered, uncovered_lines)
@@ -46,7 +46,7 @@ module SingleCov
46
46
  end
47
47
  end
48
48
 
49
- def assert_tested(files: Dir['{app,lib}/**/*.rb'], tests: default_tests, untested: [])
49
+ def assert_tested(files: glob('{app,lib}/**/*.rb'), tests: default_tests, untested: [])
50
50
  missing = files - tests.map { |t| file_under_test(t) }
51
51
  fixed = untested - missing
52
52
  missing -= untested
@@ -58,11 +58,13 @@ module SingleCov
58
58
  end
59
59
  end
60
60
 
61
- def setup(framework)
61
+ def setup(framework, root: nil)
62
62
  if defined?(SimpleCov)
63
63
  raise "Load SimpleCov after SingleCov"
64
64
  end
65
65
 
66
+ @root = root if root
67
+
66
68
  case framework
67
69
  when :minitest
68
70
  minitest_should_not_be_running!
@@ -83,7 +85,11 @@ module SingleCov
83
85
  private
84
86
 
85
87
  def default_tests
86
- Dir["{test,spec}/**/*_{test,spec}.rb"]
88
+ glob("{test,spec}/**/*_{test,spec}.rb")
89
+ end
90
+
91
+ def glob(pattern)
92
+ Dir["#{root}/#{pattern}"].map! { |f| f.sub("#{root}/", '') }
87
93
  end
88
94
 
89
95
  # do not ask for coverage when SimpleCov already does or it conflicts
@@ -148,14 +154,14 @@ module SingleCov
148
154
 
149
155
  def guess_and_check_covered_file(file)
150
156
  if file && file.start_with?("/")
151
- raise "Use paths relative to rails root."
157
+ raise "Use paths relative to root."
152
158
  end
153
159
 
154
160
  if file
155
- raise "#{file} does not exist and cannot be covered." unless File.exist?(file)
161
+ raise "#{file} does not exist and cannot be covered." unless File.exist?("#{root}/#{file}")
156
162
  else
157
163
  file = file_under_test(caller[1])
158
- unless File.exist?(file)
164
+ unless File.exist?("#{root}/#{file}")
159
165
  raise "Tried to guess covered file as #{file}, but it does not exist.\nUse `SingleCov.covered file: 'target_file.rb'` to set covered file location."
160
166
  end
161
167
  end
@@ -179,7 +185,7 @@ module SingleCov
179
185
  end
180
186
 
181
187
  def warn_about_no_coverage(file)
182
- if $LOADED_FEATURES.include?(File.expand_path(file))
188
+ if $LOADED_FEATURES.include?("#{root}/#{file}")
183
189
  # we cannot enforce $LOADED_FEATURES during covered! since it would fail when multiple files are loaded
184
190
  "#{file} was expected to be covered, but already loaded before tests started."
185
191
  else
@@ -190,12 +196,15 @@ module SingleCov
190
196
  def file_under_test(file)
191
197
  file = file.dup
192
198
 
193
- # remove project root
194
- file.sub!("#{Dir.pwd}/", '')
195
-
196
199
  # remove caller junk to get nice error messages when something fails
197
200
  file.sub!(/\.rb\b.*/, '.rb')
198
201
 
202
+ # resolve all kinds of relativity
203
+ file = File.expand_path(file)
204
+
205
+ # remove project root
206
+ file.sub!("#{root}/", '')
207
+
199
208
  # preserve subfolders like foobar/test/xxx_test.rb -> foobar/lib/xxx_test.rb
200
209
  subfolder, file_part = file.split(%r{(?:^|/)(?:test|spec)/}, 2)
201
210
  unless file_part
@@ -223,5 +232,9 @@ module SingleCov
223
232
 
224
233
  file_part
225
234
  end
235
+
236
+ def root
237
+ @root ||= (defined?(Bundler) && Bundler.root.to_s) || Dir.pwd
238
+ end
226
239
  end
227
240
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: single_cov
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser