1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
require 'spec_helper'
describe ReverseMarkdown do
let(:input) { File.read('spec/assets/minimum.html') }
let(:document) { Nokogiri::HTML(input) }
it "parses nokogiri documents" do
expect { ReverseMarkdown.convert(document) }.not_to raise_error
end
it "parses nokogiri elements" do
expect { ReverseMarkdown.convert(document.root) }.not_to raise_error
end
it "parses string input" do
expect { ReverseMarkdown.convert(input) }.not_to raise_error
end
it "behaves in a sane way when root element is nil" do
expect(ReverseMarkdown.convert(nil)).to eq ''
end
describe '#config' do
it 'stores a given configuration option' do
ReverseMarkdown.config.github_flavored = true
expect(ReverseMarkdown.config.github_flavored).to eq true
end
it 'can be used as a block configurator as well' do
ReverseMarkdown.config do |config|
expect(config.github_flavored).to eq false
config.github_flavored = true
end
expect(ReverseMarkdown.config.github_flavored).to eq true
end
describe 'force_encoding option', jruby: :exclude do
it 'raises invalid byte sequence in UTF-8 exception' do
# Older versions of ruby used to raise ArgumentError here. Remove when we drop support for 3.1.
expect { ReverseMarkdown.convert("hi \255") }.to raise_error { [Encoding::CompatibilityError, ArgumentError].include?(_1.class) }
end
it 'handles invalid byte sequence if option is set' do
expect(ReverseMarkdown.convert("hi \255", force_encoding: true)).to eq "hi\n\n"
end
end
end
end
|