From b95630f382e562ab14349fa3005bccd5b12eb2df Mon Sep 17 00:00:00 2001 From: Jeremy Wells Date: Fri, 26 Oct 2018 13:07:26 +1300 Subject: [PATCH 1/2] Add spec helper to simplify specs, and Gemfile to load required dev gems --- .gitignore | 1 + .rspec | 4 ++- Gemfile | 6 ++++ Gemfile.lock | 60 +++++++++++++++++++++++++++++++ html2confluence.gemspec | 3 ++ spec/combination_examples_spec.rb | 2 -- spec/complex_tables_spec.rb | 2 -- spec/html2confluence_spec.rb | 2 -- spec/jira_examples_spec.rb | 2 -- spec/spec_helper.rb | 17 +++++++++ 10 files changed, 90 insertions(+), 9 deletions(-) create mode 100644 .gitignore create mode 100644 Gemfile create mode 100644 Gemfile.lock create mode 100644 spec/spec_helper.rb diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..250186b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +spec/coverage diff --git a/.rspec b/.rspec index 5052887..9ae52ee 100644 --- a/.rspec +++ b/.rspec @@ -1 +1,3 @@ ---color \ No newline at end of file +--colour +--require spec_helper +--profile diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..4fda8bd --- /dev/null +++ b/Gemfile @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + +gemspec +git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..5b44601 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,60 @@ +PATH + remote: . + specs: + html2confluence (1.3.23) + nokogiri + +GEM + remote: https://rubygems.org/ + specs: + ast (2.4.0) + diff-lcs (1.3) + docile (1.3.1) + json (2.1.0) + mini_portile2 (2.3.0) + nokogiri (1.8.5) + mini_portile2 (~> 2.3.0) + parallel (1.12.1) + parser (2.5.1.2) + ast (~> 2.4.0) + powerpack (0.1.2) + rainbow (3.0.0) + rspec (3.8.0) + rspec-core (~> 3.8.0) + rspec-expectations (~> 3.8.0) + rspec-mocks (~> 3.8.0) + rspec-core (3.8.0) + rspec-support (~> 3.8.0) + rspec-expectations (3.8.2) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.8.0) + rspec-mocks (3.8.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.8.0) + rspec-support (3.8.0) + rubocop (0.55.0) + parallel (~> 1.10) + parser (>= 2.5) + powerpack (~> 0.1) + rainbow (>= 2.2.2, < 4.0) + ruby-progressbar (~> 1.7) + unicode-display_width (~> 1.0, >= 1.0.1) + ruby-progressbar (1.10.0) + simplecov (0.16.1) + docile (~> 1.1) + json (>= 1.8, < 3) + simplecov-html (~> 0.10.0) + simplecov-html (0.10.2) + unicode-display_width (1.4.0) + +PLATFORMS + ruby + +DEPENDENCIES + html2confluence! + rspec + rubocop (< 0.56) + simplecov + +BUNDLED WITH + 1.16.6 diff --git a/html2confluence.gemspec b/html2confluence.gemspec index 2608c18..d4c7093 100644 --- a/html2confluence.gemspec +++ b/html2confluence.gemspec @@ -15,4 +15,7 @@ Gem::Specification.new do |s| s.files = Dir.glob("{lib,spec}/**/*") + %w(example.rb README.mdown) s.add_dependency "nokogiri" + s.add_development_dependency "rspec" + s.add_development_dependency "rubocop", "< 0.56" + s.add_development_dependency "simplecov" end diff --git a/spec/combination_examples_spec.rb b/spec/combination_examples_spec.rb index f1ef51e..4a78d2e 100644 --- a/spec/combination_examples_spec.rb +++ b/spec/combination_examples_spec.rb @@ -1,6 +1,4 @@ # encoding: utf-8 -$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib') -require 'html2confluence' describe HTMLToConfluenceParser, "when running combination examples" do diff --git a/spec/complex_tables_spec.rb b/spec/complex_tables_spec.rb index 1c8fa12..cd5d017 100644 --- a/spec/complex_tables_spec.rb +++ b/spec/complex_tables_spec.rb @@ -1,6 +1,4 @@ # encoding: utf-8 -$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib') -require 'html2confluence' describe HTMLToConfluenceParser, "when running complex tables examples" do diff --git a/spec/html2confluence_spec.rb b/spec/html2confluence_spec.rb index 027f194..1c90b67 100644 --- a/spec/html2confluence_spec.rb +++ b/spec/html2confluence_spec.rb @@ -1,6 +1,4 @@ # encoding: utf-8 -$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib') -require 'html2confluence' describe HTMLToConfluenceParser, "when converting html to textile" do context "in a large html document" do diff --git a/spec/jira_examples_spec.rb b/spec/jira_examples_spec.rb index 3310541..d770e7e 100644 --- a/spec/jira_examples_spec.rb +++ b/spec/jira_examples_spec.rb @@ -1,6 +1,4 @@ # encoding: utf-8 -$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib') -require 'html2confluence' describe HTMLToConfluenceParser, "when running JIRA examples" do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..7fc85e5 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,17 @@ +require 'rspec' +require 'simplecov' + +SimpleCov.start do + coverage_dir 'spec/coverage' + add_filter 'spec' + add_filter '.bundle' +end + +require 'html2confluence' + +RSpec.configure do |config| + config.filter_gems_from_backtrace "rspec-core", "rspec" + config.run_all_when_everything_filtered = true + config.order = :random +end + From 074e978bf61eadd3ef8fbaf6d8adc1973eb31bb5 Mon Sep 17 00:00:00 2001 From: Jeremy Wells Date: Fri, 26 Oct 2018 13:21:50 +1300 Subject: [PATCH 2/2] Fix existing spec breakages around blockquote handling --- spec/combination_examples_spec.rb | 14 +-- spec/complex_tables_spec.rb | 5 +- spec/html2confluence_spec.rb | 8 +- spec/jira_examples_spec.rb | 201 +++++++++++++++--------------- 4 files changed, 106 insertions(+), 122 deletions(-) diff --git a/spec/combination_examples_spec.rb b/spec/combination_examples_spec.rb index 4a78d2e..a6ba0c2 100644 --- a/spec/combination_examples_spec.rb +++ b/spec/combination_examples_spec.rb @@ -1,6 +1,7 @@ # encoding: utf-8 describe HTMLToConfluenceParser, "when running combination examples" do + let(:parser) { HTMLToConfluenceParser.new } it "should match complex examples" do html = <<-END @@ -18,7 +19,6 @@ END - parser = HTMLToConfluenceParser.new parser.feed(html) expect(parser.to_wiki_markup.strip).to include(markup.strip) end @@ -93,7 +93,6 @@ h1. With +nice+ formatting. END - parser = HTMLToConfluenceParser.new parser.feed(html) expect(parser.to_wiki_markup.strip).to include(markup.strip) end @@ -104,10 +103,9 @@ END markup = <<-END -{quote}\nbq. content here\n{quote} +{quote}\ncontent here\n{quote} END - parser = HTMLToConfluenceParser.new parser.feed(html) expect(parser.to_wiki_markup.strip).to include(markup.strip) end @@ -120,7 +118,6 @@ markup = "Previous\n\n*Scenario 4a: Existing deletes their ID*\n*Given* I am an existing user" - parser = HTMLToConfluenceParser.new parser.feed(html) expect(parser.to_wiki_markup.strip).to eq(markup) end @@ -134,7 +131,6 @@ markup = "Previous line\n\n*Scenario 4a: Existing deletes their ID*\n*Given* I am an existing user" - parser = HTMLToConfluenceParser.new parser.feed(html) expect(parser.to_wiki_markup.strip).to eq(markup) end @@ -144,7 +140,6 @@ markup = "*And* first line\n\n*second line*" - parser = HTMLToConfluenceParser.new parser.feed(html) expect(parser.to_wiki_markup.strip).to eq(markup) end @@ -154,7 +149,6 @@ markup = "!a source!" - parser = HTMLToConfluenceParser.new parser.feed(html) expect(parser.to_wiki_markup.strip).to eq(markup) end @@ -163,7 +157,6 @@ html = "
familiar with the XMLHttpRequest Object
\n\n" markup = "familiar with the XMLHttpRequest Object" - parser = HTMLToConfluenceParser.new parser.feed(html) expect(parser.to_wiki_markup.strip).to eq(markup) @@ -177,7 +170,6 @@ markup = "Previous line\n\n----" - parser = HTMLToConfluenceParser.new parser.feed(html) expect(parser.to_wiki_markup.strip).to eq(markup) end @@ -189,7 +181,6 @@ markup = "A" - parser = HTMLToConfluenceParser.new parser.feed(html) expect(parser.to_wiki_markup.strip).to eq(markup) end @@ -202,7 +193,6 @@ markup = "A" - parser = HTMLToConfluenceParser.new parser.feed(html) expect(parser.to_wiki_markup.strip).to eq(markup) end diff --git a/spec/complex_tables_spec.rb b/spec/complex_tables_spec.rb index cd5d017..6ee5cc8 100644 --- a/spec/complex_tables_spec.rb +++ b/spec/complex_tables_spec.rb @@ -1,6 +1,7 @@ # encoding: utf-8 describe HTMLToConfluenceParser, "when running complex tables examples" do + let(:parser) { HTMLToConfluenceParser.new } it "should handle table with newlines" do html = <<-END @@ -19,7 +20,6 @@ * Good for my teeth| END - parser = HTMLToConfluenceParser.new parser.feed(html) expect(parser.to_wiki_markup.strip).to include(markup.strip) end @@ -33,7 +33,6 @@ | |Empty| | END - parser = HTMLToConfluenceParser.new parser.feed(html) expect(parser.to_wiki_markup.strip).to include(markup.strip) end @@ -50,7 +49,6 @@ b{noformat} |c | END - parser = HTMLToConfluenceParser.new parser.feed(html) expect(parser.to_wiki_markup.strip).to include(markup.strip) end @@ -77,7 +75,6 @@ 2{noformat} |3 | END - parser = HTMLToConfluenceParser.new parser.feed(html) expect(parser.to_wiki_markup.strip).to include(markup.strip) end diff --git a/spec/html2confluence_spec.rb b/spec/html2confluence_spec.rb index 1c90b67..3debf37 100644 --- a/spec/html2confluence_spec.rb +++ b/spec/html2confluence_spec.rb @@ -1,8 +1,10 @@ # encoding: utf-8 describe HTMLToConfluenceParser, "when converting html to textile" do + let(:parser) { HTMLToConfluenceParser.new } + context "in a large html document" do - before :all do + before do html = <<-END
@@ -124,7 +126,6 @@ |Not table
END - parser = HTMLToConfluenceParser.new parser.feed(html) @textile = parser.to_wiki_markup end @@ -263,7 +264,6 @@ END - parser = HTMLToConfluenceParser.new parser.feed(html) @textile = parser.to_wiki_markup @@ -282,7 +282,6 @@ END - parser = HTMLToConfluenceParser.new parser.feed(html) @textile = parser.to_wiki_markup @@ -301,7 +300,6 @@ END - parser = HTMLToConfluenceParser.new parser.feed(html) @textile = parser.to_wiki_markup diff --git a/spec/jira_examples_spec.rb b/spec/jira_examples_spec.rb index d770e7e..9f06c6c 100644 --- a/spec/jira_examples_spec.rb +++ b/spec/jira_examples_spec.rb @@ -1,9 +1,30 @@ # encoding: utf-8 describe HTMLToConfluenceParser, "when running JIRA examples" do + let(:parser) { HTMLToConfluenceParser.new } - before :all do - html = <<-END + it "should convert images within a link" do + imagetarget = "https://example.com/image.jpg" + link = "https://example.com/index.html" + test_html = %{ +

