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
@@ -24,70 +24,70 @@ module Deface
24
24
  describe ".overrides" do
25
25
 
26
26
  it "should return all overrides" do
27
- Rails.application.config.deface.overrides.all.size.should == 2
28
- Rails.application.config.deface.overrides.all.should == Deface::Override.all
27
+ expect(Rails.application.config.deface.overrides.all.size).to eq(2)
28
+ expect(Rails.application.config.deface.overrides.all).to eq(Deface::Override.all)
29
29
  end
30
30
 
31
31
  it "should find overrides" do
32
- Rails.application.config.deface.overrides.find(:virtual_path => "posts/new").size.should == 1
32
+ expect(Rails.application.config.deface.overrides.find(:virtual_path => "posts/new").size).to eq(1)
33
33
  end
34
34
 
35
35
  describe "load_all" do
36
36
 
37
37
  before do
38
- Rails.application.stub :root => Pathname.new(File.join(File.dirname(__FILE__), '..', "assets"))
39
- Rails.application.stub :paths => {}
40
- Rails.application.stub_chain :railties, railties_collection_accessor => []
38
+ allow(Rails.application).to receive_messages :root => Pathname.new(File.join(File.dirname(__FILE__), '..', "assets"))
39
+ allow(Rails.application).to receive_messages :paths => {}
40
+ allow(Rails.application).to receive_message_chain :railties, railties_collection_accessor => []
41
41
 
42
- Deface::DSL::Loader.should_receive(:register)
42
+ expect(Deface::DSL::Loader).to receive(:register)
43
43
  end
44
44
 
45
45
  it "should enumerate_and_load nil when app has no app/overrides path set" do
46
- Rails.application.config.deface.overrides.should_receive(:enumerate_and_load).with(nil, Rails.application.root)
46
+ expect(Rails.application.config.deface.overrides).to receive(:enumerate_and_load).with(nil, Rails.application.root)
47
47
  Rails.application.config.deface.overrides.load_all(Rails.application)
48
48
  end
49
49
 
50
50
  it "should enumerate_and_load path when app has app/overrides path set" do
51
- Rails.application.stub :paths => {"app/overrides" => ["app/some_path"] }
52
- Rails.application.config.deface.overrides.should_receive(:enumerate_and_load).with(["app/some_path"] , Rails.application.root)
51
+ allow(Rails.application).to receive_messages :paths => {"app/overrides" => ["app/some_path"] }
52
+ expect(Rails.application.config.deface.overrides).to receive(:enumerate_and_load).with(["app/some_path"] , Rails.application.root)
53
53
  Rails.application.config.deface.overrides.load_all(Rails.application)
54
54
  end
55
55
 
56
56
  it "should enumerate_and_load nil when railtie has no app/overrides path set" do
57
- Rails.application.stub_chain :railties, railties_collection_accessor => [double('railtie', :root => "/some/path")]
57
+ allow(Rails.application).to receive_message_chain :railties, railties_collection_accessor => [double('railtie', :root => "/some/path")]
58
58
 
59
- Rails.application.config.deface.overrides.should_receive(:enumerate_and_load).with(nil, Rails.application.root)
60
- Rails.application.config.deface.overrides.should_receive(:enumerate_and_load).with(nil, "/some/path")
59
+ expect(Rails.application.config.deface.overrides).to receive(:enumerate_and_load).with(nil, Rails.application.root)
60
+ expect(Rails.application.config.deface.overrides).to receive(:enumerate_and_load).with(nil, "/some/path")
61
61
  Rails.application.config.deface.overrides.load_all(Rails.application)
62
62
  end
63
63
 
64
64
  it "should enumerate_and_load path when railtie has app/overrides path set" do
65
- Rails.application.stub_chain :railties, railties_collection_accessor => [ double('railtie', :root => "/some/path", :paths => {"app/overrides" => ["app/some_path"] } )]
65
+ allow(Rails.application).to receive_message_chain :railties, railties_collection_accessor => [ double('railtie', :root => "/some/path", :paths => {"app/overrides" => ["app/some_path"] } )]
66
66
 
67
- Rails.application.config.deface.overrides.should_receive(:enumerate_and_load).with(nil, Rails.application.root)
68
- Rails.application.config.deface.overrides.should_receive(:enumerate_and_load).with(["app/some_path"] , "/some/path")
67
+ expect(Rails.application.config.deface.overrides).to receive(:enumerate_and_load).with(nil, Rails.application.root)
68
+ expect(Rails.application.config.deface.overrides).to receive(:enumerate_and_load).with(["app/some_path"] , "/some/path")
69
69
  Rails.application.config.deface.overrides.load_all(Rails.application)
70
70
  end
71
71
 
72
72
  it "should enumerate_and_load railties first, followed by the application iteslf" do
73
- Rails.application.stub_chain :railties, railties_collection_accessor => [ double('railtie', :root => "/some/path", :paths => {"app/overrides" => ["app/some_path"] } )]
73
+ allow(Rails.application).to receive_message_chain :railties, railties_collection_accessor => [ double('railtie', :root => "/some/path", :paths => {"app/overrides" => ["app/some_path"] } )]
74
74
 
75
- Rails.application.config.deface.overrides.should_receive(:enumerate_and_load).with(["app/some_path"] , "/some/path").ordered
76
- Rails.application.config.deface.overrides.should_receive(:enumerate_and_load).with(nil, Rails.application.root).ordered
75
+ expect(Rails.application.config.deface.overrides).to receive(:enumerate_and_load).with(["app/some_path"] , "/some/path").ordered
76
+ expect(Rails.application.config.deface.overrides).to receive(:enumerate_and_load).with(nil, Rails.application.root).ordered
77
77
  Rails.application.config.deface.overrides.load_all(Rails.application)
