-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from appbot/namespace-and-readme
Correct namespacing for a SimpleCov formatter
- Loading branch information
Showing
20 changed files
with
189 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,7 @@ | |
## [0.1.0] - 2024-07-19 | ||
|
||
- Initial release | ||
|
||
## [1.0.0] - 2024-07-19 | ||
|
||
- Fix namespacing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
lib/simplecov/inline/formatter.rb → lib/simplecov/formatter/inline.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
module SimpleCov | ||
module Formatter | ||
class Inline | ||
class Integration | ||
class << self | ||
def configure_rspec_rails(rspec: RSpec, rails: Rails) | ||
RSpec::Core::Formatters.register SimpleCov::Formatter::Inline::RSpecFormatterSkipOnFailure, :dump_failures | ||
|
||
rspec.configure do |rspec_config| | ||
rspec_config.add_formatter SimpleCov::Formatter::Inline::RSpecFormatterSkipOnFailure | ||
rspec_config.before(:suite) do | ||
SimpleCov::Formatter::Inline::Integration | ||
.configure_formatter(rspec_config:, rails_root: rails.root.to_s) | ||
end | ||
end | ||
end | ||
|
||
def configure_formatter(rspec_config:, rails_root:) | ||
# Restrict coverage reporting to spec files and the file they are testing. | ||
# Note files_to_run contains all spec files when running rspec with no args, | ||
# so in that case do not filter. | ||
# To do so would exclude files that are covered but not directly tested. | ||
return if running_all_specs?(rspec_config:, rails_root:) | ||
|
||
SimpleCov::Formatter::Inline.config do |coverage_config| | ||
if rspec_config.inclusion_filter.rules.key?(:locations) | ||
# Skip coverage output if running rspec against a single line. | ||
# e.g. spec/x_spec.rb:123 | ||
coverage_config.no_output!(reason: 'filtered to line of code') | ||
else | ||
coverage_config.files = rspec_config.files_to_run.flat_map do |spec_path| | ||
[spec_path, rails_path_under_test(spec_path:, rails_root:)] | ||
end.compact | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def running_all_specs?(rspec_config:, rails_root:) | ||
Dir.glob("#{rails_root}#{rspec_config.pattern}").to_set == rspec_config.files_to_run.to_set | ||
end | ||
|
||
def rails_path_under_test(spec_path:, rails_root:) | ||
# Mappings | ||
# /app/spec/lib/x_spec.rb -> /app/lib/x.rb | ||
# /app/spec/controller/y_spec.rb -> /app/app/controllers/y.rb | ||
raise 'Spec file must be in rails root.' unless spec_path.start_with?(rails_root) | ||
|
||
_spec_root, spec_type, *other_directories, filename = spec_path[(rails_root.length + 1)..].split('/') | ||
|
||
return if filename.nil? | ||
|
||
filename_under_test = filename.gsub(/_spec.rb$/, '.rb') | ||
|
||
if spec_type == 'lib' | ||
[rails_root, spec_type, *other_directories, filename_under_test] | ||
else | ||
[rails_root, 'app', spec_type, *other_directories, filename_under_test] | ||
end.compact.join('/') | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
28 changes: 28 additions & 0 deletions
28
lib/simplecov/formatter/inline/rspec_formatter_skip_on_failure.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module SimpleCov | ||
module Formatter | ||
class Inline | ||
class RSpecFormatterSkipOnFailure | ||
def initialize(output) | ||
@output = output | ||
end | ||
|
||
def dump_failures(notification) | ||
return unless skip_reason(notification:) | ||
|
||
SimpleCov::Formatter::Inline.config do |coverage_config| | ||
coverage_config.no_output!(reason: skip_reason(notification:)) | ||
end | ||
end | ||
|
||
private | ||
|
||
def skip_reason(notification:) | ||
return 'no examples were run' if notification.examples.none? | ||
return 'some specs failed' if notification.failed_examples.any? | ||
|
||
nil | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module SimpleCov | ||
module Formatter | ||
class Inline | ||
VERSION = '1.0.0'.freeze | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,4 @@ | ||
require_relative 'inline/version' | ||
require_relative 'inline/formatter' | ||
require_relative 'inline/rspec_formatter_skip_on_failure' | ||
require_relative 'inline/integration' | ||
|
||
module SimpleCov | ||
module Inline | ||
class Error < StandardError; end | ||
# Your code goes here... | ||
end | ||
end | ||
require_relative 'formatter/inline' | ||
require_relative 'formatter/inline/integration' | ||
require_relative 'formatter/inline/rspec_formatter_skip_on_failure' | ||
require_relative 'formatter/inline/version' |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
require_relative 'lib/simplecov/inline/version' | ||
require_relative 'lib/simplecov/formatter/inline/version' | ||
|
||
Gem::Specification.new do |spec| | ||
spec.name = 'simplecov-inline' | ||
spec.version = SimpleCov::Inline::VERSION | ||
spec.version = SimpleCov::Formatter::Inline::VERSION | ||
spec.authors = ['tris'] | ||
spec.email = ['[email protected]'] | ||
|
||
|
Oops, something went wrong.