+ + + +

+ } + + parser.feed test_html + @textile = parser.to_wiki_markup + + expect(@textile).to eq("[!#{imagetarget}!|#{link}]") + end + + context "with large document" do + before do + html = <<-END

Biggest heading

Bigger heading

Big heading

@@ -127,9 +148,9 @@ so *no* further _formatting_ is done here - END + END - markup = <<-END + markup = <<-END h1. Biggest heading h2. Bigger heading h3. Big heading @@ -211,104 +232,82 @@ preformatted piece of text so *no* further _formatting_ is done here {noformat} - END + END + parser.feed(html) + @textile = parser.to_wiki_markup + #puts @textile + #puts RedCloth.new(@textile).to_html + end + + it "should convert heading tags" do + expect(@textile).to match(/^h1. Biggest heading/) + expect(@textile).to match(/^h2. Bigger heading/) + expect(@textile).to match(/^h3. Big heading/) + expect(@textile).to match(/^h4. Normal heading/) + expect(@textile).to match(/^h5. Small heading/) + expect(@textile).to match(/^h6. Smallest heading/) + end - parser = HTMLToConfluenceParser.new - parser.feed(html) - @textile = parser.to_wiki_markup - #puts @textile - #puts RedCloth.new(@textile).to_html - end - - it "should convert images within a link" do - imagetarget = "https://example.com/image.jpg" - link = "https://example.com/index.html" - test_html = %{ -