78
78
  end
79
79
 
80
80
  it "should ignore railtie with no root" do
81
81
  railtie = double('railtie')
82
- Rails.application.stub_chain :railties, railties_collection_accessor => [railtie]
82
+ allow(Rails.application).to receive_message_chain :railties, railties_collection_accessor => [railtie]
83
83
 
84
- railtie.should_receive(:respond_to?).with(:root)
85
- railtie.should_not_receive(:respond_to?).with(:paths)
84
+ expect(railtie).to receive(:respond_to?).with(:root)
85
+ expect(railtie).not_to receive(:respond_to?).with(:paths)
86
86
  Rails.application.config.deface.overrides.load_all(Rails.application)
87
87
  end
88
88
 
89
89
  it "should clear any previously loaded overrides" do
90
- Rails.application.config.deface.overrides.all.should_receive(:clear)
90
+ expect(Rails.application.config.deface.overrides.all).to receive(:clear)
91
91
  Rails.application.config.deface.overrides.load_all(Rails.application)
92
92
  end
93
93
 
@@ -97,15 +97,15 @@ module Deface
97
97
  describe 'load_overrides' do
98
98
  let(:assets_path) { Pathname.new(File.join(File.dirname(__FILE__), '..', "assets")) }
99
99
  let(:engine) { double('railtie', :root => assets_path, :class => "DummyEngine", :paths => {"app/overrides" => ["dummy_engine"]}) }
100
- before { Rails.application.stub(:class => 'RailsAppl') }
100
+ before { allow(Rails.application).to receive_messages(:class => 'RailsAppl') }
101
101
 
102
102
  it "should keep a reference to which railtie/app defined the override" do
103
- Rails.application.stub :root => assets_path, :paths => {"app/overrides" => ["dummy_app"] }
104
- Rails.application.stub_chain :railties, railties_collection_accessor => [ engine ]
103
+ allow(Rails.application).to receive_messages :root => assets_path, :paths => {"app/overrides" => ["dummy_app"] }
104
+ allow(Rails.application).to receive_message_chain :railties, railties_collection_accessor => [ engine ]
105
105
 
106
106
  Rails.application.config.deface.overrides.load_all(Rails.application)
107
107
 
108
- Deface::Override.all.values.map(&:values).flatten.map(&:railtie_class).should include('RailsAppl', 'DummyEngine')
108
+ expect(Deface::Override.all.values.map(&:values).flatten.map(&:railtie_class)).to include('RailsAppl', 'DummyEngine')
109
109
  end
110
110
  end
111
111
 
@@ -113,23 +113,23 @@ module Deface
113
113
  let(:root) { Pathname.new("/some/path") }
114
114
 
115
115
  it "should be enumerate default path when none supplied" do
116
- Dir.should_receive(:glob).with(root.join "app/overrides", "**", "*.rb")
117
- Dir.should_receive(:glob).with(root.join "app/overrides", "**", "*.deface")
116
+ expect(Dir).to receive(:glob).with(root.join "app/overrides", "**", "*.rb")
117
+ expect(Dir).to receive(:glob).with(root.join "app/overrides", "**", "*.deface")
118
118
  Rails.application.config.deface.overrides.send(:enumerate_and_load, nil, root)
119
119
  end
120
120
 
121
121
  it "should enumerate supplied paths" do
122
- Dir.should_receive(:glob).with(root.join "app/junk", "**", "*.rb" )
123
- Dir.should_receive(:glob).with(root.join "app/junk", "**", "*.deface" )
124
- Dir.should_receive(:glob).with(root.join "app/gold", "**", "*.rb" )
125
- Dir.should_receive(:glob).with(root.join "app/gold", "**", "*.deface" )
122
+ expect(Dir).to receive(:glob).with(root.join "app/junk", "**", "*.rb" )
123
+ expect(Dir).to receive(:glob).with(root.join "app/junk", "**", "*.deface" )
124
+ expect(Dir).to receive(:glob).with(root.join "app/gold", "**", "*.rb" )
125
+ expect(Dir).to receive(:glob).with(root.join "app/gold", "**", "*.deface" )
126
126
  Rails.application.config.deface.overrides.send(:enumerate_and_load, ["app/junk", "app/gold"], root)
127
127
  end
128
128
 
129
129
  it "should add paths to watchable_dir when running Rails 3.2" do
130
- if Rails.version[0..2] == '3.2'
130
+ if Rails.version[0..2] >= '3.2'
131
131
  Rails.application.config.deface.overrides.send(:enumerate_and_load, ["app/gold"], root)
132
- Rails.application.config.watchable_dirs.should == {"/some/path/app/gold" => [:rb, :deface] }
132
+ expect(Rails.application.config.watchable_dirs).to eq({"/some/path/app/gold" => [:rb, :deface] })
133
133
  end
134
134
  end
135
135
 
@@ -138,15 +138,15 @@ module Deface
138
138
 
139
139
  describe "#_early" do
140
140
  it "should contain one override" do
141
- Deface::Override._early.size.should == 1
141
+ expect(Deface::Override._early.size).to eq(1)
142
142
  end
143
143
 
144
144
  it "should initialize override and be emtpy after early_check" do
145
145
  before_count = Rails.application.config.deface.overrides.all.size
146
146
  Rails.application.config.deface.overrides.early_check
147
147
 
148
- Deface::Override._early.size.should == 0
149
- Rails.application.config.deface.overrides.all.size.should == (before_count + 1)
148
+ expect(Deface::Override._early.size).to eq(0)
149
+ expect(Rails.application.config.deface.overrides.all.size).to eq(before_count + 1)
150
150
  end
151
151
  end
152
152
 
@@ -11,77 +11,77 @@ module Deface
11
11
 
