Skip to content

Commit

Permalink
Assert html as xml in page presenter specs.
Browse files Browse the repository at this point in the history
  • Loading branch information
simi committed Feb 15, 2015
1 parent 8579bed commit 35260bf
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ module Pages
describe "when rendering as html" do
it "is empty section tag if it has no sections" do
content = ContentPresenter.new
expect(content.to_html).to eq(%q{<section class="" id="body_content"></section>})
expect(content.to_html).to xml_eq(%q{<section class="" id="body_content"></section>})
end

it "returns sections joined by a newline inside section tag" do
allow(section1).to receive(:wrapped_html).and_return('foo')
allow(section2).to receive(:wrapped_html).and_return('bar')
content = ContentPresenter.new([section1, section2])
expect(content.to_html).to eq(%Q{<section class="" id="body_content">foo\nbar</section>})
expect(content.to_html).to xml_eq(%Q{<section class="" id="body_content">foo\nbar</section>})
end

it "passes can_use_fallback option on to sections" do
Expand All @@ -103,7 +103,7 @@ module Pages
allow(section1).to receive(:wrapped_html).and_return('foo')
allow(section2).to receive(:wrapped_html).and_return(nil)
content = ContentPresenter.new([section1, section2])
expect(content.to_html).to eq(%q{<section class="" id="body_content">foo</section>})
expect(content.to_html).to xml_eq(%q{<section class="" id="body_content">foo</section>})
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions pages/spec/presenters/refinery/pages/menu_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ module Pages
}
let(:menu_presenter) { MenuPresenter.new(menu_items, view) }
it "returns menu items wrapped in html" do
expect(menu_presenter.to_html).to eq(
expect(menu_presenter.to_html).to xml_eq(
%Q{<nav class="menu clearfix" id="menu"><ul class="nav"><li class="first last"><a href="/refinery-cms">Refinery CMS</a></li></ul></nav>}
)
end
Expand All @@ -72,7 +72,7 @@ module Pages
let(:mounted_path) { "/subfolder"}

it "for normal pages" do
expect(menu_presenter.to_html).to eq(
expect(menu_presenter.to_html).to xml_eq(
%Q{<nav class="menu clearfix" id="menu"><ul class="nav"><li class="first last"><a href="#{mounted_path}/refinery-cms">Refinery CMS</a></li></ul></nav>}
)
end
Expand All @@ -82,7 +82,7 @@ module Pages
Menu.new(FactoryGirl.create(:page, title: "Home", link_url: "/"))
}
it "the menu item URL includes the mounted path" do
expect(menu_presenter.to_html).to eq(
expect(menu_presenter.to_html).to xml_eq(
%Q{<nav class="menu clearfix" id="menu"><ul class="nav"><li class="first last"><a href="#{mounted_path}">Home</a></li></ul></nav>}
)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module Pages
part = double(PagePart, :body => '<p>part_body</p>', :title => nil)
section = PagePartSectionPresenter.new(part)
expect(section.fallback_html).to be_html_safe
expect(section.wrapped_html).to eq(%q{<section><div class="inner"><p>part_body</p></div></section>})
expect(section.wrapped_html).to xml_eq(%q{<section><div class="inner"><p>part_body</p></div></section>})
end

it "handles a nil page body" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module Pages
it "will use the specified id" do
section = SectionPresenter.new(:fallback_html => 'foobar', :id => 'mynode')
expect(section.has_content?(true)).to be_truthy
expect(section.wrapped_html(true)).to eq('<section id="mynode"><div class="inner">foobar</div></section>')
expect(section.wrapped_html(true)).to xml_eq('<section id="mynode"><div class="inner">foobar</div></section>')
end

describe "if allowed to use fallback html" do
Expand All @@ -55,14 +55,14 @@ module Pages
it "uses wrapped fallback html" do
section = SectionPresenter.new(:fallback_html => 'foobar')
expect(section.has_content?(true)).to be_truthy
expect(section.wrapped_html(true)).to eq('<section><div class="inner">foobar</div></section>')
expect(section.wrapped_html(true)).to xml_eq('<section><div class="inner">foobar</div></section>')
end

it "uses wrapped override html if present" do
section = SectionPresenter.new(:fallback_html => 'foobar')
section.override_html = 'hello world'
expect(section.has_content?(true)).to be_truthy
expect(section.wrapped_html(true)).to eq('<section><div class="inner">hello world</div></section>')
expect(section.wrapped_html(true)).to xml_eq('<section><div class="inner">hello world</div></section>')
end
end

Expand All @@ -77,7 +77,7 @@ module Pages
section = SectionPresenter.new(:fallback_html => 'foobar')
section.override_html = 'hello world'
expect(section.has_content?(false)).to be_truthy
expect(section.wrapped_html(false)).to eq('<section><div class="inner">hello world</div></section>')
expect(section.wrapped_html(false)).to xml_eq('<section><div class="inner">hello world</div></section>')
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ module Pages
it "wraps a title section in a title element" do
section = TitleSectionPresenter.new(:fallback_html => 'foobar')
expect(section.has_content?(true)).to be_truthy
expect(section.wrapped_html(true)).to eq('<h1>foobar</h1>')
expect(section.wrapped_html(true)).to xml_eq('<h1>foobar</h1>')
end

it "will use the specified id" do
section = TitleSectionPresenter.new(:fallback_html => 'foobar', :id => 'mynode')
expect(section.has_content?(true)).to be_truthy
expect(section.wrapped_html(true)).to eq('<h1 id="mynode">foobar</h1>')
expect(section.wrapped_html(true)).to xml_eq('<h1 id="mynode">foobar</h1>')
end
end
end
Expand Down
7 changes: 7 additions & 0 deletions pages/spec/support/refinery/pages/html_helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module HtmlHelpers
RSpec::Matchers.define :xml_eq do |expected|
match do |actual|
Hash.from_xml(expected) == Hash.from_xml(actual)
end
end
end

0 comments on commit 35260bf

Please sign in to comment.