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
expect(Dummy.apply(source, {:virtual_path => "posts/index"})).to eq("Argh!
")
expect(@override.failure).to be_falsy
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
expect(Dummy.apply(source, {:virtual_path => "posts/index"})).to eq("Argh!")
expect(@override.failure).to be_falsy
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
expect(Rails.logger).to receive(:info).with(/failed to match with end selector/)
expect(Dummy.apply(source, {:virtual_path => "posts/index"})).to eq(source)
expect(@override.failure).to be_truthy
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
expect(Rails.logger).to receive(:info).with(/failed to match with starting selector/)
expect(Dummy.apply(source, {:virtual_path => "posts/index"})).to eq(source)
expect(@override.failure).to be_truthy
end
end
end
end
end