12
12
  describe "convert haml to erb" do
13
13
  it "should hanlde simple tags" do
14
- haml_to_erb("%%strong.code#message Hello, World!").should == "<strong class='code' id='message'>Hello, World!</strong>"
14
+ expect(haml_to_erb("%%strong.code#message Hello, World!")).to eq("<strong class='code' id='message'>Hello, World!</strong>")
15
15
  end
16
16
 
17
17
  it "should handle complex tags" do
18
- haml_to_erb(%q{#content
18
+ expect(haml_to_erb(%q{#content
19
19
  .left.column
20
20
  %h2 Welcome to our site!
21
21
  %p= print_information
22
22
  .right.column
23
- = render :partial => "sidebar"}).should == "<div id='content'> <div class='left column'> <h2>Welcome to our site!</h2> <p> <%= print_information %></p> </div> <div class='right column'> <%= render :partial => \"sidebar\" %> </div></div>"
23
+ = render :partial => "sidebar"})).to eq("<div id='content'> <div class='left column'> <h2>Welcome to our site!</h2> <p> <%= print_information %></p> </div> <div class='right column'> <%= render :partial => \"sidebar\" %> </div></div>")
24
24
  end
25
25
 
26
26
  it "should handle simple haml attributes" do
27
- haml_to_erb("%meta{:charset => 'utf-8'}").should == "<meta charset='utf-8' />"
28
- haml_to_erb("%p(alt='hello world')Hello World!").should == "<p alt='hello world'>Hello World!</p>"
27
+ expect(haml_to_erb("%meta{:charset => 'utf-8'}")).to eq("<meta charset='utf-8' />")
28
+ expect(haml_to_erb("%p(alt='hello world')Hello World!")).to eq("<p alt='hello world'>Hello World!</p>")
29
29
  end
30
30
 
31
31
  it "should handle haml attributes with commas" do
32
- haml_to_erb("%meta{'http-equiv' => 'X-UA-Compatible', :content => 'IE=edge,chrome=1'}").should == "<meta content='IE=edge,chrome=1' http-equiv='X-UA-Compatible' />"
33
- haml_to_erb("%meta(http-equiv='X-UA-Compatible' content='IE=edge,chrome=1')").should == "<meta content='IE=edge,chrome=1' http-equiv='X-UA-Compatible' />"
34
- haml_to_erb('%meta{:name => "author", :content => "Example, Inc."}').should == "<meta content='Example, Inc.' name='author' />"
35
- haml_to_erb('%meta(name="author" content="Example, Inc.")').should == "<meta content='Example, Inc.' name='author' />"
32
+ expect(haml_to_erb("%meta{'http-equiv' => 'X-UA-Compatible', :content => 'IE=edge,chrome=1'}")).to eq("<meta content='IE=edge,chrome=1' http-equiv='X-UA-Compatible' />")
33
+ expect(haml_to_erb("%meta(http-equiv='X-UA-Compatible' content='IE=edge,chrome=1')")).to eq("<meta content='IE=edge,chrome=1' http-equiv='X-UA-Compatible' />")
34
+ expect(haml_to_erb('%meta{:name => "author", :content => "Example, Inc."}')).to eq("<meta content='Example, Inc.' name='author' />")
35
+ expect(haml_to_erb('%meta(name="author" content="Example, Inc.")')).to eq("<meta content='Example, Inc.' name='author' />")
36
36
 
37
37
  if RUBY_VERSION > "1.9"
38
- haml_to_erb('%meta{name: "author", content: "Example, Inc."}').should == "<meta content='Example, Inc.' name='author' />"
38
+ expect(haml_to_erb('%meta{name: "author", content: "Example, Inc."}')).to eq("<meta content='Example, Inc.' name='author' />")
39
39
  end
40
40
  end
41
41
 
42
42
  it "should handle haml attributes with evaluated values" do
43
- haml_to_erb("%p{ :alt => hello_world}Hello World!").should == "<p data-erb-alt='&lt;%= hello_world %&gt;'>Hello World!</p>"
43
+ expect(haml_to_erb("%p{ :alt => hello_world}Hello World!")).to eq("<p data-erb-alt='&lt;%= hello_world %&gt;'>Hello World!</p>")
44
44
 
45
45
  if RUBY_VERSION > "1.9"
46
- haml_to_erb("%p{ alt: @hello_world}Hello World!").should == "<p data-erb-alt='&lt;%= @hello_world %&gt;'>Hello World!</p>"
46
+ expect(haml_to_erb("%p{ alt: @hello_world}Hello World!")).to eq("<p data-erb-alt='&lt;%= @hello_world %&gt;'>Hello World!</p>")
47
47
  end
48
48
 
49
- haml_to_erb("%p(alt=hello_world)Hello World!").should == "<p data-erb-alt='&lt;%= hello_world %&gt;'>Hello World!</p>"
50
- haml_to_erb("%p(alt=@hello_world)Hello World!").should == "<p data-erb-alt='&lt;%= @hello_world %&gt;'>Hello World!</p>"
49
+ expect(haml_to_erb("%p(alt=hello_world)Hello World!")).to eq("<p data-erb-alt='&lt;%= hello_world %&gt;'>Hello World!</p>")
50
+ expect(haml_to_erb("%p(alt=@hello_world)Hello World!")).to eq("<p data-erb-alt='&lt;%= @hello_world %&gt;'>Hello World!</p>")
51
51
  end
52
52
 
53
53
  it "should handle erb loud" do
54
- haml_to_erb("%h3.title= entry.title").should == "<h3 class='title'><%= entry.title %></h3>"
54
+ expect(haml_to_erb("%h3.title= entry.title")).to eq("<h3 class='title'><%= entry.title %></h3>")
55
55
  end
56
56
 
57
57
  it "should handle single erb silent" do
