deface 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -7,15 +7,15 @@ module Deface
7
7
 
8
8
  describe "#convert" do
9
9
  it "should parse html fragment" do
10
- Deface::Parser.convert("<h1>Hello</h1>").should be_an_instance_of(Nokogiri::HTML::DocumentFragment)
11
- Deface::Parser.convert("<h1>Hello</h1>").to_s.should == "<h1>Hello</h1>"
12
- Deface::Parser.convert("<title>Hello</title>").should be_an_instance_of(Nokogiri::HTML::DocumentFragment)
13
- Deface::Parser.convert("<title>Hello</title>").to_s.should == "<title>Hello</title>"
10
+ expect(Deface::Parser.convert("<h1>Hello</h1>")).to be_an_instance_of(Nokogiri::HTML::DocumentFragment)
11
+ expect(Deface::Parser.convert("<h1>Hello</h1>").to_s).to eq("<h1>Hello</h1>")
12
+ expect(Deface::Parser.convert("<title>Hello</title>")).to be_an_instance_of(Nokogiri::HTML::DocumentFragment)
13
+ expect(Deface::Parser.convert("<title>Hello</title>").to_s).to eq("<title>Hello</title>")
14
14
  end
15
15
 
16
16
  it "should parse html document" do
17
17
  parsed = Deface::Parser.convert("<html><head><title>Hello</title></head><body>test</body>")
18
- parsed.should be_an_instance_of(Nokogiri::HTML::Document)
18
+ expect(parsed).to be_an_instance_of(Nokogiri::HTML::Document)
19
19
  parsed = parsed.to_s.split("\n")
20
20
 
21
21
  unless RUBY_PLATFORM == 'java'
@@ -24,15 +24,15 @@ module Deface
24
24
 
25
25
  #accounting for qwerks in Nokogir between ruby versions / platforms
26
26
  if RUBY_PLATFORM == 'java'
27
- parsed.should == ["<html><head><title>Hello</title></head><body>test</body></html>"]
27
+ expect(parsed).to eq(["<html><head><title>Hello</title></head><body>test</body></html>"])
28
28
  elsif RUBY_VERSION < "1.9"
29
- parsed.should == "<html>\n<head><title>Hello</title></head>\n<body>test</body>\n</html>".split("\n")
29
+ expect(parsed).to eq("<html>\n<head><title>Hello</title></head>\n<body>test</body>\n</html>".split("\n"))
30
30
  else
31
- parsed.should == "<html>\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n<title>Hello</title>\n</head>\n<body>test</body>\n</html>".split("\n")
31
+ expect(parsed).to eq("<html>\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n<title>Hello</title>\n</head>\n<body>test</body>\n</html>".split("\n"))
32
32
  end
33
33
 
34
34
  parsed = Deface::Parser.convert("<html><title>test</title></html>")
35
- parsed.should be_an_instance_of(Nokogiri::HTML::Document)
35
+ expect(parsed).to be_an_instance_of(Nokogiri::HTML::Document)
36
36
  parsed = parsed.to_s.split("\n")
37
37
 
38
38
  unless RUBY_PLATFORM == 'java'
@@ -41,88 +41,88 @@ module Deface
41
41
 
42
42
  #accounting for qwerks in Nokogir between ruby versions / platforms
43
43
  if RUBY_VERSION < "1.9" || RUBY_PLATFORM == 'java'
44
- parsed.should == ["<html><head><title>test</title></head></html>"]
44
+ expect(parsed).to eq(["<html><head><title>test</title></head></html>"])
45
45
  else
46
- parsed.should == "<html><head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n<title>test</title>\n</head></html>".split("\n")
46
+ expect(parsed).to eq("<html><head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n<title>test</title>\n</head></html>".split("\n"))
47
47
  end
48
48
 
49
49
  parsed = Deface::Parser.convert("<html><p>test</p></html>")
50
- parsed.should be_an_instance_of(Nokogiri::HTML::Document)
50
+ expect(parsed).to be_an_instance_of(Nokogiri::HTML::Document)
51
51
  parsed = parsed.to_s.split("\n")
52
52
 
53
53
  if RUBY_PLATFORM == 'java'
54
- parsed.should eq ["<html><head></head><body><p>test</p></body></html>"]
54
+ expect(parsed).to eq ["<html><head></head><body><p>test</p></body></html>"]
55
55
  else
