require 'spec_helper' mock_node_underline_only = {"value" => "foo", "nodeType" => "text", "marks" => [{"type" => "underline"}]} mock_node_italic_only = {"value" => "foo", "nodeType" => "text", "marks" => [{"type" => "italic"}]} mock_node_bold_only = {"value" => "foo", "nodeType" => "text", "marks" => [{"type" => "bold"}]} mock_node_multiple_marks = { "value" => "foo", "nodeType" => "text", "marks" => [{"type" => "underline"}, {"type" => "italic"}, {"type" => "bold"}], } mock_node_unsupported_mark = {"value" => "foo", "nodeType" => "text", "marks" => [{"type" => "foobar"}]} describe StructuredTextRenderer::TextRenderer do subject do described_class.new( 'text' => StructuredTextRenderer::TextRenderer, 'bold' => StructuredTextRenderer::BoldRenderer, 'italic' => StructuredTextRenderer::ItalicRenderer, 'underline' => StructuredTextRenderer::UnderlineRenderer, nil => StructuredTextRenderer::NullRenderer ) end describe '#render' do it 'can render with a single mark' do expect(subject.render(mock_node_bold_only)).to eq "foo" expect(subject.render(mock_node_italic_only)).to eq "foo" expect(subject.render(mock_node_underline_only)).to eq "foo" end it 'can render multiple marks' do expect(subject.render(mock_node_multiple_marks)).to eq "foo" end it 'raises an error for unsupported marks' do expect { subject.render(mock_node_unsupported_mark) }.to raise_error "No renderer defined for 'foobar' nodes" end it 'supports custom renderers' do subject = described_class.new( 'text' => StructuredTextRenderer::TextRenderer, 'bold' => BoldMarkdownRenderer, nil => StructuredTextRenderer::NullRenderer ) expect(subject.render(mock_node_bold_only)).to eq "**foo**" end end end