require 'active_support/core_ext/string/strip' describe DocTest::HTML::ExamplesSuite do extend Forwardable it_should_behave_like DocTest::BaseExamplesSuite def_delegator :suite, :create_example subject(:suite) { described_class.new } describe '#initialize' do it 'uses ".html" as default file_ext' do expect(suite.file_ext).to eq '.html' end end describe 'parsing/serialization:' do context 'one example' do shared_examples :example do let(:parsed) { suite.parse input, 's' } let(:serialized) { suite.serialize output } it { (expect parsed).to have(1).items } it 'returns an array with parsed example object' do (expect parsed.first).to eql output end it 'returns a serialized example as string' do (expect serialized).to eql input end end context 'with name only' do let(:input) { "\n" } let(:output) { create_example 's:basic' } include_examples :example end context 'with multiline content' do let :content do <<-EOF.strip_heredoc
Paragraphs don't require any special markup.
To begin a new one, separate it by blank line.
EOF end let(:input) { "\n#{content}" } let(:output) { create_example 's:multiline', content: content.chomp } include_examples :example end context 'with description' do let :input do <<-EOF.strip_heredoc allons-y! EOF end let :output do create_example 's:strong', content: 'allons-y!', desc: "This is a description,\nsee?" end include_examples :example end context 'with options' do let :input do <<-EOF.strip_heredocdummy
EOF end let :output do create_example 's:basic', content: 'dummy
', opts: { exclude: ['.//code', './/section'], include: ['./p/node()'] } end include_examples :example end context 'with boolean option' do let(:input) { "\n" } let(:output) { create_example 's:basic', opts: { header_footer: true } } include_examples :example end context 'with description and options' do let :input do <<-EOF.strip_heredoc EOF end let :output do create_example 's:basic', desc: 'This is a description.', opts: { exclude: ['.//code'], header_footer: true } end include_examples :example end end context 'multiple examples' do let :input do <<-EOF.strip_heredoc http://asciidoctor.org Refer to <Chunky bacon
meh
why?
Chunkybacon
why?
' end end context 'with :header_footer option' do let(:opts) { {header_footer: true} } it 'renders content with :header_footer => true' do suite.convert_example input, {}, renderer end end context 'with example named /^document.*/' do let(:input) { create_example 'document:dummy', content: '*chunky* bacon' } let(:converter_opts) { {header_footer: true} } it 'renders content with :header_footer => true' do suite.convert_example input, {}, renderer end end context 'with example named /inline_.*/' do let(:input) { create_example 'inline_quoted:dummy', content: '*chunky* bacon' } let(:rendered) { 'chunky bacon
' } it 'returns content without top-leveltags' do expect(result.content).to eq 'chunky bacon' end it 'does not add implicit include into returned example' do expect(result.opts).to_not include :include end context 'with :include option' do let(:opts) { {include: ['.//b']} } it 'preferes the include option' do expect(result.content).to eq 'chunky' end end end end end