58
- haml_to_erb("- some_method").should == "<% some_method %>"
58
+ expect(haml_to_erb("- some_method")).to eq("<% some_method %>")
59
59
  end
60
60
 
61
61
  it "should handle implicitly closed erb loud" do
62
- haml_to_erb("= if @this == 'this'
62
+ expect(haml_to_erb("= if @this == 'this'
63
63
  %p hello
64
- ").should == "<%= if @this == 'this' %><p>hello</p><% end %>"
64
+ ")).to eq("<%= if @this == 'this' %><p>hello</p><% end %>")
65
65
  end
66
66
 
67
67
  it "should handle implicitly closed erb silent" do
68
- haml_to_erb("- if foo?
68
+ expect(haml_to_erb("- if foo?
69
69
  %p hello
70
- ").should == "<% if foo? %><p>hello</p><% end %>"
70
+ ")).to eq("<% if foo? %><p>hello</p><% end %>")
71
71
  end
72
72
 
73
73
  it "should handle blocks passed to erb loud" do
74
- haml_to_erb("= form_for Post.new do |f|
74
+ expect(haml_to_erb("= form_for Post.new do |f|
75
75
  %p
76
- = f.text_field :name").should == "<%= form_for Post.new do |f| %><p> <%= f.text_field :name %></p><% end %>"
76
+ = f.text_field :name")).to eq("<%= form_for Post.new do |f| %><p> <%= f.text_field :name %></p><% end %>")
77
77
 
78
78
  end
79
79
 
80
80
 
81
81
  it "should handle blocks passed to erb silent" do
82
- haml_to_erb("- @posts.each do |post|
82
+ expect(haml_to_erb("- @posts.each do |post|
83
83
  %p
84
- = post.name").should == "<% @posts.each do |post| %><p> <%= post.name %></p><% end %>"
84
+ = post.name")).to eq("<% @posts.each do |post| %><p> <%= post.name %></p><% end %>")
85
85
 
86
86
  end
87
87
  end
@@ -12,35 +12,35 @@ module Deface
12
12
  Deface::Override.actions.each do |action|
13
13
  Rails.application.config.deface.overrides.all.clear
14
14
  @override = Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", action => "h1", :text => "<h1>Argh!</h1>")
15
- @override.action.should == action
15
+ expect(@override.action).to eq(action)
16
16
  end
17
17
  end
18
18
 
19
19
  it "should have a sources method" do
20
- Deface::DEFAULT_SOURCES.map(&:to_sym).should include(:text)
20
+ expect(Deface::DEFAULT_SOURCES.map(&:to_sym)).to include(:text)
21
21
  end
22
22
 
23
23
  it "should return correct selector" do
24
- @override.selector.should == "h1"
24
+ expect(@override.selector).to eq("h1")
25
25
  end
26
26
 
27
27
  it "should set default :updated_at" do
28
- @override.args[:updated_at].should_not be_nil
28
+ expect(@override.args[:updated_at]).not_to be_nil
29
29
  end
30
30
 
31
31
  describe "#original_source" do
32
32
  it "should return nil with not specified" do
33
- @override.original_source.should be_nil
33
+ expect(@override.original_source).to be_nil
34
34
  end
35
35
 
36
36
  it "should return parsed nokogiri document when present" do
37
37
  @original = Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :replace => "h1", :text => "<h1>Argh!</h1>", :original => "<p><%= something %></p>")
38
- @original.original_source.should be_an_instance_of Nokogiri::HTML::DocumentFragment
38
+ expect(@original.original_source).to be_an_instance_of Nokogiri::HTML::DocumentFragment
39
39
 
40
40
  if RUBY_PLATFORM == 'java'
41
- @original.original_source.to_s.should == "<p><erb loud=\"\"> something </erb></p>"
41
+ expect(@original.original_source.to_s).to eq("<p><erb loud=\"\"> something </erb></p>")
42
42
  else
43
- @original.original_source.to_s.should == "<p><erb loud> something </erb></p>"
43
+ expect(@original.original_source.to_s).to eq("<p><erb loud> something </erb></p>")
44
44
  end
45
45
  end
46
46
  end
@@ -51,8 +51,8 @@ module Deface
51
51
  end
52
52
 
53
53
  it "should warn but not validate" do
54
- Rails.logger.should_receive(:info).once
55
- @override.validate_original("<p>this gets ignored</p>").should be_nil
54
+ expect(Rails.logger).to receive(:info).once
55
+ expect(@override.validate_original("<p>this gets ignored</p>")).to be_nil
56
56
  end
57
57
 
58
58
  end
@@ -109,9 +109,9 @@ module Deface
109
109
  end
110
110
 
111
111
  it "should return un-convert text as source" do
112
- @override.source.should == "<h1 id=\"<%= dom_id @pirate %>\">Argh!</h1>"
112
+ expect(@override.source).to eq("<h1 id=\"<%= dom_id @pirate %>\">Argh!</h1>")
113
113
 
114
- @override.source_argument.should == :text
114
+ expect(@override.source_argument).to eq(:text)
115
115
  end
116
116
  end
117
117
 
@@ -122,9 +122,9 @@ module Deface
122
122
  end
123
123
 
124
124
  it "should return un-convert text as source" do
125
- @override.source.should == "<h1 id=\"<%= dom_id @pirate %>\">Argh!</h1>"
125
+ expect(@override.source).to eq("<h1 id=\"<%= dom_id @pirate %>\">Argh!</h1>")
126
126
 
127
- @override.source_argument.should == :erb
127
+ expect(@override.source_argument).to eq(:erb)
128
128
  end
129
129
  end
130
130
 
@@ -136,9 +136,9 @@ module Deface
136
136
  end
137
137
 
138
138
  it "should return erb converted from haml as source" do
139
- @override.source.should == "<strong class='erb' id='message'><%= 'Hello, World!' %>\n</strong>\n"
139
+ expect(@override.source).to eq("<strong class='erb' id='message'><%= 'Hello, World!' %>\n</strong>\n")
140
140
 
141
- @override.source_argument.should == :haml
141
+ expect(@override.source_argument).to eq(:haml)
142
142
  end
143
143
  end
144
144
 
@@ -150,9 +150,9 @@ module Deface
150
150
  end
151
151
 
152
152
  it "should return erb converted from slim as source" do
153
- @override.source.should == "<strong class=\"erb\" id=\"message\"><%= ::Temple::Utils.escape_html_safe(('Hello, World!')) %><%\n%></strong>"
153
+ expect(@override.source).to eq("<strong class=\"erb\" id=\"message\"><%= ::Temple::Utils.escape_html_safe(('Hello, World!')) %>\n</strong>")
154
154
 
155
- @override.source_argument.should == :slim
155
+ expect(@override.source_argument).to eq(:slim)
156
156
  end
157
157
  end
158
158
 
@@ -161,15 +161,15 @@ module Deface
161
161
 
162
162
  before(:each) do
163
163
  #stub view paths to be local spec/assets directory
164
- ActionController::Base.stub(:view_paths).and_return([File.join(File.dirname(__FILE__), '..', "assets")])
164
+ allow(ActionController::Base).to receive(:view_paths).and_return([File.join(File.dirname(__FILE__), '..', "assets")])
165
165
 
166
166
  @override = Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :replace => "h1", :partial => "shared/post")
167
167
  end
168
168
 
169
169
  it "should return un-convert partial contents as source" do
170
- @override.source.should == "<p>I'm from shared/post partial</p>\n<%= \"And I've got ERB\" %>\n"
170
+ expect(@override.source).to eq("<p>I'm from shared/post partial</p>\n<%= \"And I've got ERB\" %>\n")
171
171
 
172
- @override.source_argument.should == :partial
172
+ expect(@override.source_argument).to eq(:partial)
173
173
  end
174
174
 
175
175
  end
@@ -178,15 +178,15 @@ module Deface
178
178
 
179
179
  before(:each) do
180
180
  #stub view paths to be local spec/assets directory
181
- ActionController::Base.stub(:view_paths).and_return([File.join(File.dirname(__FILE__), '..', "assets")])
181
+ allow(ActionController::Base).to receive(:view_paths).and_return([File.join(File.dirname(__FILE__), '..', "assets")])
182
182
 
183
183
  @override = Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :replace => "h1", :template => "shared/person")
184
184
  end
185
185
 
186
186
  it "should return un-convert template contents as source" do
187
- @override.source.should == "<p>I'm from shared/person template</p>\n<%= \"I've got ERB too\" %>\n"
187
+ expect(@override.source).to eq("<p>I'm from shared/person template</p>\n<%= \"I've got ERB too\" %>\n")
188
188
 
189
- @override.source_argument.should == :template
189
+ expect(@override.source_argument).to eq(:template)
190
190
  end
191
191
 
192
192
  end
@@ -197,29 +197,29 @@ module Deface
197
197
 
198
198
  before(:each) do
199
199
  @override = Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :insert_after => "h1", :copy => "h1")
200
- @override.stub(:parsed_document).and_return(parsed)
200
+ allow(@override).to receive(:parsed_document).and_return(parsed)
201
201
  end
202
202
 
203
203
  it "should not change original parsed source" do
204
204
  @override.source
205
205
 
206
206
  if RUBY_PLATFORM == 'java'
207
- parsed.to_s.gsub(/\n/,'').should == "<div><h1>Manage Posts</h1><erb loud=\"\"> some_method </erb></div>"
207
+ expect(parsed.to_s.gsub(/\n/,'')).to eq("<div><h1>Manage Posts</h1><erb loud=\"\"> some_method </erb></div>")
208
208
  else
209
- parsed.to_s.gsub(/\n/,'').should == "<div><h1>Manage Posts</h1><erb loud> some_method </erb></div>"
209
+ expect(parsed.to_s.gsub(/\n/,'')).to eq("<div><h1>Manage Posts</h1><erb loud> some_method </erb></div>")
210
210
  end
211
211
 
212
- @override.source_argument.should == :copy
212
+ expect(@override.source_argument).to eq(:copy)
213
213
  end
214
214
 
215
215
  it "should return copy of content from source document" do
216
- @override.source.to_s.strip.should == "<h1>Manage Posts</h1>"
216
+ expect(@override.source.to_s.strip).to eq("<h1>Manage Posts</h1>")
217
217
  end
218
218
 
219
219
  it "should return unescaped content for source document" do
220
220
  @override = Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :insert_after => "h1", :copy => "erb[loud]:contains('some_method')")
221
- @override.stub(:parsed_document).and_return(parsed)
222
- @override.source.should == "<%= some_method %>"
221
+ allow(@override).to receive(:parsed_document).and_return(parsed)
222
+ expect(@override.source).to eq("<%= some_method %>")
223
223
  end
224
224
 
225
225
  end
@@ -232,23 +232,23 @@ module Deface
232
232
  @override = Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :insert_after => "h1",
233
233
  :copy => {:start => "erb:contains('if true')", :end => "erb:contains('end')"})
234
234
 
235
- @override.stub(:parsed_document).and_return(parsed)
235
+ allow(@override).to receive(:parsed_document).and_return(parsed)
236
236
  end
237
237
 
238
238
  it "should not change original parsed source" do
239
239
  @override.source
240
240
 
241
241
  if RUBY_PLATFORM == 'java'
242
- parsed.to_s.gsub(/\n/,'').should == "<h1>World</h1><erb silent=\"\"> if true </erb><p>True that!</p><erb silent=\"\"> end </erb><p>Hello</p>"
242
+ expect(parsed.to_s.gsub(/\n/,'')).to eq("<h1>World</h1><erb silent=\"\"> if true </erb><p>True that!</p><erb silent=\"\"> end </erb><p>Hello</p>")
243
243
  else
244
- parsed.to_s.gsub(/\n/,'').should == "<h1>World</h1><erb silent> if true </erb><p>True that!</p><erb silent> end </erb><p>Hello</p>"
244
+ expect(parsed.to_s.gsub(/\n/,'')).to eq("<h1>World</h1><erb silent> if true </erb><p>True that!</p><erb silent> end </erb><p>Hello</p>")
245
245
  end
246
246
 
247
- @override.source_argument.should == :copy
247
+ expect(@override.source_argument).to eq(:copy)
248
248
  end
249
249
 
250
250
  it "should return copy of content from source document" do
251
- @override.source.should == "<% if true %><p>True that!</p><% end %>"
251
+ expect(@override.source).to eq("<% if true %><p>True that!</p><% end %>")
252
252
  end
253
253
  end
254
254
 
@@ -256,28 +256,28 @@ module Deface
256
256
  let(:parsed) { Deface::Parser.convert("<div><h1>Manage Posts</h1><%= some_method %></div>") }
257
257
  before(:each) do
258
258
  @override = Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :insert_after => "h1", :cut => "h1")
259
- @override.stub(:parsed_document).and_return(parsed)
259
+ allow(@override).to receive(:parsed_document).and_return(parsed)
260
260
  end
261
261
 
262
262
  it "should remove cut element from original parsed source" do
263
263
  @override.source
264
264
  if RUBY_PLATFORM == 'java'
265
- parsed.to_s.gsub(/\n/,'').should == "<div><erb loud=\"\"> some_method </erb></div>"
265
+ expect(parsed.to_s.gsub(/\n/,'')).to eq("<div><erb loud=\"\"> some_method </erb></div>")
266
266
  else
267
- parsed.to_s.gsub(/\n/,'').should == "<div><erb loud> some_method </erb></div>"
267
+ expect(parsed.to_s.gsub(/\n/,'')).to eq("<div><erb loud> some_method </erb></div>")
268
268
  end
269
269
 
270
- @override.source_argument.should == :cut
270
+ expect(@override.source_argument).to eq(:cut)
271
271
  end
272
272
 
273
273
  it "should remove and return content from source document" do
274
- @override.source.should == "<h1>Manage Posts</h1>"
274
+ expect(@override.source).to eq("<h1>Manage Posts</h1>")
275
275
  end
276
276
 
277
277
  it "should return unescaped content for source document" do
278
278
  @override = Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :insert_after => "h1", :cut => "erb[loud]:contains('some_method')")
279
- @override.stub(:parsed_document).and_return(parsed)
280
- @override.source.should == "<%= some_method %>"
279
+ allow(@override).to receive(:parsed_document).and_return(parsed)
280
+ expect(@override.source).to eq("<%= some_method %>")
281
281
  end
282
282
 
283
283
  end
@@ -291,29 +291,29 @@ module Deface
291
291
  @override = Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :insert_after => "h1",
292
292
  :cut => {:start => "erb:contains('if true')", :end => "erb:contains('end')"})
293
293
 
294
- @override.stub(:parsed_document).and_return(parsed)
294
+ allow(@override).to receive(:parsed_document).and_return(parsed)
295
295
  end
296
296
 
297
297
  it "should remove cut element from original parsed source" do
298
298
  @override.source
299
299
  if RUBY_PLATFORM == 'java'
300
- parsed.to_s.gsub(/\n/,'').should == "<h1>World</h1><erb loud=\"\"> hello </erb>"
300
+ expect(parsed.to_s.gsub(/\n/,'')).to eq("<h1>World</h1><erb loud=\"\"> hello </erb>")
301
301
  else
302
- parsed.to_s.gsub(/\n/,'').should == "<h1>World</h1><erb loud> hello </erb>"
302
+ expect(parsed.to_s.gsub(/\n/,'')).to eq("<h1>World</h1><erb loud> hello </erb>")
303
303
  end
304
304
 
305
- @override.source_argument.should == :cut
305
+ expect(@override.source_argument).to eq(:cut)
306
306
  end
307
307
 
308
308
  it "should return copy of content from source document" do
309
- @override.source.should == "<% if true %><p>True that!</p><% end %>"
309
+ expect(@override.source).to eq("<% if true %><p>True that!</p><% end %>")
310
310
  end
311
311
  end
312
312
 
313
313
  describe "with block" do
314
314
  before(:each) do
315
315
  #stub view paths to be local spec/assets directory
316
- ActionController::Base.stub(:view_paths).and_return([File.join(File.dirname(__FILE__), '..', "assets")])
316
+ allow(ActionController::Base).to receive(:view_paths).and_return([File.join(File.dirname(__FILE__), '..', "assets")])
317
317
 
318
318
  @override = Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :replace => "h1") do
319
319
  "This is replacement text for the h1"
@@ -321,7 +321,7 @@ module Deface
321
321
  end
322
322
 
323
323
  it "should set source to block content" do
324
- @override.source.should == "This is replacement text for the h1"
324
+ expect(@override.source).to eq("This is replacement text for the h1")
325
325
  end
326
326
  end
327
327
 
@@ -332,7 +332,7 @@ module Deface
332
332
  end
333
333
 
334
334
  it "should namespace the override's name" do
335
- @override.name.should == 'spree_engine_sample_name'
335
+ expect(@override.name).to eq('spree_engine_sample_name')
336
336
  end
337
337
  end
338
338
 
@@ -344,7 +344,7 @@ module Deface
344
344
  end
345
345
 
346
346
  it "should namespace the override's name" do
347
- @override.name.should == 'spree_engine_sample_name'
347
+ expect(@override.name).to eq('spree_engine_sample_name')
348
348
  end
349
349
  end
350
350
 
@@ -354,18 +354,18 @@ module Deface
354
354
  end
355
355
 
356
356
  it "should return escaped source" do
357
- @override.source_element.should be_an_instance_of Nokogiri::HTML::DocumentFragment
357
+ expect(@override.source_element).to be_an_instance_of Nokogiri::HTML::DocumentFragment
358
358
 
359
359
  if RUBY_PLATFORM == 'java'
360
360
  source = "<erb loud=\"\"> method :opt =&gt; 'x' &amp; 'y' </erb>"
361
- @override.source_element.to_s.should == source
361
+ expect(@override.source_element.to_s).to eq(source)
362
362
  #do it twice to ensure it doesn't change as it's destructive
363
- @override.source_element.to_s.should == source
363
+ expect(@override.source_element.to_s).to eq(source)
364
364
  else
365
365
  source = "<erb loud> method :opt =&gt; 'x' &amp; 'y' </erb>"
366
- @override.source_element.to_s.should == source
366
+ expect(@override.source_element.to_s).to eq(source)
367
367
  #do it twice to ensure it doesn't change as it's destructive
368
- @override.source_element.to_s.should == source
368
+ expect(@override.source_element.to_s).to eq(source)
369
369
  end
370
370
  end
371
371
  end
@@ -380,8 +380,8 @@ module Deface
380
380
  end
381
381
 
382
382
  it "should return new source" do
383
- @replacement.source.should_not == "<h1>Argh!</h1>"
384
- @replacement.source.should == "<h1>Arrrr!</h1>"
383
+ expect(@replacement.source).not_to eq("<h1>Argh!</h1>")
384
+ expect(@replacement.source).to eq("<h1>Arrrr!</h1>")
385
385
  end
386
386
 
387
387
  end
@@ -396,7 +396,7 @@ module Deface
396
396
  end
397
397
 
398
398
  it "should return new action" do
399
- @replacement.action.should == :insert_after
399
+ expect(@replacement.action).to eq(:insert_after)
400
400
  end
401
401
 
402
402
  it "should remove old action" do
@@ -408,7 +408,7 @@ module Deface
408
408
  describe "when redefining an override when changing source type" do
409
409
  before(:each) do
410
410
  #stub view paths to be local spec/assets directory
411
- ActionController::Base.stub(:view_paths).and_return([File.join(File.dirname(__FILE__), '..', "assets")])
411
+ allow(ActionController::Base).to receive(:view_paths).and_return([File.join(File.dirname(__FILE__), '..', "assets")])
412
412
 
413
413
  Rails.application.config.deface.overrides.all.clear
414
414
  @override = Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :partial => "shared/post", :replace => "h1", :text => "<span>I'm text</span>")
@@ -418,7 +418,7 @@ module Deface
418
418
  end
419
419
 
420
420
  it "should return new source" do
421
- @override.source.should == "<p>I do be a pirate!</p>"
421
+ expect(@override.source).to eq("<p>I do be a pirate!</p>")
422
422
  end
423
423
 
424
424
  end
@@ -430,56 +430,56 @@ module Deface
430
430
  @second = Deface::Override.new(:virtual_path => "posts/index", :name => "second", :insert_after => "li", :text => "<li>second</li>", :sequence => {:after => "first"})
431
431
  @first = Deface::Override.new(:virtual_path => "posts/index", :name => "first", :replace => "li", :text => "<li>first</li>")
432
432
 
433
- @third.sequence.should == 102
434
- @second.sequence.should == 101
435
- @first.sequence.should == 100
433
+ expect(@third.sequence).to eq(102)
434
+ expect(@second.sequence).to eq(101)
435
+ expect(@first.sequence).to eq(100)
436
436
  end
437
437
 
438
438
  it "should calculate correct before sequences" do
439
439
  @second = Deface::Override.new(:virtual_path => "posts/index", :name => "second", :insert_after => "li", :text => "<li>second</li>", :sequence => 99)
440
440
  @first = Deface::Override.new(:virtual_path => "posts/index", :name => "first", :replace => "li", :text => "<li>first</li>", :sequence => {:before => "second"})
441
441
 
442
- @second.sequence.should == 99
443
- @first.sequence.should == 98
442
+ expect(@second.sequence).to eq(99)
443
+ expect(@first.sequence).to eq(98)
444
444
  end
445
445
 
446
446
  it "should calculate correct sequences with invalid hash" do
447
447
  @second = Deface::Override.new(:virtual_path => "posts/index", :name => "second", :insert_after => "li", :text => "<li>second</li>", :sequence => {})
448
448
  @first = Deface::Override.new(:virtual_path => "posts/show", :name => "first", :replace => "li", :text => "<li>first</li>", :sequence => {:before => "second"})
449
449
 
450
- @second.sequence.should == 100
451
- @first.sequence.should == 100
450
+ expect(@second.sequence).to eq(100)
451
+ expect(@first.sequence).to eq(100)
452
452
  end
453
453
 
454
454
  end
455
455
 
456
456
  describe "#end_selector" do
457
457
  it "should return nil when closing_selector is not defined" do
458
- @override.end_selector.should be_nil
458
+ expect(@override.end_selector).to be_nil
459
459
  end
460
460
 
461
461
  it "should return nil when closing_selector is an empty string" do
462
462
  @override = Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :replace => "h1", :closing_selector => "", :text => "<h1>Argh!</h1>")
