Sha256: 4e3c8138b9bd18247aaa3811a554bd4f9f23f28e77a89977ee7538fe5c04f09e

Contents?: true

Size: 1.86 KB

Versions: 3

Compression:

Stored size: 1.86 KB

Contents

RSpec.describe BreadcrumbTrail::HTMLBuilder do
  let(:breadcrumbs) {
    [
      { path: "/", name: "home" },
      { path: "/foo", name: "foo" },
      { path: "/foo/bar", name: "foo/bar" }
    ].map { |data| BreadcrumbTrail::Breadcrumb.new(data) } }
  let(:context) { double("context") }
  let(:options) { Hash.new }

  subject { described_class.new(context, breadcrumbs, options) }

  it "renders a list" do
    expect(subject.call).to eq "<ol>" \
      "<li><a href=\"/\">home</a></li>" \
      "<li><a href=\"/foo\">foo</a></li>" \
      "<li><a href=\"/foo/bar\">foo/bar</a></li>" \
      "</ol>"
  end

  describe "when given options" do
    let(:options) { { outer: "ul", outer_options: { class: "navigation" } } }

    it "renders a list with options" do
      expect(subject.call).
        to eq "<ul class=\"navigation\">" \
        "<li><a href=\"/\">home</a></li>" \
        "<li><a href=\"/foo\">foo</a></li>" \
        "<li><a href=\"/foo/bar\">foo/bar</a></li>" \
        "</ul>"
    end
  end

  describe "when given nil tags" do
    let(:options) { { outer: nil, inner: nil } }

    it "renders only links" do
      expect(subject.call).to eq \
        "<a href=\"/\">home</a>" \
        "<a href=\"/foo\">foo</a>" \
        "<a href=\"/foo/bar\">foo/bar</a>"
    end
  end

  describe "when given breadcrumbs with html data" do
    let(:breadcrumbs) {
      [
        { path: "/", name: "<script>home</script>" },
        { path: "/foo", name: "<a>foo</a>" },
        { path: "/foo/bar", name: "<foo/bar>" }
      ].map { |data| BreadcrumbTrail::Breadcrumb.new(data) }
    }

    it "escapes the breadcrumbs" do
      expect(subject.call).to eq "<ol>" \
        "<li><a href=\"/\">&lt;script&gt;home&lt;/script&gt;</a></li>" \
        "<li><a href=\"/foo\">&lt;a&gt;foo&lt;/a&gt;</a></li>" \
        "<li><a href=\"/foo/bar\">&lt;foo/bar&gt;</a></li>" \
        "</ol>"
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
breadcrumb_trail-0.2.1 spec/html_builder_spec.rb
breadcrumb_trail-0.2.0 spec/html_builder_spec.rb
breadcrumb_trail-0.1.0 spec/html_builder_spec.rb