require 'spec_helper' module Deface module Actions describe Replace do include_context "mock Rails.application" before { Dummy.all.clear } describe "with a single replace override defined" do before { @override = Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :replace => "p", :text => "

Argh!

") } let(:source) { "

test

" } it "should return modified source" do Dummy.apply(source, {:virtual_path => "posts/index"}).should == "

Argh!

" @override.failure.should be_false end end describe "with a single replace override with closing_selector defined" do before { @override = Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :replace => "h1", :closing_selector => "h2", :text => "Argh!") } let(:source) { "

start

some junk

more junk

end

" } it "should return modified source" do Dummy.apply(source, {:virtual_path => "posts/index"}).should == "Argh!" @override.failure.should be_false end end describe "with a single replace override with bad closing_selector defined" do before { @override = Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :replace => "h1", :closing_selector => "h3", :text => "Argh!") } let(:source) { "

start

some junk

more junk

end

" } it "should log error and return unmodified source" do Rails.logger.should_receive(:info).with(/failed to match with end selector/) Dummy.apply(source, {:virtual_path => "posts/index"}).should == source @override.failure.should be_true end end describe "with a single replace override with bad selector defined" do before { @override = Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :replace => "h3", :closing_selector => "h2", :text => "Argh!") } let(:source) { "

start

some junk

more junk

end

" } it "should log error and return unmodified source" do Rails.logger.should_receive(:info).with(/failed to match with starting selector/) Dummy.apply(source, {:virtual_path => "posts/index"}).should == source @override.failure.should be_true end end end end end