463
- @override.end_selector.should be_nil
463
+ expect(@override.end_selector).to be_nil
464
464
  end
465
465
 
466
466
  it "should return nil when closing_selector is nil" do
467
467
  @override = Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :replace => "h1", :closing_selector => nil, :text => "<h1>Argh!</h1>")
468
- @override.end_selector.should be_nil
468
+ expect(@override.end_selector).to be_nil
469
469
  end
470
470
 
471
471
  it "should return closing_selector is present" do
472
472
  @override = Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :replace => "h1", :closing_selector => "h4", :text => "<h1>Argh!</h1>")
473
- @override.end_selector.should == "h4"
473
+ expect(@override.end_selector).to eq("h4")
474
474
  end
475
475
  end
476
476
 
477
477
  describe "#touch" do
478
478
  it "should change the overrides :updated_at value" do
479
479
  before_touch = @override.args[:updated_at]
480
- Time.zone.stub(:now).and_return(Time.parse('2006-08-24'))
480
+ allow(Time.zone).to receive(:now).and_return(Time.parse('2006-08-24'))
481
481
  @override.touch
482
- @override.args[:updated_at].should_not == before_touch
482
+ expect(@override.args[:updated_at]).not_to eq(before_touch)
483
483
  end
484
484
  end
485
485
 