- - - -

- } - - parser = HTMLToConfluenceParser.new - parser.feed test_html - @textile = parser.to_wiki_markup - - expect(@textile).to eq("[!#{imagetarget}!|#{link}]") - end - - it "should convert heading tags" do - expect(@textile).to match(/^h1. Biggest heading/) - expect(@textile).to match(/^h2. Bigger heading/) - expect(@textile).to match(/^h3. Big heading/) - expect(@textile).to match(/^h4. Normal heading/) - expect(@textile).to match(/^h5. Small heading/) - expect(@textile).to match(/^h6. Smallest heading/) - end - - it "should convert inline formatting" do - expect(@textile).to match(/^\*strong\*/) - expect(@textile).to match(/^_emphasis_/) - expect(@textile).to match(/^\?\?citation\?\?/) - expect(@textile).to match(/^-deleted-/) - expect(@textile).to match(/^\+inserted\+/) - expect(@textile).to match(/^\^superscript\^/) - expect(@textile).to match(/^\~subscript\~/) - expect(@textile).to match(/^\{\{monospaced\}\}/) - end - - it "should convert block quotes" do - expect(@textile).to match(/^bq. Some block quoted text/) - expect(@textile).to match(/^\{quote\}\s*here is quotable\s*content to be quoted\s*{quote}/) - end - - it "should handle text color" do - expect(@textile).to match(/^\{color\:red\}\s*look ma, red text!\s*\{color\}/) - end - - it "should convert horizontal rules" do - expect(@textile).to match(/^----/) - end - - it "should convert dashes" do - expect(@textile).to match(/^a -- b/) - expect(@textile).to match(/^a --- b/) - end - - it "should convert links" do - expect(@textile).to match(/^\[\#anchor\]/) - expect(@textile).to match(/^\[http\:\/\/jira.atlassian.com\]/) - expect(@textile).to match(/^\[Atlassian\|http\:\/\/atlassian.com\]/) - expect(@textile).to match(/^\[file\:\/\/\/c\:\/temp\/foo.txt\]/) - end - - it "should convert bullets" do - expect(@textile).to match(/\* some\s*\* bullet\s*\*\* indented\s*\*\* bullets\s*\* points/) - expect(@textile).to match(/- different\s*- bullet\s*- types/) - expect(@textile).to match(/# a\s*# numbered\s*# list/) - expect(@textile).to match(/# a\s*# numbered\s*#\* with\s*#\* nested\s*#\* bullet\s*# list/) - expect(@textile).to match(/\* a\s*\* bulleted\s*\*# with\s*\*# nested\s*\*# numbered\s*\* list/) - end - - it "should convert pre blocks" do - expect(@textile).to match(/^\{noformat\}\s*preformatted piece of text\s*so \*no\* further _formatting_ is done here\s*\{noformat\}/) - end - - it "should convert tables" do - expect(@textile).to include("||heading 1 ||heading 2 ||heading 3 ||") - expect(@textile).to include("|col A1 |col A2 |col A3 |") - expect(@textile).to include("|col B1 |col B2 |col B3 |") - end - - it "should convert emoji from jira" do - expect(@textile).to include(":)") - expect(@textile).to include("(!)") - expect(@textile).to include("(off)") - expect(@textile).to include("(/)") + it "should convert inline formatting" do + expect(@textile).to match(/^\*strong\*/) + expect(@textile).to match(/^_emphasis_/) + expect(@textile).to match(/^\?\?citation\?\?/) + expect(@textile).to match(/^-deleted-/) + expect(@textile).to match(/^\+inserted\+/) + expect(@textile).to match(/^\^superscript\^/) + expect(@textile).to match(/^\~subscript\~/) + expect(@textile).to match(/^\{\{monospaced\}\}/) + end + + it "should convert block quotes" do + expect(@textile).to match(/^Some block quoted text/) + expect(@textile).to match(/^\{quote\}\s*here is quotable\s*content to be quoted\s*{quote}/) + end + + it "should handle text color" do + expect(@textile).to match(/^\{color\:red\}\s*look ma, red text!\s*\{color\}/) + end + + it "should convert horizontal rules" do + expect(@textile).to match(/^----/) + end + + it "should convert dashes" do + expect(@textile).to match(/^a -- b/) + expect(@textile).to match(/^a --- b/) + end + + it "should convert links" do + expect(@textile).to match(/^\[\#anchor\]/) + expect(@textile).to match(/^\[http\:\/\/jira.atlassian.com\]/) + expect(@textile).to match(/^\[Atlassian\|http\:\/\/atlassian.com\]/) + expect(@textile).to match(/^\[file\:\/\/\/c\:\/temp\/foo.txt\]/) + end + + it "should convert bullets" do + expect(@textile).to match(/\* some\s*\* bullet\s*\*\* indented\s*\*\* bullets\s*\* points/) + expect(@textile).to match(/- different\s*- bullet\s*- types/) + expect(@textile).to match(/# a\s*# numbered\s*# list/) + expect(@textile).to match(/# a\s*# numbered\s*#\* with\s*#\* nested\s*#\* bullet\s*# list/) + expect(@textile).to match(/\* a\s*\* bulleted\s*\*# with\s*\*# nested\s*\*# numbered\s*\* list/) + end + + it "should convert pre blocks" do + expect(@textile).to match(/^\{noformat\}\s*preformatted piece of text\s*so \*no\* further _formatting_ is done here\s*\{noformat\}/) + end + + it "should convert tables" do + expect(@textile).to include("||heading 1 ||heading 2 ||heading 3 ||") + expect(@textile).to include("|col A1 |col A2 |col A3 |") + expect(@textile).to include("|col B1 |col B2 |col B3 |") + end + + it "should convert emoji from jira" do + expect(@textile).to include(":)") + expect(@textile).to include("(!)") + expect(@textile).to include("(off)") + expect(@textile).to include("(/)") + end end - end