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.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/Gemfile +3 -2
  4. data/README.markdown +3 -11
  5. data/deface.gemspec +4 -4
  6. data/lib/deface/applicator.rb +1 -1
  7. data/lib/deface/dsl/loader.rb +42 -34
  8. data/lib/deface/railtie.rb +2 -2
  9. data/lib/deface/slim_converter.rb +15 -0
  10. data/lib/deface/sources/copy.rb +1 -1
  11. data/lib/deface/sources/slim.rb +2 -2
  12. data/lib/deface/template_helper.rb +1 -1
  13. data/spec/deface/action_view_template_spec.rb +12 -12
  14. data/spec/deface/actions/add_to_attributes_spec.rb +8 -8
  15. data/spec/deface/actions/insert_after_spec.rb +1 -1
  16. data/spec/deface/actions/insert_before_spec.rb +1 -1
  17. data/spec/deface/actions/insert_bottom_spec.rb +2 -2
  18. data/spec/deface/actions/insert_top_spec.rb +2 -2
  19. data/spec/deface/actions/remove_from_attributes_spec.rb +9 -9
  20. data/spec/deface/actions/remove_spec.rb +2 -2
  21. data/spec/deface/actions/replace_contents_spec.rb +2 -2
  22. data/spec/deface/actions/replace_spec.rb +10 -10
  23. data/spec/deface/actions/set_attributes_spec.rb +11 -11
  24. data/spec/deface/actions/surround_contents_spec.rb +5 -5
  25. data/spec/deface/actions/surround_spec.rb +5 -5
  26. data/spec/deface/applicator_spec.rb +6 -6
  27. data/spec/deface/dsl/context_spec.rb +7 -7
  28. data/spec/deface/dsl/loader_spec.rb +74 -77
  29. data/spec/deface/environment_spec.rb +38 -38
  30. data/spec/deface/haml_converter_spec.rb +24 -24
  31. data/spec/deface/override_spec.rb +90 -90
  32. data/spec/deface/parser_spec.rb +54 -54
  33. data/spec/deface/precompiler_spec.rb +7 -7
  34. data/spec/deface/search_spec.rb +7 -7
  35. data/spec/deface/slim_converter_spec.rb +32 -0
  36. data/spec/deface/template_helper_spec.rb +21 -22
  37. data/spec/deface/utils/failure_finder_spec.rb +11 -11
  38. data/spec/spec_helper.rb +25 -17
  39. 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"}).should == "<%= raw(text) %>"
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"}).should == "<h2>I should be safe</h2><span>Before!</span><span>After!</span>"
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"}).should == "<p><h1>Argh!</h1></p>"
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"}).should == "<h1>start</h1><span>Argh!</span><h2>end</h2>"
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"}).should == "<h1>Argh!</h1>"
15
- @override.failure.should be_false
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"}).should == "<span>Argh!</span>"
25
- @override.failure.should be_false
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.should_receive(:info).with(/failed to match with end selector/)
35
- Dummy.apply(source, {:virtual_path => "posts/index"}).should == source
36
- @override.failure.should be_true
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.should_receive(:info).with(/failed to match with starting selector/)
46
- Dummy.apply(source, {:virtual_path => "posts/index"}).should == source
47
- @override.failure.should be_true
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.should == "pretty"
18
- attrs["alt"].value.should == "something interesting"
19
- attrs["src"].value.should == "path/to/button.png"
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.should == "pretty"
32
- attrs["alt"].value.should == "<%= something_interesting %>"
33
- attrs["src"].value.should == "path/to/button.png"
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.should == "<%= get_some_other_class %>"
46
- attrs["alt"].value.should == "something interesting"
47
- attrs["src"].value.should == "path/to/button.png"
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.should eq "path/to/button.png"
60
- tag.attributes['class'].value.should eq "<%= hello_world %>"
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"}).should == "<h4>yay!</h4><div><span><p>test</p></span></div>"
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"}).should == "<p><% if 1==1 %>test<% end %></p>"
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", '').should == "<div><h1>Start</h1><% if 1==1 %><h2>middle</h2><h3>child</h3><% end %><p><span>This is the</span> end.</p></div>"
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"}).should == "<p><% if 1==1 %>test<% else %>test<% end %></p>"
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", '').should == "<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>"
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"}).should == "<h1>It's behind you!</h1><div><p>test</p></div>"
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", '').should == "<span><% some_method('test') do %><p>test</p><% end %></span>"
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", '').should == "<span><% some_method('test') do %><h1>Start</h1><h2>middle</h2><p><span>This is the</span> end.</p><% end %></span>"
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"}).should == "<div><p>test</p></div><h1>It's behind you!</h1><div><p>test</p></div>"
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", '').should == "<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>"
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"}).should == "<p>test</p><%= raw(text) %>"
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"}).should == "<h1>World</h1><p>Hello</p><h1>World</h1>"
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"}).should == "<% if true %><p>True that!</p><% end %><h1>World</h1><% if true %><p>True that!</p><% end %><p>Hello</p>"
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"}).should == "<p>Hello</p><h1>World</h1>"
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"}).should == "<% if true %><p>True that!</p><% end %><p>Hello</p>"
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", "").should == "<ul><li>first</li><li>second</li><li>third</li></ul>"
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.should_receive(:new).with hash_including(expected_hash.reverse_merge(:name => 'sample_name'))
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.should_receive(:logger).and_return(logger)
42
- logger.should_receive(:error).with("\e[1;32mDeface: [WARNING]\e[0m Multiple action methods have been called. The last one will be used.")
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.stub_chain(:logger, :error)
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.should_receive(:logger).and_return(logger)
72
- logger.should_receive(:error).with("\e[1;32mDeface: [WARNING]\e[0m Multiple source methods have been called. The last one will be used.")
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.stub_chain(:logger, :error)
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
- lambda { Deface::DSL::Loader.load(filename) }.should_not raise_error(
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
- lambda { Deface::DSL::Loader.load(filename) }.should_not raise_error(
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
- lambda { Deface::DSL::Loader.load(filename) }.should_not raise_error(
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
- lambda { Deface::DSL::Loader.load(filename) }.should_not raise_error(
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
- lambda { Deface::DSL::Loader.load(filename) }.should raise_error(
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
- lambda { Deface::DSL::Loader.load(filename) }.should_not raise_error(
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
- lambda { Deface::DSL::Loader.load(filename) }.should raise_error(
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.should_receive(:open).with(filename).and_yield(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.should_receive(:new).with(override_name).
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.should_receive(:read).and_return(file_contents)
73
+ expect(file).to receive(:read).and_return(file_contents)
77
74
 
78
- context.should_receive(:virtual_path).with('path/to/view').ordered
79
- context.should_receive(:instance_eval).with(file_contents).ordered
80
- context.should_receive(:create_override).ordered
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.should_receive(:open).with(filename).and_yield(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.should_receive(:new).with(override_name).
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.should_receive(:read).and_return(file_contents)
93
+ expect(file).to receive(:read).and_return(file_contents)
97
94
 
98
- Deface::DSL::Loader.should_receive(:extract_dsl_commands_from_erb).
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.should_receive(:virtual_path).with('path/to/view').ordered
103
- context.should_receive(:instance_eval).with('dsl commands').ordered
104
- context.should_receive(:erb).with('erb').ordered
105
- context.should_receive(:create_override).ordered
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.should_receive(:open).with(filename).and_yield(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.should_receive(:new).with(override_name).
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.should_receive(:read).and_return(file_contents)
118
+ expect(file).to receive(:read).and_return(file_contents)
122
119
 
123
- Deface::DSL::Loader.should_receive(:extract_dsl_commands_from_haml).
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.should_receive(:virtual_path).with('path/to/view').ordered
128
- context.should_receive(:instance_eval).with('dsl commands').ordered
129
- context.should_receive(:haml).with('haml').ordered
130
- context.should_receive(:create_override).ordered
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.should_receive(:open).with(filename).and_yield(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.should_receive(:new).with(override_name).
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.should_receive(:read).and_return(file_contents)
143
+ expect(file).to receive(:read).and_return(file_contents)
147
144
 
148
- Deface::DSL::Loader.should_receive(:extract_dsl_commands_from_slim).
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.should_receive(:virtual_path).with('path/to/view').ordered
153
- context.should_receive(:instance_eval).with('dsl commands').ordered
154
- context.should_receive(:slim).with('slim').ordered
155
- context.should_receive(:create_override).ordered
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.should_receive(:register).with('deface', Deface::DSL::Loader)
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.should == "\ntest 'command'"
175
- the_rest.should == "<h1>Wow!</h1>"
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.should == "\ntest 'command'\nanother 'command'"
182
- the_rest.should == "<h1>Wow!</h1>"
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.should == ""
189
- the_rest.should == example
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.should == "\ntest 'command'\nanother 'command'"
196
- the_rest.should == "\n<h1>Wow!</h1>"
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.should == "\ntest 'command'\nanother 'command'"
203
- the_rest.should == "\n<h1>Wow!</h1>"
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.should == "\nreplace_contents 'h1 .title'\nclosing_selector \"div#intro\"\ndisabled\nnamespaced"
210
- the_rest.should == "<h1>Wow!</h1>"
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.should == "\nreplace_contents 'h1 .title'\nclosing_selector %q{div#intro}\ndisabled\nnamespaced"
217
- the_rest.should == "<h1>Wow!</h1>"
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.should == "\nreplace_contents 'h1 .title'\ndisabled\nsequence 2\nnamespaced"
224
- the_rest.should == "<h1>Wow!</h1>"
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.should == "\nadd_to_attributes 'h1 .title'\nattributes :class => 'pretty'"
231
- the_rest.should == "<h1>Wow!</h1>"
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.should == "test 'command'\nanother 'command'\n"
240
- the_rest.should == "%h1 Wow!"
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.should == "\ntest 'command'\nanother 'command'\n"
247
- the_rest.should == "%h1 Wow!"
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.should == ""
254
- the_rest.should == example
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.should == "test 'command'\nanother 'command'\n"
263
- the_rest.should == "h1 Wow!"
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.should == "\ntest 'command'\nanother 'command'\n"
270
- the_rest.should == "h1 Wow!"
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.should == ""
277
- the_rest.should == example
273
+ expect(dsl_commands).to eq ""
274
+ expect(the_rest).to eq example
278
275
  end
279
276
  end
280
277
  end