56
56
  parsed = parsed[1..-1]
57
- parsed.should eq ["<html><body><p>test</p></body></html>"]
57
+ expect(parsed).to eq ["<html><body><p>test</p></body></html>"]
58
58
  end
59
59
  end
60
60
 
61
61
  # Regression test for #84, #100
62
62
  it "should parse html document with erb in the head" do
63
63
  parsed = Deface::Parser.convert("<html><head><%= method_name %></head><body></body></html>")
64
- parsed.should be_an_instance_of(Nokogiri::HTML::Document)
64
+ expect(parsed).to be_an_instance_of(Nokogiri::HTML::Document)
65
65
  parsed = parsed.to_s.split("\n")
66
66
 
67
67
  if RUBY_PLATFORM == 'java'
68
- parsed.should == ["<html><head><erb loud=\"\"> method_name </erb></head><body></body></html>"]
68
+ expect(parsed).to eq(["<html><head><erb loud=\"\"> method_name </erb></head><body></body></html>"])
69
69
  else
70
70
  parsed = parsed[1..-1]
71
- parsed.should == "<html>\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n<erb loud> method_name </erb>\n</head>\n<body></body>\n</html>".split("\n")
71
+ expect(parsed).to eq("<html>\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n<erb loud> method_name </erb>\n</head>\n<body></body>\n</html>".split("\n"))
72
72
  end
73
73
  end
74
74
 
75
75
  it "should parse body tag" do
76
76
  tag = Deface::Parser.convert("<body id=\"body\" <%= something %>>test</body>")
77
- tag.should be_an_instance_of(Nokogiri::XML::Element)
78
- tag.text.should eq 'test'
79
- tag.attributes['id'].value.should eq 'body'
80
- tag.attributes['data-erb-0'].value.should eq '<%= something %>'
77
+ expect(tag).to be_an_instance_of(Nokogiri::XML::Element)
78
+ expect(tag.text).to eq 'test'
79
+ expect(tag.attributes['id'].value).to eq 'body'
80
+ expect(tag.attributes['data-erb-0'].value).to eq '<%= something %>'
81
81
  end
82
82
 
83
83
  it "should convert <% ... %>" do
84
84
  tag = Deface::Parser.convert("<% method_name %>")
85
85
  tag = tag.css('erb').first
86
- tag.attributes['silent'].value.should eq ''
86
+ expect(tag.attributes['silent'].value).to eq ''
87
87
  end
88
88
 
89
89
  it "should convert <%= ... %>" do
90
90
  tag = Deface::Parser.convert("<%= method_name %>")
91
91
  tag = tag.css('erb').first
92
- tag.attributes['loud'].value.should eq ''
92
+ expect(tag.attributes['loud'].value).to eq ''
93
93
  end
94
94
 
95
95
  it "should convert first <% ... %> inside html tag" do
96
- Deface::Parser.convert("<p <% method_name %>></p>").to_s.should == "<p data-erb-0=\"&lt;% method_name %&gt;\"></p>"
96
+ expect(Deface::Parser.convert("<p <% method_name %>></p>").to_s).to eq("<p data-erb-0=\"&lt;% method_name %&gt;\"></p>")
97
97
  end
98
98
 
99
99
  it "should convert second <% ... %> inside html tag" do
100
- Deface::Parser.convert("<p <% method_name %> <% x = y %>></p>").to_s.should == "<p data-erb-0=\"&lt;% method_name %&gt;\" data-erb-1=\"&lt;% x = y %&gt;\"></p>"
100
+ expect(Deface::Parser.convert("<p <% method_name %> <% x = y %>></p>").to_s).to eq("<p data-erb-0=\"&lt;% method_name %&gt;\" data-erb-1=\"&lt;% x = y %&gt;\"></p>")
101
101
  end
102
102
 
103
103
  it "should convert <% ... %> inside double quoted attr value" do
104
- Deface::Parser.convert("<p id=\"<% method_name %>\"></p>").to_s.should == "<p data-erb-id=\"&lt;% method_name %&gt;\"></p>"
104
+ expect(Deface::Parser.convert("<p id=\"<% method_name %>\"></p>").to_s).to eq("<p data-erb-id=\"&lt;% method_name %&gt;\"></p>")
105
105
  end
106
106
 
107
107
  if RUBY_PLATFORM == 'java'
