spec/rack/dev-mark/theme/base_spec.rb in rack-dev-mark-0.4.6 vs spec/rack/dev-mark/theme/base_spec.rb in rack-dev-mark-0.5.0
- old
+ new
@@ -11,7 +11,56 @@
it "sets up" do
subject.setup 'env', 'rev'
expect(subject.env).to eq('env')
expect(subject.revision).to eq('rev')
end
+ describe "#gsub_tag_content" do
+ let(:input) { %Q|<body><h1>head</h1><a href="something">x</a><span></span>y</div>| }
+ let(:output) { %Q|<body><h1>head</h1><a href="something">replaced</a><span></span>y</div>| }
+ it "replaces a string" do
+ expect(subject.send(:gsub_tag_content, input, 'a', &lambda{ |v| 'replaced' })).to eq(output)
+ end
+ context "for multiple tags" do
+ let(:input) { %Q|<body><h1>head</h1><a href="something">x</a><a href="anything">y</a></div>| }
+ let(:output) { %Q|<body><h1>head</h1><a href="something">replaced</a><a href="anything">replaced</a></div>| }
+ it "replaces a string" do
+ expect(subject.send(:gsub_tag_content, input, 'a', &lambda{ |v| 'replaced' })).to eq(output)
+ end
+ end
+ end
+ describe "#gsub_tag_attribute" do
+ let(:input) { %Q|<body><h1>head</h1><a href="something" data-title="x" data-body="x">x</a><span data-title="y">y</span></div>| }
+ let(:output) { %Q|<body><h1>head</h1><a href="something" data-title="replaced" data-body="x">x</a><span data-title="y">y</span></div>| }
+ it "replaces a string" do
+ expect(subject.send(:gsub_tag_attribute, input, 'a', 'data-title', &lambda{ |v| 'replaced' })).to eq(output)
+ end
+ context "for multiple tags" do
+ let(:input) { %Q|<body><h1>head</h1><a href="something" data-title="x" data-body="x">x</a><a href="anything" data-title="y">y</a></div>| }
+ let(:output) { %Q|<body><h1>head</h1><a href="something" data-title="replaced" data-body="x">x</a><a href="anything" data-title="replaced">y</a></div>| }
+ it "replaces a string" do
+ expect(subject.send(:gsub_tag_attribute, input, 'a', 'data-title', &lambda{ |v| 'replaced' })).to eq(output)
+ end
+ end
+ context "for single tag" do
+ let(:input) { %Q|<body><h1>head</h1><a href="something" data-title="x" data-body="x">x</a><span href="anything" data-title="y">y</span><img data-title="i"></div>| }
+ let(:output) { %Q|<body><h1>head</h1><a href="something" data-title="x" data-body="x">x</a><span href="anything" data-title="y">y</span><img data-title="replaced"></div>| }
+ it "replaces a string" do
+ expect(subject.send(:gsub_tag_attribute, input, 'img', 'data-title', &lambda{ |v| 'replaced' })).to eq(output)
+ end
+ end
+ context "for any tags" do
+ let(:input) { %Q|<body><h1>head</h1><a href="something" data-title="x" data-body="x">x</a><span href="anything" data-title="y">y</span></div>| }
+ let(:output) { %Q|<body><h1>head</h1><a href="something" data-title="replaced" data-body="x">x</a><span href="anything" data-title="replaced">y</span></div>| }
+ it "replaces a string" do
+ expect(subject.send(:gsub_tag_attribute, input, nil, 'data-title', &lambda{ |v| 'replaced' })).to eq(output)
+ end
+ end
+ context "with single quotations" do
+ let(:input) { %Q|<body><h1>head</h1><a href='something' data-title='x' data-body='x'>x</a><span data-title='y'>y</span></div>| }
+ let(:output) { %Q|<body><h1>head</h1><a href='something' data-title='replaced' data-body='x'>x</a><span data-title='y'>y</span></div>| }
+ it "replaces a string" do
+ expect(subject.send(:gsub_tag_attribute, input, 'a', 'data-title', &lambda{ |v| 'replaced' })).to eq(output)
+ end
+ end
+ end
end
end