deface 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile +3 -2
- data/README.markdown +3 -11
- data/deface.gemspec +4 -4
- data/lib/deface/applicator.rb +1 -1
- data/lib/deface/dsl/loader.rb +42 -34
- data/lib/deface/railtie.rb +2 -2
- data/lib/deface/slim_converter.rb +15 -0
- data/lib/deface/sources/copy.rb +1 -1
- data/lib/deface/sources/slim.rb +2 -2
- data/lib/deface/template_helper.rb +1 -1
- data/spec/deface/action_view_template_spec.rb +12 -12
- data/spec/deface/actions/add_to_attributes_spec.rb +8 -8
- data/spec/deface/actions/insert_after_spec.rb +1 -1
- data/spec/deface/actions/insert_before_spec.rb +1 -1
- data/spec/deface/actions/insert_bottom_spec.rb +2 -2
- data/spec/deface/actions/insert_top_spec.rb +2 -2
- data/spec/deface/actions/remove_from_attributes_spec.rb +9 -9
- data/spec/deface/actions/remove_spec.rb +2 -2
- data/spec/deface/actions/replace_contents_spec.rb +2 -2
- data/spec/deface/actions/replace_spec.rb +10 -10
- data/spec/deface/actions/set_attributes_spec.rb +11 -11
- data/spec/deface/actions/surround_contents_spec.rb +5 -5
- data/spec/deface/actions/surround_spec.rb +5 -5
- data/spec/deface/applicator_spec.rb +6 -6
- data/spec/deface/dsl/context_spec.rb +7 -7
- data/spec/deface/dsl/loader_spec.rb +74 -77
- data/spec/deface/environment_spec.rb +38 -38
- data/spec/deface/haml_converter_spec.rb +24 -24
- data/spec/deface/override_spec.rb +90 -90
- data/spec/deface/parser_spec.rb +54 -54
- data/spec/deface/precompiler_spec.rb +7 -7
- data/spec/deface/search_spec.rb +7 -7
- data/spec/deface/slim_converter_spec.rb +32 -0
- data/spec/deface/template_helper_spec.rb +21 -22
- data/spec/deface/utils/failure_finder_spec.rb +11 -11
- data/spec/spec_helper.rb +25 -17
- metadata +33 -69
@@ -11,7 +11,7 @@ module Deface
|
|
11
11
|
let(:source) { "<p>test</p><%= raw(text) %>" }
|
12
12
|
|
13
13
|
it "should return modified source" do
|
14
|
-
Dummy.apply(source, {:virtual_path => "posts/index"}).
|
14
|
+
expect(Dummy.apply(source, {:virtual_path => "posts/index"})).to eq("<%= raw(text) %>")
|
15
15
|
end
|
16
16
|
|
17
17
|
end
|
@@ -21,7 +21,7 @@ module Deface
|
|
21
21
|
let(:source) { "<h2>I should be safe</h2><span>Before!</span><h1>start</h1><p>some junk</p><div>more junk</div><h2>end</h2><span>After!</span>" }
|
22
22
|
|
23
23
|
it "should return modified source" do
|
24
|
-
Dummy.apply(source, {:virtual_path => "posts/index"}).
|
24
|
+
expect(Dummy.apply(source, {:virtual_path => "posts/index"})).to eq("<h2>I should be safe</h2><span>Before!</span><span>After!</span>")
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
@@ -11,7 +11,7 @@ module Deface
|
|
11
11
|
let(:source) { "<p><span>Hello</span>I am not a <em>pirate</em></p>" }
|
12
12
|
|
13
13
|
it "should return modified source" do
|
14
|
-
Dummy.apply(source, {:virtual_path => "posts/index"}).
|
14
|
+
expect(Dummy.apply(source, {:virtual_path => "posts/index"})).to eq("<p><h1>Argh!</h1></p>")
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -20,7 +20,7 @@ module Deface
|
|
20
20
|
let(:source) { "<h1>start</h1><p>some junk</p><div>more junk</div><h2>end</h2>" }
|
21
21
|
|
22
22
|
it "should return modified source" do
|
23
|
-
Dummy.apply(source, {:virtual_path => "posts/index"}).
|
23
|
+
expect(Dummy.apply(source, {:virtual_path => "posts/index"})).to eq("<h1>start</h1><span>Argh!</span><h2>end</h2>")
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
@@ -11,8 +11,8 @@ module Deface
|
|
11
11
|
let(:source) { "<p>test</p>" }
|
12
12
|
|
13
13
|
it "should return modified source" do
|
14
|
-
Dummy.apply(source, {:virtual_path => "posts/index"}).
|
15
|
-
@override.failure.
|
14
|
+
expect(Dummy.apply(source, {:virtual_path => "posts/index"})).to eq("<h1>Argh!</h1>")
|
15
|
+
expect(@override.failure).to be_falsy
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -21,8 +21,8 @@ module Deface
|
|
21
21
|
let(:source) { "<h1>start</h1><p>some junk</p><div>more junk</div><h2>end</h2>" }
|
22
22
|
|
23
23
|
it "should return modified source" do
|
24
|
-
Dummy.apply(source, {:virtual_path => "posts/index"}).
|
25
|
-
@override.failure.
|
24
|
+
expect(Dummy.apply(source, {:virtual_path => "posts/index"})).to eq("<span>Argh!</span>")
|
25
|
+
expect(@override.failure).to be_falsy
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
@@ -31,9 +31,9 @@ module Deface
|
|
31
31
|
let(:source) { "<h1>start</h1><p>some junk</p><div>more junk</div><h2>end</h2>" }
|
32
32
|
|
33
33
|
it "should log error and return unmodified source" do
|
34
|
-
Rails.logger.
|
35
|
-
Dummy.apply(source, {:virtual_path => "posts/index"}).
|
36
|
-
@override.failure.
|
34
|
+
expect(Rails.logger).to receive(:info).with(/failed to match with end selector/)
|
35
|
+
expect(Dummy.apply(source, {:virtual_path => "posts/index"})).to eq(source)
|
36
|
+
expect(@override.failure).to be_truthy
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
@@ -42,9 +42,9 @@ module Deface
|
|
42
42
|
let(:source) { "<h1>start</h1><p>some junk</p><div>more junk</div><h2>end</h2>" }
|
43
43
|
|
44
44
|
it "should log error and return unmodified source" do
|
45
|
-
Rails.logger.
|
46
|
-
Dummy.apply(source, {:virtual_path => "posts/index"}).
|
47
|
-
@override.failure.
|
45
|
+
expect(Rails.logger).to receive(:info).with(/failed to match with starting selector/)
|
46
|
+
expect(Dummy.apply(source, {:virtual_path => "posts/index"})).to eq(source)
|
47
|
+
expect(@override.failure).to be_truthy
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
@@ -14,9 +14,9 @@ module Deface
|
|
14
14
|
it "should return modified source" do
|
15
15
|
attrs = attributes_to_sorted_array(Dummy.apply(source, {:virtual_path => "posts/index"}))
|
16
16
|
|
17
|
-
attrs["class"].value.
|
18
|
-
attrs["alt"].value.
|
19
|
-
attrs["src"].value.
|
17
|
+
expect(attrs["class"].value).to eq("pretty")
|
18
|
+
expect(attrs["alt"].value).to eq("something interesting")
|
19
|
+
expect(attrs["src"].value).to eq("path/to/button.png")
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
@@ -28,9 +28,9 @@ module Deface
|
|
28
28
|
it "should return modified source" do
|
29
29
|
attrs = attributes_to_sorted_array(Dummy.apply(source, {:virtual_path => "posts/index"}))
|
30
30
|
|
31
|
-
attrs["class"].value.
|
32
|
-
attrs["alt"].value.
|
33
|
-
attrs["src"].value.
|
31
|
+
expect(attrs["class"].value).to eq("pretty")
|
32
|
+
expect(attrs["alt"].value).to eq("<%= something_interesting %>")
|
33
|
+
expect(attrs["src"].value).to eq("path/to/button.png")
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
@@ -42,9 +42,9 @@ module Deface
|
|
42
42
|
it "should return modified source" do
|
43
43
|
attrs = attributes_to_sorted_array(Dummy.apply(source, {:virtual_path => "posts/index"}))
|
44
44
|
|
45
|
-
attrs["class"].value.
|
46
|
-
attrs["alt"].value.
|
47
|
-
attrs["src"].value.
|
45
|
+
expect(attrs["class"].value).to eq("<%= get_some_other_class %>")
|
46
|
+
expect(attrs["alt"].value).to eq("something interesting")
|
47
|
+
expect(attrs["src"].value).to eq("path/to/button.png")
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
@@ -56,8 +56,8 @@ module Deface
|
|
56
56
|
it "should return modified source" do
|
57
57
|
tag = Nokogiri::HTML::DocumentFragment.parse(Dummy.apply(source, {:virtual_path => "posts/index"}).gsub("\n", ""))
|
58
58
|
tag = tag.css('img').first
|
59
|
-
tag.attributes['src'].value.
|
60
|
-
tag.attributes['class'].value.
|
59
|
+
expect(tag.attributes['src'].value).to eq "path/to/button.png"
|
60
|
+
expect(tag.attributes['class'].value).to eq "<%= hello_world %>"
|
61
61
|
end
|
62
62
|
end
|
63
63
|
end
|
@@ -11,7 +11,7 @@ module Deface
|
|
11
11
|
let(:source) { "<h4>yay!</h4><div><p>test</p></div>" }
|
12
12
|
|
13
13
|
it "should return modified source" do
|
14
|
-
Dummy.apply(source, {:virtual_path => "posts/index"}).
|
14
|
+
expect(Dummy.apply(source, {:virtual_path => "posts/index"})).to eq("<h4>yay!</h4><div><span><p>test</p></span></div>")
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -20,7 +20,7 @@ module Deface
|
|
20
20
|
let(:source) { "<p>test</p>" }
|
21
21
|
|
22
22
|
it "should return modified source" do
|
23
|
-
Dummy.apply(source, {:virtual_path => "posts/index"}).
|
23
|
+
expect(Dummy.apply(source, {:virtual_path => "posts/index"})).to eq("<p><% if 1==1 %>test<% end %></p>")
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -30,7 +30,7 @@ module Deface
|
|
30
30
|
let(:source) { "<div><h1>Start</h1><h2>middle</h2><h3>child</h3><p><span>This is the</span> end.</p></div>" }
|
31
31
|
|
32
32
|
it "should return modified source" do
|
33
|
-
Dummy.apply(source, {:virtual_path => "posts/index"}).gsub("\n", '').
|
33
|
+
expect(Dummy.apply(source, {:virtual_path => "posts/index"}).gsub("\n", '')).to eq("<div><h1>Start</h1><% if 1==1 %><h2>middle</h2><h3>child</h3><% end %><p><span>This is the</span> end.</p></div>")
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
@@ -39,7 +39,7 @@ module Deface
|
|
39
39
|
let(:source) { "<p>test</p>" }
|
40
40
|
|
41
41
|
it "should return modified source" do
|
42
|
-
Dummy.apply(source, {:virtual_path => "posts/index"}).
|
42
|
+
expect(Dummy.apply(source, {:virtual_path => "posts/index"})).to eq("<p><% if 1==1 %>test<% else %>test<% end %></p>")
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
@@ -49,7 +49,7 @@ module Deface
|
|
49
49
|
let(:source) { "<div><h1>Start</h1><h2>middle</h2><h3>child</h3><p><span>This is the</span> end.</p></div>" }
|
50
50
|
|
51
51
|
it "should return modified source" do
|
52
|
-
Dummy.apply(source, {:virtual_path => "posts/index"}).gsub("\n", '').
|
52
|
+
expect(Dummy.apply(source, {:virtual_path => "posts/index"}).gsub("\n", '')).to eq("<div><h1>Start</h1><% if 1==1 %><h2>middle</h2><h3>child</h3><% else %><h2>middle</h2><h3>child</h3><% end %><p><span>This is the</span> end.</p></div>")
|
53
53
|
end
|
54
54
|
end
|
55
55
|
end
|
@@ -11,7 +11,7 @@ module Deface
|
|
11
11
|
let(:source) { "<p>test</p>" }
|
12
12
|
|
13
13
|
it "should return modified source" do
|
14
|
-
Dummy.apply(source, {:virtual_path => "posts/index"}).
|
14
|
+
expect(Dummy.apply(source, {:virtual_path => "posts/index"})).to eq("<h1>It's behind you!</h1><div><p>test</p></div>")
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -20,7 +20,7 @@ module Deface
|
|
20
20
|
let(:source) { "<span><p>test</p></span>" }
|
21
21
|
|
22
22
|
it "should return modified source" do
|
23
|
-
Dummy.apply(source, {:virtual_path => "posts/index"}).gsub("\n", '').
|
23
|
+
expect(Dummy.apply(source, {:virtual_path => "posts/index"}).gsub("\n", '')).to eq("<span><% some_method('test') do %><p>test</p><% end %></span>")
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -30,7 +30,7 @@ module Deface
|
|
30
30
|
let(:source) { "<span><h1>Start</h1><h2>middle</h2><p><span>This is the</span> end.</p></span>" }
|
31
31
|
|
32
32
|
it "should return modified source" do
|
33
|
-
Dummy.apply(source, {:virtual_path => "posts/index"}).gsub("\n", '').
|
33
|
+
expect(Dummy.apply(source, {:virtual_path => "posts/index"}).gsub("\n", '')).to eq("<span><% some_method('test') do %><h1>Start</h1><h2>middle</h2><p><span>This is the</span> end.</p><% end %></span>")
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
@@ -39,7 +39,7 @@ module Deface
|
|
39
39
|
let(:source) { "<p>test</p>" }
|
40
40
|
|
41
41
|
it "should return modified source" do
|
42
|
-
Dummy.apply(source, {:virtual_path => "posts/index"}).
|
42
|
+
expect(Dummy.apply(source, {:virtual_path => "posts/index"})).to eq("<div><p>test</p></div><h1>It's behind you!</h1><div><p>test</p></div>")
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
@@ -49,7 +49,7 @@ module Deface
|
|
49
49
|
let(:source) { "<span><h1>Start</h1><h2>middle</h2><p><span>This is the</span> end.</p></span>" }
|
50
50
|
|
51
51
|
it "should return modified source" do
|
52
|
-
Dummy.apply(source, {:virtual_path => "posts/index"}).gsub("\n", '').
|
52
|
+
expect(Dummy.apply(source, {:virtual_path => "posts/index"}).gsub("\n", '')).to eq("<span><% if true %><h1>Start</h1><h2>middle</h2><p><span>This is the</span> end.</p><% else %><h1>Start</h1><h2>middle</h2><p><span>This is the</span> end.</p><% end %></span>")
|
53
53
|
end
|
54
54
|
end
|
55
55
|
end
|
@@ -15,7 +15,7 @@ module Deface
|
|
15
15
|
|
16
16
|
|
17
17
|
it "should return unmodified source" do
|
18
|
-
Dummy.apply(source, {:virtual_path => "posts/index"}).
|
18
|
+
expect(Dummy.apply(source, {:virtual_path => "posts/index"})).to eq("<p>test</p><%= raw(text) %>")
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
@@ -25,7 +25,7 @@ module Deface
|
|
25
25
|
|
26
26
|
|
27
27
|
it "should return modified source" do
|
28
|
-
Dummy.apply(source, {:virtual_path => "posts/index"}).
|
28
|
+
expect(Dummy.apply(source, {:virtual_path => "posts/index"})).to eq("<h1>World</h1><p>Hello</p><h1>World</h1>")
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -36,7 +36,7 @@ module Deface
|
|
36
36
|
|
37
37
|
|
38
38
|
it "should return modified source" do
|
39
|
-
Dummy.apply(source, {:virtual_path => "posts/index"}).
|
39
|
+
expect(Dummy.apply(source, {:virtual_path => "posts/index"})).to eq("<% if true %><p>True that!</p><% end %><h1>World</h1><% if true %><p>True that!</p><% end %><p>Hello</p>")
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
@@ -46,7 +46,7 @@ module Deface
|
|
46
46
|
|
47
47
|
|
48
48
|
it "should return modified source" do
|
49
|
-
Dummy.apply(source, {:virtual_path => "posts/index"}).
|
49
|
+
expect(Dummy.apply(source, {:virtual_path => "posts/index"})).to eq("<p>Hello</p><h1>World</h1>")
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
@@ -57,7 +57,7 @@ module Deface
|
|
57
57
|
|
58
58
|
|
59
59
|
it "should return modified source" do
|
60
|
-
Dummy.apply(source, {:virtual_path => "posts/index"}).
|
60
|
+
expect(Dummy.apply(source, {:virtual_path => "posts/index"})).to eq("<% if true %><p>True that!</p><% end %><p>Hello</p>")
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
@@ -71,7 +71,7 @@ module Deface
|
|
71
71
|
let(:source) { "<ul><li>replaced</li></ul>" }
|
72
72
|
|
73
73
|
it "should return modified source" do
|
74
|
-
Dummy.apply(source, {:virtual_path => "posts/index"}).gsub("\n", "").
|
74
|
+
expect(Dummy.apply(source, {:virtual_path => "posts/index"}).gsub("\n", "")).to eq("<ul><li>first</li><li>second</li><li>third</li></ul>")
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
@@ -9,7 +9,7 @@ describe Deface::DSL::Context do
|
|
9
9
|
subject { context = Deface::DSL::Context.new('sample_name') }
|
10
10
|
|
11
11
|
def override_should_be_created_with(expected_hash)
|
12
|
-
Deface::Override.
|
12
|
+
expect(Deface::Override).to receive(:new).with hash_including(expected_hash.reverse_merge(:name => 'sample_name'))
|
13
13
|
|
14
14
|
subject.create_override
|
15
15
|
end
|
@@ -38,14 +38,14 @@ describe Deface::DSL::Context do
|
|
38
38
|
subject.insert_top('selector')
|
39
39
|
|
40
40
|
logger = double('logger')
|
41
|
-
Rails.
|
42
|
-
logger.
|
41
|
+
expect(Rails).to receive(:logger).and_return(logger)
|
42
|
+
expect(logger).to receive(:error).with("\e[1;32mDeface: [WARNING]\e[0m Multiple action methods have been called. The last one will be used.")
|
43
43
|
|
44
44
|
subject.insert_bottom('selector')
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'should use the last action that is specified' do
|
48
|
-
Rails.
|
48
|
+
allow(Rails).to receive_message_chain(:logger, :error)
|
49
49
|
|
50
50
|
subject.insert_top('insert_top/selector')
|
51
51
|
subject.insert_bottom('insert_bottom/selector')
|
@@ -68,14 +68,14 @@ describe Deface::DSL::Context do
|
|
68
68
|
subject.partial('partial name')
|
69
69
|
|
70
70
|
logger = double('logger')
|
71
|
-
Rails.
|
72
|
-
logger.
|
71
|
+
expect(Rails).to receive(:logger).and_return(logger)
|
72
|
+
expect(logger).to receive(:error).with("\e[1;32mDeface: [WARNING]\e[0m Multiple source methods have been called. The last one will be used.")
|
73
73
|
|
74
74
|
subject.template('template/path')
|
75
75
|
end
|
76
76
|
|
77
77
|
it 'should use the last source that is specified' do
|
78
|
-
Rails.
|
78
|
+
allow(Rails).to receive_message_chain(:logger, :error)
|
79
79
|
|
80
80
|
subject.partial('partial name')
|
81
81
|
subject.template('template/path')
|
@@ -4,44 +4,42 @@ require 'deface/dsl/loader'
|
|
4
4
|
|
5
5
|
describe Deface::DSL::Loader do
|
6
6
|
context '.load' do
|
7
|
+
before { allow(File).to receive(:open) }
|
8
|
+
|
7
9
|
context 'extension check' do
|
8
10
|
it 'should succeed if file ends with .deface' do
|
9
11
|
file = double('deface file')
|
10
|
-
filename = 'app/overrides/example_name.deface'
|
12
|
+
filename = 'app/overrides/my_view/example_name.deface'
|
11
13
|
|
12
|
-
|
13
|
-
"Deface::DSL does not know how to read 'app/overrides/example_name.deface'. Override files should end with just .deface, .html.erb.deface, .html.haml.deface or .html.slim.deface")
|
14
|
+
expect { Deface::DSL::Loader.load(filename) }.not_to raise_error
|
14
15
|
end
|
15
16
|
|
16
17
|
it 'should succeed if file ends with .html.erb.deface' do
|
17
18
|
file = double('deface file')
|
18
|
-
filename = 'app/overrides/example_name.html.erb.deface'
|
19
|
+
filename = 'app/overrides/my_view/example_name.html.erb.deface'
|
19
20
|
|
20
|
-
|
21
|
-
"Deface::DSL does not know how to read 'app/overrides/example_name.html.erb.deface'. Override files should end with just .deface, .html.erb.deface, .html.haml.deface or .html.slim.deface")
|
21
|
+
expect { Deface::DSL::Loader.load(filename) }.not_to raise_error
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'should succeed if file ends with .html.haml.deface' do
|
25
25
|
file = double('deface file')
|
26
|
-
filename = 'app/overrides/example_name.html.haml.deface'
|
26
|
+
filename = 'app/overrides/my_view/example_name.html.haml.deface'
|
27
27
|
|
28
|
-
|
29
|
-
"Deface::DSL does not know how to read 'app/overrides/example_name.html.haml.deface'. Override files should end with just .deface, .html.erb.deface, .html.haml.deface or .html.slim.deface")
|
28
|
+
expect { Deface::DSL::Loader.load(filename) }.not_to raise_error
|
30
29
|
end
|
31
30
|
|
32
31
|
it 'should succeed if file ends with .html.slim.deface' do
|
33
32
|
file = double('deface file')
|
34
|
-
filename = 'app/overrides/example_name.html.slim.deface'
|
33
|
+
filename = 'app/overrides/my_view/example_name.html.slim.deface'
|
35
34
|
|
36
|
-
|
37
|
-
"Deface::DSL does not know how to read 'app/overrides/example_name.html.slim.deface'. Override files should end with just .deface, .html.erb.deface, .html.haml.deface or .html.slim.deface")
|
35
|
+
expect { Deface::DSL::Loader.load(filename) }.not_to raise_error
|
38
36
|
end
|
39
37
|
|
40
38
|
it 'should fail if file ends with .blargh.deface' do
|
41
39
|
file = double('deface file')
|
42
40
|
filename = 'app/overrides/example_name.blargh.deface'
|
43
41
|
|
44
|
-
|
42
|
+
expect { Deface::DSL::Loader.load(filename) }.to raise_error(
|
45
43
|
"Deface::DSL does not know how to read 'app/overrides/example_name.blargh.deface'. Override files should end with just .deface, .html.erb.deface, .html.haml.deface or .html.slim.deface")
|
46
44
|
end
|
47
45
|
|
@@ -49,8 +47,7 @@ describe Deface::DSL::Loader do
|
|
49
47
|
file = double('deface file')
|
50
48
|
filename = 'app/overrides/parent.dir.with.dot/example_name.html.haml.deface'
|
51
49
|
|
52
|
-
|
53
|
-
"Deface::DSL does not know how to read 'app/overrides/parent.dir.with.dot/example_name.html.haml.deface'. Override files should end with just .deface, .html.erb.deface, .html.haml.deface or .html.slim.deface")
|
50
|
+
expect { Deface::DSL::Loader.load(filename) }.not_to raise_error
|
54
51
|
end
|
55
52
|
end
|
56
53
|
|
@@ -58,26 +55,26 @@ describe Deface::DSL::Loader do
|
|
58
55
|
file = double('html/erb/deface file')
|
59
56
|
filename = 'app/overrides/example_name.html.erb.deface'
|
60
57
|
|
61
|
-
|
58
|
+
expect { Deface::DSL::Loader.load(filename) }.to raise_error(
|
62
59
|
"Deface::DSL overrides must be in a sub-directory that matches the views virtual path. Move 'app/overrides/example_name.html.erb.deface' into a sub-directory.")
|
63
60
|
end
|
64
61
|
|
65
62
|
it 'should set the virtual_path for a .deface file in a directory below overrides' do
|
66
63
|
file = double('deface file')
|
67
64
|
filename = 'app/overrides/path/to/view/example_name.deface'
|
68
|
-
File.
|
65
|
+
expect(File).to receive(:open).with(filename).and_yield(file)
|
69
66
|
|
70
67
|
override_name = 'example_name'
|
71
68
|
context = double('dsl context')
|
72
|
-
Deface::DSL::Context.
|
69
|
+
expect(Deface::DSL::Context).to receive(:new).with(override_name).
|
73
70
|
and_return(context)
|
74
71
|
|
75
72
|
file_contents = double('file contents')
|
76
|
-
file.
|
73
|
+
expect(file).to receive(:read).and_return(file_contents)
|
77
74
|
|
78
|
-
context.
|
79
|
-
context.
|
80
|
-
context.
|
75
|
+
expect(context).to receive(:virtual_path).with('path/to/view').ordered
|
76
|
+
expect(context).to receive(:instance_eval).with(file_contents).ordered
|
77
|
+
expect(context).to receive(:create_override).ordered
|
81
78
|
|
82
79
|
Deface::DSL::Loader.load(filename)
|
83
80
|
end
|
@@ -85,24 +82,24 @@ describe Deface::DSL::Loader do
|
|
85
82
|
it 'should set the virtual_path for a .html.erb.deface file in a directory below overrides' do
|
86
83
|
file = double('html/erb/deface file')
|
87
84
|
filename = 'app/overrides/path/to/view/example_name.html.erb.deface'
|
88
|
-
File.
|
85
|
+
expect(File).to receive(:open).with(filename).and_yield(file)
|
89
86
|
|
90
87
|
override_name = 'example_name'
|
91
88
|
context = double('dsl context')
|
92
|
-
Deface::DSL::Context.
|
89
|
+
expect(Deface::DSL::Context).to receive(:new).with(override_name).
|
93
90
|
and_return(context)
|
94
91
|
|
95
92
|
file_contents = double('file contents')
|
96
|
-
file.
|
93
|
+
expect(file).to receive(:read).and_return(file_contents)
|
97
94
|
|
98
|
-
Deface::DSL::Loader.
|
95
|
+
expect(Deface::DSL::Loader).to receive(:extract_dsl_commands_from_erb).
|
99
96
|
with(file_contents).
|
100
97
|
and_return(['dsl commands', 'erb'])
|
101
98
|
|
102
|
-
context.
|
103
|
-
context.
|
104
|
-
context.
|
105
|
-
context.
|
99
|
+
expect(context).to receive(:virtual_path).with('path/to/view').ordered
|
100
|
+
expect(context).to receive(:instance_eval).with('dsl commands').ordered
|
101
|
+
expect(context).to receive(:erb).with('erb').ordered
|
102
|
+
expect(context).to receive(:create_override).ordered
|
106
103
|
|
107
104
|
Deface::DSL::Loader.load(filename)
|
108
105
|
end
|
@@ -110,24 +107,24 @@ describe Deface::DSL::Loader do
|
|
110
107
|
it 'should set the virtual_path for a .html.haml.deface file in a directory below overrides' do
|
111
108
|
file = double('html/haml/deface file')
|
112
109
|
filename = 'app/overrides/path/to/view/example_name.html.haml.deface'
|
113
|
-
File.
|
110
|
+
expect(File).to receive(:open).with(filename).and_yield(file)
|
114
111
|
|
115
112
|
override_name = 'example_name'
|
116
113
|
context = double('dsl context')
|
117
|
-
Deface::DSL::Context.
|
114
|
+
expect(Deface::DSL::Context).to receive(:new).with(override_name).
|
118
115
|
and_return(context)
|
119
116
|
|
120
117
|
file_contents = double('file contents')
|
121
|
-
file.
|
118
|
+
expect(file).to receive(:read).and_return(file_contents)
|
122
119
|
|
123
|
-
Deface::DSL::Loader.
|
120
|
+
expect(Deface::DSL::Loader).to receive(:extract_dsl_commands_from_haml).
|
124
121
|
with(file_contents).
|
125
122
|
and_return(['dsl commands', 'haml'])
|
126
123
|
|
127
|
-
context.
|
128
|
-
context.
|
129
|
-
context.
|
130
|
-
context.
|
124
|
+
expect(context).to receive(:virtual_path).with('path/to/view').ordered
|
125
|
+
expect(context).to receive(:instance_eval).with('dsl commands').ordered
|
126
|
+
expect(context).to receive(:haml).with('haml').ordered
|
127
|
+
expect(context).to receive(:create_override).ordered
|
131
128
|
|
132
129
|
Deface::DSL::Loader.load(filename)
|
133
130
|
end
|
@@ -135,24 +132,24 @@ describe Deface::DSL::Loader do
|
|
135
132
|
it 'should set the virtual_path for a .html.slim.deface file in a directory below overrides' do
|
136
133
|
file = double('html/slim/deface file')
|
137
134
|
filename = 'app/overrides/path/to/view/example_name.html.slim.deface'
|
138
|
-
File.
|
135
|
+
expect(File).to receive(:open).with(filename).and_yield(file)
|
139
136
|
|
140
137
|
override_name = 'example_name'
|
141
138
|
context = double('dsl context')
|
142
|
-
Deface::DSL::Context.
|
139
|
+
expect(Deface::DSL::Context).to receive(:new).with(override_name).
|
143
140
|
and_return(context)
|
144
141
|
|
145
142
|
file_contents = double('file contents')
|
146
|
-
file.
|
143
|
+
expect(file).to receive(:read).and_return(file_contents)
|
147
144
|
|
148
|
-
Deface::DSL::Loader.
|
145
|
+
expect(Deface::DSL::Loader).to receive(:extract_dsl_commands_from_slim).
|
149
146
|
with(file_contents).
|
150
147
|
and_return(['dsl commands', 'slim'])
|
151
148
|
|
152
|
-
context.
|
153
|
-
context.
|
154
|
-
context.
|
155
|
-
context.
|
149
|
+
expect(context).to receive(:virtual_path).with('path/to/view').ordered
|
150
|
+
expect(context).to receive(:instance_eval).with('dsl commands').ordered
|
151
|
+
expect(context).to receive(:slim).with('slim').ordered
|
152
|
+
expect(context).to receive(:create_override).ordered
|
156
153
|
|
157
154
|
Deface::DSL::Loader.load(filename)
|
158
155
|
end
|
@@ -161,7 +158,7 @@ describe Deface::DSL::Loader do
|
|
161
158
|
|
162
159
|
context '.register' do
|
163
160
|
it 'should register the deface extension with the polyglot library' do
|
164
|
-
Polyglot.
|
161
|
+
expect(Polyglot).to receive(:register).with('deface', Deface::DSL::Loader)
|
165
162
|
|
166
163
|
Deface::DSL::Loader.register
|
167
164
|
end
|
@@ -171,64 +168,64 @@ describe Deface::DSL::Loader do
|
|
171
168
|
it 'should work in the simplest case' do
|
172
169
|
example = "<!-- test 'command' --><h1>Wow!</h1>"
|
173
170
|
dsl_commands, the_rest = Deface::DSL::Loader.extract_dsl_commands_from_erb(example)
|
174
|
-
dsl_commands.
|
175
|
-
the_rest.
|
171
|
+
expect(dsl_commands).to eq "\ntest 'command'"
|
172
|
+
expect(the_rest).to eq "<h1>Wow!</h1>"
|
176
173
|
end
|
177
174
|
|
178
175
|
it 'should combine multiple comments' do
|
179
176
|
example = "<!-- test 'command' --><!-- another 'command' --><h1>Wow!</h1>"
|
180
177
|
dsl_commands, the_rest = Deface::DSL::Loader.extract_dsl_commands_from_erb(example)
|
181
|
-
dsl_commands.
|
182
|
-
the_rest.
|
178
|
+
expect(dsl_commands).to eq "\ntest 'command'\nanother 'command'"
|
179
|
+
expect(the_rest).to eq "<h1>Wow!</h1>"
|
183
180
|
end
|
184
181
|
|
185
182
|
it 'should leave internal comments alone' do
|
186
183
|
example = "<br/><!-- test 'command' --><!-- another 'command' --><h1>Wow!</h1>"
|
187
184
|
dsl_commands, the_rest = Deface::DSL::Loader.extract_dsl_commands_from_erb(example)
|
188
|
-
dsl_commands.
|
189
|
-
the_rest.
|
185
|
+
expect(dsl_commands).to eq ""
|
186
|
+
expect(the_rest).to eq example
|
190
187
|
end
|
191
188
|
|
192
189
|
it 'should work with comments on own lines' do
|
193
190
|
example = "<!-- test 'command' -->\n<!-- another 'command' -->\n<h1>Wow!</h1>"
|
194
191
|
dsl_commands, the_rest = Deface::DSL::Loader.extract_dsl_commands_from_erb(example)
|
195
|
-
dsl_commands.
|
196
|
-
the_rest.
|
192
|
+
expect(dsl_commands).to eq "\ntest 'command'\nanother 'command'"
|
193
|
+
expect(the_rest).to eq "\n<h1>Wow!</h1>"
|
197
194
|
end
|
198
195
|
|
199
196
|
it 'should work with newlines inside the comment' do
|
200
197
|
example = "<!--\n test 'command'\nanother 'command'\n -->\n<h1>Wow!</h1>"
|
201
198
|
dsl_commands, the_rest = Deface::DSL::Loader.extract_dsl_commands_from_erb(example)
|
202
|
-
dsl_commands.
|
203
|
-
the_rest.
|
199
|
+
expect(dsl_commands).to eq "\ntest 'command'\nanother 'command'"
|
200
|
+
expect(the_rest).to eq "\n<h1>Wow!</h1>"
|
204
201
|
end
|
205
202
|
|
206
203
|
it 'should work with multiple commands on one line' do
|
207
204
|
example = %q{<!-- replace_contents 'h1 .title' closing_selector "div#intro" disabled namespaced --><h1>Wow!</h1>}
|
208
205
|
dsl_commands, the_rest = Deface::DSL::Loader.extract_dsl_commands_from_erb(example)
|
209
|
-
dsl_commands.
|
210
|
-
the_rest.
|
206
|
+
expect(dsl_commands).to eq "\nreplace_contents 'h1 .title'\nclosing_selector \"div#intro\"\ndisabled\nnamespaced"
|
207
|
+
expect(the_rest).to eq "<h1>Wow!</h1>"
|
211
208
|
end
|
212
209
|
|
213
210
|
it 'should work with multiple commands on one line when command argument is not a normal string' do
|
214
211
|
example = %q{<!-- replace_contents 'h1 .title' closing_selector %q{div#intro} disabled namespaced --><h1>Wow!</h1>}
|
215
212
|
dsl_commands, the_rest = Deface::DSL::Loader.extract_dsl_commands_from_erb(example)
|
216
|
-
dsl_commands.
|
217
|
-
the_rest.
|
213
|
+
expect(dsl_commands).to eq "\nreplace_contents 'h1 .title'\nclosing_selector %q{div#intro}\ndisabled\nnamespaced"
|
214
|
+
expect(the_rest).to eq "<h1>Wow!</h1>"
|
218
215
|
end
|
219
216
|
|
220
217
|
it 'should work with multiple commands on one line when command argument is an integer' do
|
221
218
|
example = %q{<!-- replace_contents 'h1 .title' disabled sequence 2 namespaced --><h1>Wow!</h1>}
|
222
219
|
dsl_commands, the_rest = Deface::DSL::Loader.extract_dsl_commands_from_erb(example)
|
223
|
-
dsl_commands.
|
224
|
-
the_rest.
|
220
|
+
expect(dsl_commands).to eq "\nreplace_contents 'h1 .title'\ndisabled\nsequence 2\nnamespaced"
|
221
|
+
expect(the_rest).to eq "<h1>Wow!</h1>"
|
225
222
|
end
|
226
223
|
|
227
224
|
it 'should work with multiple commands on one line when command argument is a hash' do
|
228
225
|
example = %q{<!-- add_to_attributes 'h1 .title' attributes :class => 'pretty'--><h1>Wow!</h1>}
|
229
226
|
dsl_commands, the_rest = Deface::DSL::Loader.extract_dsl_commands_from_erb(example)
|
230
|
-
dsl_commands.
|
231
|
-
the_rest.
|
227
|
+
expect(dsl_commands).to eq "\nadd_to_attributes 'h1 .title'\nattributes :class => 'pretty'"
|
228
|
+
expect(the_rest).to eq "<h1>Wow!</h1>"
|
232
229
|
end
|
233
230
|
end
|
234
231
|
|
@@ -236,22 +233,22 @@ describe Deface::DSL::Loader do
|
|
236
233
|
it 'should work in the simplest case' do
|
237
234
|
example = "/ test 'command'\n/ another 'command'\n%h1 Wow!"
|
238
235
|
dsl_commands, the_rest = Deface::DSL::Loader.extract_dsl_commands_from_haml(example)
|
239
|
-
dsl_commands.
|
240
|
-
the_rest.
|
236
|
+
expect(dsl_commands).to eq "test 'command'\nanother 'command'\n"
|
237
|
+
expect(the_rest).to eq "%h1 Wow!"
|
241
238
|
end
|
242
239
|
|
243
240
|
it 'should work with a block style comment using spaces' do
|
244
241
|
example = "/\n test 'command'\n another 'command'\n%h1 Wow!"
|
245
242
|
dsl_commands, the_rest = Deface::DSL::Loader.extract_dsl_commands_from_haml(example)
|
246
|
-
dsl_commands.
|
247
|
-
the_rest.
|
243
|
+
expect(dsl_commands).to eq "\ntest 'command'\nanother 'command'\n"
|
244
|
+
expect(the_rest).to eq "%h1 Wow!"
|
248
245
|
end
|
249
246
|
|
250
247
|
it 'should leave internal comments alone' do
|
251
248
|
example = "%br\n/ test 'command'\n/ another 'command'\n%h1 Wow!"
|
252
249
|
dsl_commands, the_rest = Deface::DSL::Loader.extract_dsl_commands_from_erb(example)
|
253
|
-
dsl_commands.
|
254
|
-
the_rest.
|
250
|
+
expect(dsl_commands).to eq ""
|
251
|
+
expect(the_rest).to eq example
|
255
252
|
end
|
256
253
|
end
|
257
254
|
|
@@ -259,22 +256,22 @@ describe Deface::DSL::Loader do
|
|
259
256
|
it 'should work in the simplest case' do
|
260
257
|
example = "/ test 'command'\n/ another 'command'\nh1 Wow!"
|
261
258
|
dsl_commands, the_rest = Deface::DSL::Loader.extract_dsl_commands_from_slim(example)
|
262
|
-
dsl_commands.
|
263
|
-
the_rest.
|
259
|
+
expect(dsl_commands).to eq "test 'command'\nanother 'command'\n"
|
260
|
+
expect(the_rest).to eq "h1 Wow!"
|
264
261
|
end
|
265
262
|
|
266
263
|
it 'should work with a block style comment using spaces' do
|
267
264
|
example = "/\n test 'command'\n another 'command'\nh1 Wow!"
|
268
265
|
dsl_commands, the_rest = Deface::DSL::Loader.extract_dsl_commands_from_slim(example)
|
269
|
-
dsl_commands.
|
270
|
-
the_rest.
|
266
|
+
expect(dsl_commands).to eq "\ntest 'command'\nanother 'command'\n"
|
267
|
+
expect(the_rest).to eq "h1 Wow!"
|
271
268
|
end
|
272
269
|
|
273
270
|
it 'should leave internal comments alone' do
|
274
271
|
example = "br\n/ test 'command'\n/ another 'command'\nh1 Wow!"
|
275
272
|
dsl_commands, the_rest = Deface::DSL::Loader.extract_dsl_commands_from_erb(example)
|
276
|
-
dsl_commands.
|
277
|
-
the_rest.
|
273
|
+
expect(dsl_commands).to eq ""
|
274
|
+
expect(the_rest).to eq example
|
278
275
|
end
|
279
276
|
end
|
280
277
|
end
|