108
108
  it "should convert <% ... %> contains double quoted value" do
109
- Deface::Parser.convert("<p <% method_name \"test\" %>></p>").to_s.should == "<p data-erb-0=\"&lt;% method_name %22test%22 %&gt;\"></p>"
109
+ expect(Deface::Parser.convert("<p <% method_name \"test\" %>></p>").to_s).to eq("<p data-erb-0=\"&lt;% method_name %22test%22 %&gt;\"></p>")
110
110
  end
111
111
  end
112
112
 
113
113
  it "should convert <% ... %> inside single quoted attr value" do
114
- Deface::Parser.convert("<p id='<% method_name %>'></p>").to_s.should == "<p data-erb-id=\"&lt;% method_name %&gt;\"></p>"
114
+ expect(Deface::Parser.convert("<p id='<% method_name %>'></p>").to_s).to eq("<p data-erb-id=\"&lt;% method_name %&gt;\"></p>")
115
115
  end
116
116
 
117
117
  it "should convert <% ... %> inside non-quoted attr value" do
118
118
  tag = Deface::Parser.convert("<p id=<% method_name %>></p>")
119
119
  tag = tag.css('p').first
120
- tag.attributes['data-erb-id'].value.should eq '<% method_name %>'
120
+ expect(tag.attributes['data-erb-id'].value).to eq '<% method_name %>'
121
121
 
122
122
  tag = Deface::Parser.convert("<p id=<% method_name %> alt=\"test\"></p>")
123
123
  tag = tag.css('p').first
124
- tag.attributes['data-erb-id'].value.should eq '<% method_name %>'
125
- tag.attributes['alt'].value.should eq 'test'
124
+ expect(tag.attributes['data-erb-id'].value).to eq '<% method_name %>'
125
+ expect(tag.attributes['alt'].value).to eq 'test'
126
126
  end
127
127
 
128
128
  it "should convert multiple <% ... %> inside html tag" do
@@ -130,88 +130,88 @@ module Deface
130
130
  \"2\" %>" title='<% method_name %>' <%= other_method %></p>})
131
131
 
132
132
  tag = tag.css('p').first
133
- tag.attributes['data-erb-0'].value.should == "<%= method_name %>"
134
- tag.attributes['data-erb-1'].value.should == "<%= other_method %>"
135
- tag.attributes['data-erb-alt'].value.should == "<% x = 'y' + \n \\\"2\\\" %>"
136
- tag.attributes['data-erb-title'].value.should == "<% method_name %>"
133
+ expect(tag.attributes['data-erb-0'].value).to eq("<%= method_name %>")
134
+ expect(tag.attributes['data-erb-1'].value).to eq("<%= other_method %>")
135
+ expect(tag.attributes['data-erb-alt'].value).to eq("<% x = 'y' + \n \\\"2\\\" %>")
136
+ expect(tag.attributes['data-erb-title'].value).to eq("<% method_name %>")
137
137
  end
138
138
 
139
139
  it "should convert <%= ... %> including href attribute" do
140
140
  tag = Deface::Parser.convert(%(<a href="<%= x 'y' + "z" %>">A Link</a>))
141
141
  tag = tag.css('a').first
142
- tag.attributes['data-erb-href'].value.should eq "<%= x 'y' + \"z\" %>"
143
- tag.text.should eq 'A Link'
142
+ expect(tag.attributes['data-erb-href'].value).to eq "<%= x 'y' + \"z\" %>"
143
+ expect(tag.text).to eq 'A Link'
144
144
  end
145
145
 
146
146
  it "should escape contents erb tags" do
147
147
  tag = Deface::Parser.convert("<% method_name :key => 'value' %>")
148
148
  tag = tag.css('erb').first
149
- tag.attributes.key?('silent').should be_true
150
- tag.text.should eq " method_name :key => 'value' "
149
+ expect(tag.attributes.key?('silent')).to be_truthy
150
+ expect(tag.text).to eq " method_name :key => 'value' "
151
151
  end
152
152
 
153
153
  it "should handle round brackets in erb tags" do
154
154
  # commented out line below will fail as : adjacent to ( causes Nokogiri parser issue on jruby
155
155
  tag = Deface::Parser.convert("<% method_name(:key => 'value') %>")
156
156
  tag = tag.css('erb').first
