Skip to content

Commit be33798

Browse files
authored
Merge pull request #2072 from github/test-coverage-100
Add 100% test coverage floor with SimpleCov
2 parents b86a513 + 54a8e28 commit be33798

11 files changed

Lines changed: 327 additions & 14 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ vendor/
88
.DS_Store
99
.venv
1010
venv
11+
coverage/

Gemfile.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ GEM
3939
crass (1.0.6)
4040
creole (0.5.0)
4141
date (3.5.1)
42+
docile (1.4.1)
4243
drb (2.2.3)
4344
erb (6.0.4)
4445
expression_parser (0.9.0)
@@ -98,6 +99,12 @@ GEM
9899
crass (~> 1.0.2)
99100
nokogiri (>= 1.12.0)
100101
securerandom (0.4.1)
102+
simplecov (0.22.0)
103+
docile (~> 1.1)
104+
simplecov-html (~> 0.11)
105+
simplecov_json_formatter (~> 0.1)
106+
simplecov-html (0.13.2)
107+
simplecov_json_formatter (0.1.4)
101108
stringio (3.2.0)
102109
tdiff (0.4.0)
103110
tsort (0.2.0)
@@ -143,6 +150,7 @@ DEPENDENCIES
143150
redcarpet
144151
rexml
145152
sanitize (>= 4.6.3)
153+
simplecov (~> 0.22)
146154
twitter-text (~> 1.14)
147155
wikicloth (= 0.8.3)
148156

github-markup.gemspec

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
require File.expand_path("../lib/github-markup", __FILE__)
1+
version_file = File.expand_path("../lib/github-markup.rb", __FILE__)
2+
version_match = File.read(version_file).match(/VERSION = ['"]([^'"]+)['"]/)
3+
raise "Could not find VERSION in #{version_file}" unless version_match
4+
version = version_match[1]
25

36
Gem::Specification.new do |s|
47
s.name = "github-markup"
5-
s.version = GitHub::Markup::VERSION
8+
s.version = version
69
s.summary = "The code GitHub uses to render README.markup"
710
s.description = <<~DESC
811
This gem is used by GitHub to render any fancy markup such as Markdown,
@@ -28,4 +31,5 @@ Gem::Specification.new do |s|
2831
s.add_development_dependency 'nokogiri', '~> 1.19.2'
2932
s.add_development_dependency 'nokogiri-diff', '~> 0.3.0'
3033
s.add_development_dependency "github-linguist", ">= 7.1.3"
34+
s.add_development_dependency 'simplecov', '~> 0.22'
3135
end

lib/github/markup.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ def language(filename, content, symlink: false)
9797
end
9898

9999
# Define markups
100-
markups_rb = File.dirname(__FILE__) + '/markups.rb'
101-
instance_eval File.read(markups_rb), markups_rb
100+
require_relative 'markups'
102101
end
103102
end

lib/github/markup/rdoc.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ def render(filename, content, options: {})
1313
if ::RDoc::VERSION.to_i >= 4
1414
h = ::RDoc::Markup::ToHtml.new(::RDoc::Options.new)
1515
else
16+
# :nocov: RDoc < 4 has been unsupported since Ruby 2.4 (2016); modern RDoc requires Options.
1617
h = ::RDoc::Markup::ToHtml.new
18+
# :nocov:
1719
end
1820
h.convert(content)
1921
end

lib/github/markups.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,32 @@
22
require "github/markup/rdoc"
33
require "shellwords"
44

5-
markup_impl(::GitHub::Markups::MARKUP_MARKDOWN, ::GitHub::Markup::Markdown.new)
5+
GitHub::Markup.markup_impl(::GitHub::Markups::MARKUP_MARKDOWN, ::GitHub::Markup::Markdown.new)
66

7-
markup(::GitHub::Markups::MARKUP_TEXTILE, :redcloth, /textile/, ["Textile"]) do |filename, content, options: {}|
7+
GitHub::Markup.markup(::GitHub::Markups::MARKUP_TEXTILE, :redcloth, /textile/, ["Textile"]) do |filename, content, options: {}|
88
RedCloth.new(content).to_html
99
end
1010

11-
markup_impl(::GitHub::Markups::MARKUP_RDOC, GitHub::Markup::RDoc.new)
11+
GitHub::Markup.markup_impl(::GitHub::Markups::MARKUP_RDOC, GitHub::Markup::RDoc.new)
1212

13-
markup(::GitHub::Markups::MARKUP_ORG, 'org-ruby', /org/, ["Org"]) do |filename, content, options: {}|
13+
GitHub::Markup.markup(::GitHub::Markups::MARKUP_ORG, 'org-ruby', /org/, ["Org"]) do |filename, content, options: {}|
1414
Orgmode::Parser.new(content, {
1515
:allow_include_files => false,
1616
:skip_syntax_highlight => true
1717
}).to_html
1818
end
1919

20-
markup(::GitHub::Markups::MARKUP_CREOLE, :creole, /creole/, ["Creole"]) do |filename, content, options: {}|
20+
GitHub::Markup.markup(::GitHub::Markups::MARKUP_CREOLE, :creole, /creole/, ["Creole"]) do |filename, content, options: {}|
2121
Creole.creolize(content)
2222
end
2323

24-
markup(::GitHub::Markups::MARKUP_MEDIAWIKI, :wikicloth, /mediawiki|wiki/, ["MediaWiki"]) do |filename, content, options: {}|
24+
GitHub::Markup.markup(::GitHub::Markups::MARKUP_MEDIAWIKI, :wikicloth, /mediawiki|wiki/, ["MediaWiki"]) do |filename, content, options: {}|
2525
wikicloth = WikiCloth::WikiCloth.new(:data => content)
2626
WikiCloth::WikiBuffer::HTMLElement::ESCAPED_TAGS << 'tt' unless WikiCloth::WikiBuffer::HTMLElement::ESCAPED_TAGS.include?('tt')
2727
wikicloth.to_html(:noedit => true)
2828
end
2929

30-
markup(::GitHub::Markups::MARKUP_ASCIIDOC, :asciidoctor, /adoc|asc(iidoc)?/, ["AsciiDoc"]) do |filename, content, options: {}|
30+
GitHub::Markup.markup(::GitHub::Markups::MARKUP_ASCIIDOC, :asciidoctor, /adoc|asc(iidoc)?/, ["AsciiDoc"]) do |filename, content, options: {}|
3131
attributes = {
3232
'showtitle' => '@',
3333
'idprefix' => '',
@@ -47,13 +47,13 @@
4747
Asciidoctor.convert(content, :safe => :secure, :attributes => attributes)
4848
end
4949

50-
command(
50+
GitHub::Markup.command(
5151
::GitHub::Markups::MARKUP_RST,
5252
"python3 #{Shellwords.escape(File.dirname(__FILE__))}/commands/rest2html",
5353
/re?st(\.txt)?/,
5454
["reStructuredText"],
5555
"restructuredtext"
5656
)
5757

58-
command(::GitHub::Markups::MARKUP_POD6, :pod62html, /pod6/, ["Pod 6"], "pod6")
59-
command(::GitHub::Markups::MARKUP_POD, :pod2html, /pod/, ["Pod"], "pod")
58+
GitHub::Markup.command(::GitHub::Markups::MARKUP_POD6, :pod62html, /pod6/, ["Pod 6"], "pod6")
59+
GitHub::Markup.command(::GitHub::Markups::MARKUP_POD, :pod2html, /pod/, ["Pod"], "pod")

0 commit comments

Comments
 (0)