require 'spec_helper' def attributes_to_sorted_array(src) Nokogiri::HTML::DocumentFragment.parse(src).children.first.attributes end module Deface describe Applicator do include_context "mock Rails.application" before { Dummy.all.clear } describe "with a single disabled override defined" do before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :remove => "p", :text => "
test
<%= raw(text) %>" } it "should return unmodified source" do expect(Dummy.apply(source, {:virtual_path => "posts/index"})).to eq("test
<%= raw(text) %>") end end describe "with a single :copy override defined" do before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :insert_after => "p", :copy => "h1") } let(:source) { "Hello
" } it "should return modified source" do expect(Dummy.apply(source, {:virtual_path => "posts/index"})).to eq("Hello
True that!
<% end %>Hello
" } it "should return modified source" do expect(Dummy.apply(source, {:virtual_path => "posts/index"})).to eq("<% if true %>True that!
<% end %>True that!
<% end %>Hello
") end end describe "with a single :cut override defined" do before { Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :insert_after => "p", :cut => "h1") } let(:source) { "Hello
" } it "should return modified source" do expect(Dummy.apply(source, {:virtual_path => "posts/index"})).to eq("Hello
True that!
<% end %>Hello
" } it "should return modified source" do expect(Dummy.apply(source, {:virtual_path => "posts/index"})).to eq("<% if true %>True that!
<% end %>Hello
") end end describe "with mulitple sequenced overrides defined" do before do Deface::Override.new(:virtual_path => "posts/index", :name => "third", :insert_after => "li:contains('second')", :text => "