157
- tag.attributes.key?('silent').should be_true
158
- tag.text.should eq " method_name(:key => 'value') "
157
+ expect(tag.attributes.key?('silent')).to be_truthy
158
+ expect(tag.text).to eq " method_name(:key => 'value') "
159
159
 
160
160
  tag = Deface::Parser.convert("<% method_name( :key => 'value' ) %>")
161
161
  tag = tag.css('erb').first
162
- tag.attributes.key?('silent').should be_true
163
- tag.text.should eq " method_name( :key => 'value' ) "
162
+ expect(tag.attributes.key?('silent')).to be_truthy
163
+ expect(tag.text).to eq " method_name( :key => 'value' ) "
164
164
  end
165
165
 
166
166
  it "should respect valid encoding tag" do
167
167
  source = %q{<%# encoding: ISO-8859-1 %>Can you say ümlaut?}
168
168
  Deface::Parser.convert(source)
169
- source.encoding.name.should == 'ISO-8859-1'
169
+ expect(source.encoding.name).to eq('ISO-8859-1')
170
170
  end
171
171
 
172
172
  it "should force default encoding" do
173
173
  source = %q{Can you say ümlaut?}
174
174
  source.force_encoding('ISO-8859-1')
175
175
  Deface::Parser.convert(source)
176
- source.encoding.should == Encoding.default_external
176
+ expect(source.encoding).to eq(Encoding.default_external)
177
177
  end
178
178
 
179
179
  it "should force default encoding" do
180
180
  source = %q{<%# encoding: US-ASCII %>Can you say ümlaut?}
181
- lambda { Deface::Parser.convert(source) }.should raise_error(ActionView::WrongEncodingError)
181
+ expect { Deface::Parser.convert(source) }.to raise_error(ActionView::WrongEncodingError)
182
182
  end
183
183
  end
184
184
 
185
185
  describe "#undo_erb_markup" do
186
186
  it "should revert <erb silent>" do
187
- Deface::Parser.undo_erb_markup!("<erb silent> method_name </erb>").should == "<% method_name %>"
187
+ expect(Deface::Parser.undo_erb_markup!("<erb silent> method_name </erb>")).to eq("<% method_name %>")
188
188
  end
189
189
 
190
190
  it "should revert <erb loud>" do
191
- Deface::Parser.undo_erb_markup!("<erb loud> method_name </erb>").should == "<%= method_name %>"
191
+ expect(Deface::Parser.undo_erb_markup!("<erb loud> method_name </erb>")).to eq("<%= method_name %>")
192
192
  end
193
193
 
194
194
  it "should revert data-erb-x attrs inside html tag" do
195
- Deface::Parser.undo_erb_markup!("<p data-erb-0=\"&lt;% method_name %&gt;\" data-erb-1=\"&lt;% x = y %&gt;\"></p>").should == "<p <% method_name %> <% x = y %>></p>"
195
+ expect(Deface::Parser.undo_erb_markup!("<p data-erb-0=\"&lt;% method_name %&gt;\" data-erb-1=\"&lt;% x = y %&gt;\"></p>")).to eq("<p <% method_name %> <% x = y %>></p>")
196
196
  end
197
197
 
198
198
  it "should revert data-erb-id attr inside html tag" do
199
- Deface::Parser.undo_erb_markup!("<p data-erb-id=\"&lt;% method_name &gt; 1 %&gt;\"></p>").should == "<p id=\"<% method_name > 1 %>\"></p>"
199
+ expect(Deface::Parser.undo_erb_markup!("<p data-erb-id=\"&lt;% method_name &gt; 1 %&gt;\"></p>")).to eq("<p id=\"<% method_name > 1 %>\"></p>")
200
200
  end
201
201
 
202
202
  it "should revert data-erb-href attr inside html tag" do
203
- Deface::Parser.undo_erb_markup!("<a data-erb-href=\"&lt;%= x 'y' + &quot;z&quot; %&gt;\">A Link</a>").should == %(<a href="<%= x 'y' + \"z\" %>">A Link</a>)
203
+ expect(Deface::Parser.undo_erb_markup!("<a data-erb-href=\"&lt;%= x 'y' + &quot;z&quot; %&gt;\">A Link</a>")).to eq(%(<a href="<%= x 'y' + \"z\" %>">A Link</a>))
204
204
  end
205
205
 
206
206
  if RUBY_PLATFORM == 'java'
207
207
  it "should revert data-erb-x containing double quoted value" do
208
- Deface::Parser.undo_erb_markup!("<p data-erb-0=\"&lt;% method_name %22test%22 %&gt;\"></p>").should == %(<p <% method_name \"test\" %>></p>)
208
+ expect(Deface::Parser.undo_erb_markup!("<p data-erb-0=\"&lt;% method_name %22test%22 %&gt;\"></p>")).to eq(%(<p <% method_name \"test\" %>></p>))
209
209
  end
210
210
  end
211
211
 
212
212
  it "should unescape contents of erb tags" do
213
- Deface::Parser.undo_erb_markup!("<% method(:key =&gt; 'value' %>").should == "<% method(:key => 'value' %>"
214
- Deface::Parser.undo_erb_markup!("<% method(:key =&gt; 'value'\n %>").should == "<% method(:key => 'value'\n %>"
213
+ expect(Deface::Parser.undo_erb_markup!("<% method(:key =&gt; 'value' %>")).to eq("<% method(:key => 'value' %>")
214
+ expect(Deface::Parser.undo_erb_markup!("<% method(:key =&gt; 'value'\n %>")).to eq("<% method(:key => 'value'\n %>")
215
215
  end
216
216
 
217
217
  end
@@ -10,14 +10,14 @@ module Deface
10
10
  FileUtils.rm_rf('spec/dummy/app/compiled_views')
11
11
  environment = Deface::Environment.new
12
12
  overrides = Deface::Environment::Overrides.new
13
- overrides.stub(:all => {}) # need to do this before creating an override
14
- overrides.stub(:all => {"posts/precompileme".to_sym => {"precompileme".parameterize => Deface::Override.new(:virtual_path => "posts/precompileme", :name => "precompileme", :insert_bottom => 'li', :text => "Added to li!")}})
15
- environment.stub(:overrides => overrides)
13
+ allow(overrides).to receive_messages(:all => {}) # need to do this before creating an override
14
+ allow(overrides).to receive_messages(:all => {"posts/precompileme".to_sym => {"precompileme".parameterize => Deface::Override.new(:virtual_path => "posts/precompileme", :name => "precompileme", :insert_bottom => 'li', :text => "Added to li!")}})
15
+ allow(environment).to receive_messages(:overrides => overrides)
16
16
 
17
- Rails.application.config.stub :deface => environment
17
+ allow(Rails.application.config).to receive_messages :deface => environment
18
18
 
19
19
  #stub view paths to be local spec/assets directory
20
- ActionController::Base.stub(:view_paths).and_return([File.join(File.dirname(__FILE__), '..', "assets")])
20
+ allow(ActionController::Base).to receive(:view_paths).and_return([File.join(File.dirname(__FILE__), '..', "assets")])
21
21
 
22
22
  Precompiler.precompile()
23
23
  end
@@ -31,12 +31,12 @@ module Deface
31
31
 
32
32
  filename = 'spec/dummy/app/compiled_views/posts/precompileme.html.erb'
33
33
 
34
- File.exists?(filename).should be_true
34
+ expect(File.exists?(filename)).to be_truthy
35
35
 
36
36
  file = File.open(filename, "rb")
37
37
  contents = file.read
38
38
 
39
- contents.should =~ /precompile/
39
+ expect(contents).to match(/precompile/)
40
40
  end
41
41
  end
42
42
  end
@@ -11,14 +11,14 @@ module Deface
11
11
 
12
12
  describe "#find" do
13
13
  it "should find by virtual_path" do
14
- Deface::Override.find({:virtual_path => "posts/index"}).size.should == 1
15
- Deface::Override.find({:virtual_path => "/posts/index"}).size.should == 1
16
- Deface::Override.find({:virtual_path => "/posts/index.html"}).size.should == 1
17
- Deface::Override.find({:virtual_path => "posts/index.html"}).size.should == 1
14
+ expect(Deface::Override.find({:virtual_path => "posts/index"}).size).to eq(1)
15
+ expect(Deface::Override.find({:virtual_path => "/posts/index"}).size).to eq(1)
16
+ expect(Deface::Override.find({:virtual_path => "/posts/index.html"}).size).to eq(1)
17
+ expect(Deface::Override.find({:virtual_path => "posts/index.html"}).size).to eq(1)
18
18
  end
19
19
 
20
20
  it "should return empty array when no details hash passed" do
21
- Deface::Override.find({}).should == []
21
+ expect(Deface::Override.find({})).to eq([])
22
22
  end
23
23
  end
24
24
 
@@ -32,8 +32,8 @@ module Deface
32
32
  end
33
33
 
34
34
  it "should find by virtual_path" do
35
- Deface::Override.find_using("shared/post").size.should == 1
36
- Deface::Override.find_using("shared/person").size.should == 1
35
+ expect(Deface::Override.find_using("shared/post").size).to eq(1)
36
+ expect(Deface::Override.find_using("shared/person").size).to eq(1)
37
37
  end
38
38
 
39
39
  end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ module Deface
4
+ describe SlimConverter do
5
+ include_context "mock Rails.application"
6
+
7
+ def slim_to_erb(src)
8
+ conv = Deface::SlimConverter.new(src)
9
+ conv.result.gsub("\n", "")
10
+ end
11
+
12
+ describe "convert slim to erb" do
13
+ it "should hanlde simple tags" do
14
+ expect(slim_to_erb('div class="some" id="message"= "Hi, World!"')).to eq("<div class=\"some\" id=\"message\"><%= ::Temple::Utils.escape_html_safe((\"Hi, World!\")) %></div>")
15
+ end
16
+
17
+ it "should handle complex tags" do
18
+ expect(slim_to_erb(%q{nav#top-nav-bar
19
+ ul#nav-bar.inline data-hook=''
20
+ - if true
21
+ .nav-links.high_res
22
+ li.dropdown
23
+ .welcome Welcome #{Spree::User.first.email} &#9662;
24
+ ul.dropdown
25
+ li = link_to 'Account', account_path
26
+ li = link_to 'Log out', logout_path
27
+ })).to eq("<nav id=\"top-nav-bar\"><ul class=\"inline\" data-hook=\"\" id=\"nav-bar\"><% if true %><div class=\"nav-links high_res\"><li class=\"dropdown\"><div class=\"welcome\">Welcome <%= ::Temple::Utils.escape_html_safe((Spree::User.first.email)) %> &#9662;</div><ul class=\"dropdown\"><li><%= ::Temple::Utils.escape_html_safe((link_to 'Account', account_path)) %></li><li><%= ::Temple::Utils.escape_html_safe((link_to 'Log out', logout_path)) %></li></ul></li></div><% end %></ul></nav>")
28
+ end
29
+ end
30
+
31
+ end
32
+ end
@@ -8,41 +8,40 @@ module Deface
8
8
  describe "load_template_source" do
9
9
  before do
10
10
  #stub view paths to be local spec/assets directory
11
- ActionController::Base.stub(:view_paths).and_return([File.join(File.dirname(__FILE__), '..', "assets")])
11
+ allow(ActionController::Base).to receive(:view_paths).and_return([File.join(File.dirname(__FILE__), '..', "assets")])
12
12
  end
13
13
 
14
14
  describe "with no overrides defined" do
15
15
  it "should return source for partial" do
16
- load_template_source("shared/post", true).should == "<p>I'm from shared/post partial</p>\n<%= \"And I've got ERB\" %>\n"
16
+ expect(load_template_source("shared/post", true)).to eq "<p>I'm from shared/post partial</p>\n<%= \"And I've got ERB\" %>\n"
17
17
  end
18
18
 
19
19
  it "should return converted source for partial containing haml" do
20
- load_template_source("shared/hello", true).should == "<div class='<%= @some %>' id='message'><%= 'Hello, World!' %>\n</div>\n"
20
+ expect(load_template_source("shared/hello", true)).to eq "<div class='<%= @some %>' id='message'><%= 'Hello, World!' %>\n</div>\n"
21
21
  end
22
22
 
23
23
  it "should return converted source for partial containing slim" do
24
- load_template_source("shared/hi", true).should == "<div class=\"some\" id=\"message\"><%= ::Temple::Utils.escape_html_safe((\"Hi, World!\")) %><%\n%></div>"
24
+ expect(load_template_source("shared/hi", true)).to eq "<div class=\"some\" id=\"message\"><%= ::Temple::Utils.escape_html_safe((\"Hi, World!\")) %>\n</div>"
25
25
  end
26
26
 
27
27
  it "should return source for template" do
28
- load_template_source("shared/person", false).should == "<p>I'm from shared/person template</p>\n<%= \"I've got ERB too\" %>\n"
28
+ expect(load_template_source("shared/person", false)).to eq "<p>I'm from shared/person template</p>\n<%= \"I've got ERB too\" %>\n"
29
29
  end
30
30
 
31
31
  it "should return converted source for template containing haml" do
32
- load_template_source("shared/pirate", false).gsub(/\s/, '').should == "<divid='content'><divclass='left'><p><%=print_information%></p></div><divclass='right'id='<%=@right%>'><%=render:partial=>\"sidebar\"%></div></div>"
32
+ expect(load_template_source("shared/pirate", false).gsub(/\s/, '')).to eq "<divid='content'><divclass='left'><p><%=print_information%></p></div><divclass='right'id='<%=@right%>'><%=render:partial=>\"sidebar\"%></div></div>"
33
33
  end
34
34
 
35
35
  it "should return converted source for template containing slim" do
36
- result = "<divid=\"content\"><%%><divclass=\"left\"><%%><p><%=::Temple::Utils.escape_html_safe((print_information))%><%%></p></div><divclass=\"right\"<%_slim_codeattributes1=@right;case(_slim_codeattributes1);whentrue%>id=\"id\"<%whenfalse,nil;else%>id=\"<%=::Temple::Utils.escape_html_safe((_slim_codeattributes1))%>\"<%end%>><%%><%=::Temple::Utils.escape_html_safe((render:partial=>\"sidebar\"))%><%%></div></div>"
37
- load_template_source("shared/public", false).gsub(/\s/, '').should == result
36
+ expect(load_template_source("shared/public", false).gsub(/\s/, '')).to include('print_information')
38
37
  end
39
38
 
40
39
  it "should return source for namespaced template" do
41
- load_template_source("admin/posts/index", false).should == "<h1>Manage Posts</h1>\n"
40
+ expect(load_template_source("admin/posts/index", false)).to eq "<h1>Manage Posts</h1>\n"
42
41
  end
43
42
 
44
43
  it "should raise exception for non-existing file" do
45
- lambda { load_template_source("tester/post", true) }.should raise_error(ActionView::MissingTemplate)
44
+ expect { load_template_source("tester/post", true) }.to raise_error(ActionView::MissingTemplate)
46
45
  end
47
46
 
48
47
  end
@@ -55,40 +54,40 @@ module Deface
55
54
  Deface::Override.new(:virtual_path => "shared/person", :name => "shared#person", :replace => "p", :text => "<h1>Argh!</h1>")
56
55
  Deface::Override.new(:virtual_path => "shared/_hello", :name => "shared#hello", :replace_contents => "div#message", :text => "<%= 'Goodbye World!' %>")
57
56
  Deface::Override.new(:virtual_path => "shared/pirate", :name => "shared#pirate", :replace => "p", :text => "<h1>Argh!</h1>")
57
+ Deface::Override.new(:virtual_path => "shared/public", :name => "shared#public", :replace => "p", :text => "<h1>Ahoy!</h1>")
58
58
  Deface::Override.new(:virtual_path => "admin/posts/index", :name => "admin#posts#index", :replace => "h1", :text => "<h1>Argh!</h1>")
59
59
  end
60
60
 
61
61
  it "should return overridden source for partial including overrides" do
62
- load_template_source("shared/post", true).should == "\n<%= \"And I've got ERB\" %>"
62
+ expect(load_template_source("shared/post", true).strip).to eq "<%= \"And I've got ERB\" %>"
63
63
  end
64
64
 
65
65
  it "should return converted and overridden source for partial containing haml" do
66
- load_template_source("shared/hello", true).should == "<div class=\"<%= @some %>\" id=\"message\"><%= 'Goodbye World!' %></div>"
66
+ expect(load_template_source("shared/hello", true).strip).to eq "<div class=\"<%= @some %>\" id=\"message\"><%= 'Goodbye World!' %></div>"
67
67
  end
68
68
 
69
69
  it "should return converted and overridden source for partial containing slim" do
70
- load_template_source("shared/hi", true).should == "<div class=\"some\" id=\"message\"><%= ::Temple::Utils.escape_html_safe((\"Hi, World!\")) %><%\n%></div>"
70
+ expect(load_template_source("shared/hi", true)).to eq "<div class=\"some\" id=\"message\"><%= ::Temple::Utils.escape_html_safe((\"Hi, World!\")) %>\n</div>"
71
71
  end
72
72
 
73
73
  it "should return overridden source for partial excluding overrides" do
74
- load_template_source("shared/post", true, false).should == "<p>I'm from shared/post partial</p>\n<%= \"And I've got ERB\" %>\n"
74
+ expect(load_template_source("shared/post", true, false)).to eq "<p>I'm from shared/post partial</p>\n<%= \"And I've got ERB\" %>\n"
75
75
  end
76
76
 
77
77
  it "should return overridden source for template including overrides" do
78
- load_template_source("shared/person", false).should == "<h1>Argh!</h1>\n<%= \"I've got ERB too\" %>"
78
+ expect(load_template_source("shared/person", false).strip).to eq "<h1>Argh!</h1>\n<%= \"I've got ERB too\" %>"
79
79
  end
80
80
 
81
81
  it "should return converted and overridden source for template containing haml" do
82
- load_template_source("shared/pirate", false).gsub(/\s/, '').should == "<divid=\"content\"><divclass=\"left\"><h1>Argh!</h1></div><divclass=\"right\"id=\"<%=@right%>\"><%=render:partial=>\"sidebar\"%></div></div>"
82
+ expect(load_template_source("shared/pirate", false).gsub(/\s/, '')).to eq "<divid=\"content\"><divclass=\"left\"><h1>Argh!</h1></div><divclass=\"right\"id=\"<%=@right%>\"><%=render:partial=>\"sidebar\"%></div></div>"
83
83
  end
84
84
 
85
85
  it "should return converted and overridden source for template containing slim" do
86
- result = "<divid=\"content\"><%%><divclass=\"left\"><%%><p><%=::Temple::Utils.escape_html_safe((print_information))%><%%></p></div><divclass=\"right\"<%_slim_codeattributes1=@right;case(_slim_codeattributes1);whentrue%>id=\"id\"<%whenfalse,nil;else%>id=\"<%=::Temple::Utils.escape_html_safe((_slim_codeattributes1))%>\"<%end%>><%%><%=::Temple::Utils.escape_html_safe((render:partial=>\"sidebar\"))%><%%></div></div>"
87
- load_template_source("shared/public", false).gsub(/\s/, '').should == result
86
+ expect(load_template_source("shared/public", false).gsub(/\s/, '')).to include("<h1>Ahoy!</h1>")
88
87
  end
89
88
 
90
89
  it "should return source for namespaced template including overrides" do
91
- load_template_source("admin/posts/index", false).should == "<h1>Argh!</h1>"
90
+ expect(load_template_source("admin/posts/index", false).strip).to eq "<h1>Argh!</h1>"
92
91
  end
93
92
 
94
93
  end
@@ -97,12 +96,12 @@ module Deface
97
96
 
98
97
  describe "element_source" do
99
98
  it "should return array of matches elements" do
100
- element_source('<div><p class="pirate">Arrgh!</p><img src="/some/image.jpg"></div>', 'p.pirate').map(&:strip).should == ["<p class=\"pirate\">Arrgh!</p>"]
101
- element_source('<div><p class="pirate">Arrgh!</p><p>No pirates here...</p></div>', 'p').map(&:strip).should == ["<p class=\"pirate\">Arrgh!</p>", "<p>No pirates here...</p>"]
99
+ expect(element_source('<div><p class="pirate">Arrgh!</p><img src="/some/image.jpg"></div>', 'p.pirate').map(&:strip)).to eq ["<p class=\"pirate\">Arrgh!</p>"]
100
+ expect(element_source('<div><p class="pirate">Arrgh!</p><p>No pirates here...</p></div>', 'p').map(&:strip)).to eq ["<p class=\"pirate\">Arrgh!</p>", "<p>No pirates here...</p>"]
102
101
  end
103
102
 
104
103
  it "should return empty array for no matches" do
105
- element_source('<div><p class="pirate">Arrgh!</p><img src="/some/image.jpg"></div>', 'span').should == []
104
+ expect(element_source('<div><p class="pirate">Arrgh!</p><img src="/some/image.jpg"></div>', 'span')).to eq []
106
105
  end
107
106
  end
108
107
  end