@@ -492,18 +492,18 @@ module Deface
492
492
  end
493
493
 
494
494
  it "should return hex digest based on override's args" do
495
- @override.digest.should =~ /[a-f0-9]{32}/
495
+ expect(@override.digest).to match(/[a-f0-9]{32}/)
496
496
  end
497
497
 
498
498
  it "should change the digest when any args change" do
499
499
  @override = Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :replace => "h2", :text => "<h1>Argh!</h1>")
500
- @override.digest.should_not == @digest
500
+ expect(@override.digest).not_to eq(@digest)
501
501
 
502
502
  @override = Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :replace => "h1", :text => "<h1>Argh!</h1>")
503
- @override.digest.should == @digest
503
+ expect(@override.digest).to eq(@digest)
504
504
 
505
505
  @override = Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :replace => "h2", :text => "<h1>I'm a pirate!</h1>")
506
- @override.digest.should_not == @digest
506
+ expect(@override.digest).not_to eq(@digest)
507
507
  end
508
508
  end
509
509
 
@@ -518,28 +518,28 @@ module Deface
518
518
  end
519
519
 
520
520
  it "should return hex digest based on all applicable overrides" do
521
- Deface::Override.digest(:virtual_path => "posts/index").should =~ /[a-f0-9]{32}/
521
+ expect(Deface::Override.digest(:virtual_path => "posts/index")).to match(/[a-f0-9]{32}/)
522
522
  end
523
523
 
524
524
  it "should change the digest when any args change for any override" do
525
525
  @override = Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :replace => "h2", :text => "<h1>Argh!</h1>")
526
- Deface::Override.digest(:virtual_path => "posts/index").should_not == @digest
526
+ expect(Deface::Override.digest(:virtual_path => "posts/index")).not_to eq(@digest)
527
527
 
528
528
  @override = Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :replace => "h1", :text => "<h1>Argh!</h1>")
529
- Deface::Override.digest(:virtual_path => "posts/index").should == @digest
529
+ expect(Deface::Override.digest(:virtual_path => "posts/index")).to eq(@digest)
530
530
 
531
531
  @second = Deface::Override.new(:virtual_path => "posts/index", :name => "2nd", :insert_after => "p", :text => "<pre>this is erb?</pre>")
532
- Deface::Override.digest(:virtual_path => "posts/index").should_not == @digest
532
+ expect(Deface::Override.digest(:virtual_path => "posts/index")).not_to eq(@digest)
533
533
  end
534
534
 
535
535
  it "should change the digest when overrides are removed / added" do
536
536
  Deface::Override.all.clear
537
537
 
538
538
  @new_digest = Deface::Override.digest(:virtual_path => "posts/index")
539
- @new_digest.should_not == @digest
539
+ expect(@new_digest).not_to eq(@digest)
540
540
 
541
541
  @override = Deface::Override.new(:virtual_path => "posts/index", :name => "Posts#index", :replace => "h1", :text => "<h1>Argh!</h1>")
542
- Deface::Override.digest(:virtual_path => "posts/index").should_not == @new_digest
542
+ expect(Deface::Override.digest(:virtual_path => "posts/index")).not_to eq(@new_digest)
543
543
  end
544
544
  end
545
545
 
@@ -564,9 +564,9 @@ module Deface
564
564
 
565
565
  end
566
566
 
567
- ActionView::CompiledTemplates.instance_methods.size.should == 2
567
+ expect(ActionView::CompiledTemplates.instance_methods.size).to eq(2)
568
568
  @override.send(:expire_compiled_template)
569
- ActionView::CompiledTemplates.instance_methods.size.should == 1
569
+ expect(ActionView::CompiledTemplates.instance_methods.size).to eq(1)
570
570
  end
571
571
 
572
572
  it "should not remove compiled method when virtual path and digest matach" do
@@ -577,11 +577,11 @@ module Deface
577
577
  end
578
578
  end
579
579
 
580
- Deface::Override.should_receive(:digest).and_return('e235fa404c3c2281d4f6791162b1c638')
580
+ expect(Deface::Override).to receive(:digest).and_return('e235fa404c3c2281d4f6791162b1c638')
581
581
 
582
- ActionView::CompiledTemplates.instance_methods.size.should == 1
582
+ expect(ActionView::CompiledTemplates.instance_methods.size).to eq(1)
583
583
  @override.send(:expire_compiled_template)
584
- ActionView::CompiledTemplates.instance_methods.size.should == 1
584
+ expect(ActionView::CompiledTemplates.instance_methods.size).to eq(1)
585
585
  end
586
586
  end
587
587