From 0ae70cef678f30e12eb3e24aa69849da0fc7aca7 Mon Sep 17 00:00:00 2001 From: LightGuard Date: Wed, 31 Jul 2013 11:49:21 -0600 Subject: [PATCH] Removes testing deprecations Also some reformating --- spec/asciidoc_handler_spec.rb | 83 +++++++++-------- spec/erb_handler_spec.rb | 64 ++++++------- spec/haml_handler_spec.rb | 121 +++++++++++++------------ spec/javascript_handler_spec.rb | 29 +++--- spec/mustache_handler_spec.rb | 18 ++-- spec/redirect_handler_spec.rb | 38 ++++---- spec/slim_handler_spec.rb | 100 ++++++++++---------- spec/support/shared_handler_example.rb | 16 ++-- 8 files changed, 246 insertions(+), 223 deletions(-) diff --git a/spec/asciidoc_handler_spec.rb b/spec/asciidoc_handler_spec.rb index e167374d..175e6878 100644 --- a/spec/asciidoc_handler_spec.rb +++ b/spec/asciidoc_handler_spec.rb @@ -4,7 +4,7 @@ verify = lambda { |output| include EmmetMatchers # clean whitespace to make comparison easier - output.should have_structure("div#preamble>div.sectionbody>div.paragraph>p>strong") + output.should have_structure('div#preamble>div.sectionbody>div.paragraph>p>strong') } verify_front_matter = lambda { |output, page| @@ -27,46 +27,49 @@ } theories = - [ - { - :page => "asciidoc-page.ad", - :simple_name => "asciidoc-page", - :syntax => :asciidoc, - :extension => '.html', - :matcher => verify - }, - { - :page => "asciidoc-page.adoc", - :simple_name => "asciidoc-page", - :syntax => :asciidoc, - :extension => '.html', - :matcher => verify - }, - { - :page => "asciidoc-page.asciidoc", - :simple_name => "asciidoc-page", - :syntax => :asciidoc, - :extension => '.html', - :matcher => verify - }, - { - :page => "asciidoctor_with_front_matter.ad", - :simple_name => "asciidoctor_with_front_matter", - :syntax => :asciidoc, - :extension => '.html' , - :matcher => verify_front_matter - }, - { - :page => "asciidoctor_with_headers.ad", - :simple_name => "asciidoctor_with_headers", - :syntax => :asciidoc, - :extension => '.html', - :matcher => verify_headers - } - ] + [ + { + :page => 'asciidoc-page.ad', + :simple_name => 'asciidoc-page', + :syntax => :asciidoc, + :extension => '.html', + :matcher => verify + }, + { + :page => 'asciidoc-page.adoc', + :simple_name => 'asciidoc-page', + :syntax => :asciidoc, + :extension => '.html', + :matcher => verify + }, + { + :page => 'asciidoc-page.asciidoc', + :simple_name => 'asciidoc-page', + :syntax => :asciidoc, + :extension => '.html', + :matcher => verify + }, + { + :page => 'asciidoctor_with_front_matter.ad', + :simple_name => 'asciidoctor_with_front_matter', + :syntax => :asciidoc, + :extension => '.html', + :matcher => verify_front_matter + }, + { + :page => 'asciidoctor_with_headers.ad', + :simple_name => 'asciidoctor_with_headers', + :syntax => :asciidoc, + :extension => '.html', + :matcher => verify_headers + } + ] + describe Awestruct::Handlers::AsciidoctorHandler do - let(:additional_config_page) { {:name => 'Awestruct', :test => 10, :layout => 'empty-layout'} } - it_should_behave_like "a handler", theories + def additional_config_page + { :name => 'Awestruct', :test => 10, :layout => 'empty-layout' } + end + it_should_behave_like 'a handler', theories end diff --git a/spec/erb_handler_spec.rb b/spec/erb_handler_spec.rb index e9b8ae09..7c5eafe6 100644 --- a/spec/erb_handler_spec.rb +++ b/spec/erb_handler_spec.rb @@ -3,17 +3,17 @@ require 'rbconfig' verify = lambda { |output| - output.should =~ %r(

This is an ERB page

) - output.should =~ %r(

The fruit of the day is: apples

) - output.should =~ %r(

bacon

) ## interpolated + output.should =~ %r(

This is an ERB page

) + output.should =~ %r(

The fruit of the day is: apples

) + output.should =~ %r(

bacon

) ## interpolated } verify_with_xml = lambda { |output| - output.should =~ %r(bacon) ## interpolated + output.should =~ %r(bacon) ## interpolated } verify_with_utf8 = lambda { |output| - if(RbConfig::CONFIG['target_os'] !~ /mswin|mingw/) + if RbConfig::CONFIG['target_os'] !~ /mswin|mingw/ output.should == "Besøg fra Danmark\n" else output.should == "\r\nBesøg fra Danmark\r\n" @@ -21,32 +21,34 @@ } theories = - [ - { - :page => "erb-page.html.erb", - :simple_name => "erb-page", - :syntax => :erb, - :extension => '.html', - :matcher => verify - }, - { - :page => "erb-page.xml.erb", - :simple_name => "erb-page", - :syntax => :erb, - :extension => '.xml', - :matcher => verify_with_xml - }, - { - :page => "erb-utf-page.html.erb", - :simple_name => "erb-utf-page", - :syntax => :erb, - :extension => '.html', - :matcher => verify_with_utf8 - } - ] + [ + { + :page => 'erb-page.html.erb', + :simple_name => 'erb-page', + :syntax => :erb, + :extension => '.html', + :matcher => verify + }, + { + :page => 'erb-page.xml.erb', + :simple_name => 'erb-page', + :syntax => :erb, + :extension => '.xml', + :matcher => verify_with_xml + }, + { + :page => 'erb-utf-page.html.erb', + :simple_name => 'erb-utf-page', + :syntax => :erb, + :extension => '.html', + :matcher => verify_with_utf8 + } + ] -describe Awestruct::Handlers::TiltHandler.to_s + "-Erb" do - let(:additional_config) { {:crunchy => 'bacon'} } - it_should_behave_like "a handler", theories +describe Awestruct::Handlers::TiltHandler.to_s + '-Erb' do + def additional_config + { :crunchy => 'bacon' } + end + it_should_behave_like 'a handler', theories end diff --git a/spec/haml_handler_spec.rb b/spec/haml_handler_spec.rb index c3b66bc2..6ad0fd59 100644 --- a/spec/haml_handler_spec.rb +++ b/spec/haml_handler_spec.rb @@ -6,12 +6,12 @@ } verify_atom = lambda { |output| - output.should == %( + output.should == ' http://example.com A News Feed -) +' } verify_with_markdown = lambda { |output| @@ -31,63 +31,66 @@ } theories = - [ - { - :page => "haml-page.html.haml", - :simple_name => "haml-page", - :syntax => :haml, - :extension => '.html', - :format => :html5, - :matcher => verify - }, - { - :page => "haml-page.xml.haml", - :simple_name => "haml-page", - :syntax => :haml, - :extension => '.xml', - :format => :xhtml, - :matcher => verify - }, - { - :page => 'haml-page.atom.haml', - :simple_name => 'haml-page', - :syntax => :haml, - :extension => '.atom', - :format => :xhtml, - :matcher => verify_atom - }, - { - :page => "haml-with-markdown-page.html.haml", - :simple_name => "haml-with-markdown-page", - :syntax => :haml, - :extension => '.html', - :matcher => verify_with_markdown - }, - { - :page => "haml-with-textile-page.html.haml", - :simple_name => "haml-with-textile-page", - :syntax => :haml, - :extension => '.html', - :matcher => verify_with_textile - }, - { - :page => "haml-with-utf.html.haml", - :simple_name => "haml-with-utf", - :syntax => :haml, - :extension => '.html', - :matcher => verify_with_utf8 - }, - { - :page => "haml-with-variables.html.haml", - :simple_name => "haml-with-variables", - :syntax => :haml, - :extension => '.html', - :matcher => verify_with_variables - } - ] + [ + { + :page => 'haml-page.html.haml', + :simple_name => 'haml-page', + :syntax => :haml, + :extension => '.html', + :format => :html5, + :matcher => verify + }, + { + :page => 'haml-page.xml.haml', + :simple_name => 'haml-page', + :syntax => :haml, + :extension => '.xml', + :format => :xhtml, + :matcher => verify + }, + { + :page => 'haml-page.atom.haml', + :simple_name => 'haml-page', + :syntax => :haml, + :extension => '.atom', + :format => :xhtml, + :matcher => verify_atom + }, + { + :page => 'haml-with-markdown-page.html.haml', + :simple_name => 'haml-with-markdown-page', + :syntax => :haml, + :extension => '.html', + :matcher => verify_with_markdown + }, + { + :page => 'haml-with-textile-page.html.haml', + :simple_name => 'haml-with-textile-page', + :syntax => :haml, + :extension => '.html', + :matcher => verify_with_textile + }, + { + :page => 'haml-with-utf.html.haml', + :simple_name => 'haml-with-utf', + :syntax => :haml, + :extension => '.html', + :matcher => verify_with_utf8 + }, + { + :page => 'haml-with-variables.html.haml', + :simple_name => 'haml-with-variables', + :syntax => :haml, + :extension => '.html', + :matcher => verify_with_variables + } + ] -describe Awestruct::Handlers::TiltHandler.to_s + "-Haml" do - let(:additional_config) { {:crunchy => 'bacon'} } - it_should_behave_like "a handler", theories +describe Awestruct::Handlers::TiltHandler.to_s + '-Haml' do + def additional_config + { :crunchy => 'bacon' } + end + + it_should_behave_like 'a handler', theories end diff --git a/spec/javascript_handler_spec.rb b/spec/javascript_handler_spec.rb index 618e4c44..099aa1bd 100644 --- a/spec/javascript_handler_spec.rb +++ b/spec/javascript_handler_spec.rb @@ -2,22 +2,25 @@ require 'spec_helper' verify = lambda { |output| - output.should =~ %r(var crunchy = "bacon") + output.should =~ %r(var crunchy = "bacon") } theories = - [ - { - :page => "javascript-page.js", - :simple_name => "javascript-page", - :syntax => :javascript, - :extension => '.js', - :matcher => verify - } - ] + [ + { + :page => 'javascript-page.js', + :simple_name => 'javascript-page', + :syntax => :javascript, + :extension => '.js', + :matcher => verify + } + ] -describe Awestruct::Handlers::TiltHandler.to_s + "-JavaScript" do - let(:additional_config) { {:interpolate => true, :crunchy => 'bacon'} } - it_should_behave_like "a handler", theories +describe Awestruct::Handlers::TiltHandler.to_s + '-JavaScript' do + def additional_config + { :interpolate => true, :crunchy => 'bacon' } + end + + it_should_behave_like 'a handler', theories end \ No newline at end of file diff --git a/spec/mustache_handler_spec.rb b/spec/mustache_handler_spec.rb index c77a1750..7173aa51 100644 --- a/spec/mustache_handler_spec.rb +++ b/spec/mustache_handler_spec.rb @@ -7,23 +7,27 @@ theories = [ { - :page => "mustache-page.html.mustache", - :simple_name => "mustache-page", + :page => 'mustache-page.html.mustache', + :simple_name => 'mustache-page', :syntax => :mustache, :extension => '.html', :matcher => verify }, { - :page => "mustache-page.xml.mustache", - :simple_name => "mustache-page", + :page => 'mustache-page.xml.mustache', + :simple_name => 'mustache-page', :syntax => :mustache, :extension => '.xml', :matcher => verify } ] -describe Awestruct::Handlers::TiltHandler.to_s + "-Mustache" do - let(:additional_config) { {:markup_type => 'Mustache'} } - it_should_behave_like "a handler", theories + +describe Awestruct::Handlers::TiltHandler.to_s + '-Mustache' do + def additional_config + {:markup_type => 'Mustache'} + end + + it_should_behave_like 'a handler', theories end \ No newline at end of file diff --git a/spec/redirect_handler_spec.rb b/spec/redirect_handler_spec.rb index 3ab4f94d..4a4cfa76 100644 --- a/spec/redirect_handler_spec.rb +++ b/spec/redirect_handler_spec.rb @@ -8,25 +8,29 @@ } theories = - [ - { - :page => "simple-redirect-page.redirect", - :simple_name => "simple-redirect-page", - :syntax => :text, - :extension => '.html', - :matcher => verify - }, - { - :page => "redirect-page.redirect", - :simple_name => "redirect-page", - :syntax => :text, - :extension => '.html', - :matcher => verify_with_interpol - } - ] + [ + { + :page => "simple-redirect-page.redirect", + :simple_name => "simple-redirect-page", + :syntax => :text, + :extension => '.html', + :matcher => verify + }, + { + :page => "redirect-page.redirect", + :simple_name => "redirect-page", + :syntax => :text, + :extension => '.html', + :matcher => verify_with_interpol + } + ] + describe Awestruct::Handlers::TiltHandler.to_s + "-Redirect" do - let(:additional_config) { {:interpolate => true, :crunchy => 'bacon', :base_url => 'http://mysite' } } + def additional_config + { :interpolate => true, :crunchy => 'bacon', :base_url => 'http://mysite' } + end + it_should_behave_like "a handler", theories end diff --git a/spec/slim_handler_spec.rb b/spec/slim_handler_spec.rb index bf9c1ccc..83ba2922 100644 --- a/spec/slim_handler_spec.rb +++ b/spec/slim_handler_spec.rb @@ -26,56 +26,58 @@ } theories = - [ - { - :page => 'slim-page.html.slim', - :simple_name => 'slim-page', - :syntax => :slim, - :extension => '.html', - :format => :html5, - :matcher => verify - }, - { - :page => 'slim-page.xml.slim', - :simple_name => 'slim-page', - :syntax => :slim, - :extension => '.xml', - :format => :xhtml, - :matcher => verify - }, - { - :page => 'slim-page.atom.slim', - :simple_name => 'slim-page', - :syntax => :slim, - :extension => '.atom', - :format => :xhtml, - :matcher => verify_atom - }, - { - :page => 'slim-with-markdown-page.html.slim', - :simple_name => 'slim-with-markdown-page', - :syntax => :slim, - :extension => '.html', - :matcher => verify_with_markdown - }, - { - :page => 'slim-with-utf.html.slim', - :simple_name => 'slim-with-utf', - :syntax => :slim, - :extension => '.html', - :matcher => verify_with_utf8 - }, - { - :page => 'slim-with-variables.html.slim', - :simple_name => 'slim-with-variables', - :syntax => :slim, - :extension => '.html', - :matcher => verify_with_variables - } - ] + [ + { + :page => 'slim-page.html.slim', + :simple_name => 'slim-page', + :syntax => :slim, + :extension => '.html', + :format => :html5, + :matcher => verify + }, + { + :page => 'slim-page.xml.slim', + :simple_name => 'slim-page', + :syntax => :slim, + :extension => '.xml', + :format => :xhtml, + :matcher => verify + }, + { + :page => 'slim-page.atom.slim', + :simple_name => 'slim-page', + :syntax => :slim, + :extension => '.atom', + :format => :xhtml, + :matcher => verify_atom + }, + { + :page => 'slim-with-markdown-page.html.slim', + :simple_name => 'slim-with-markdown-page', + :syntax => :slim, + :extension => '.html', + :matcher => verify_with_markdown + }, + { + :page => 'slim-with-utf.html.slim', + :simple_name => 'slim-with-utf', + :syntax => :slim, + :extension => '.html', + :matcher => verify_with_utf8 + }, + { + :page => 'slim-with-variables.html.slim', + :simple_name => 'slim-with-variables', + :syntax => :slim, + :extension => '.html', + :matcher => verify_with_variables + } + ] describe Awestruct::Handlers::TiltHandler.to_s + '-Slim' do - let(:additional_config) { {:crunchy => 'bacon'} } - it_should_behave_like 'a handler', theories + def additional_config + { :crunchy => 'bacon' } + end + it_should_behave_like 'a handler', theories end diff --git a/spec/support/shared_handler_example.rb b/spec/support/shared_handler_example.rb index dfcb9102..121d2d6f 100644 --- a/spec/support/shared_handler_example.rb +++ b/spec/support/shared_handler_example.rb @@ -7,14 +7,14 @@ REQUIRED_VARIABLES = [:page, :simple_name, :syntax, :extension] ALL_VARIABLES = REQUIRED_VARIABLES + [:format, :matcher, :unless] -shared_examples "a handler" do |theories| +shared_examples 'a handler' do |theories| def handler_file(path) "#{@site.config.dir}/#{path}" end def create_context - Hashery::OpenCascade[ { :site=>@site } ] + Hashery::OpenCascade[{ :site => @site }] end describe Awestruct::Handlers do @@ -22,10 +22,12 @@ def create_context before :all do @engine = Awestruct::Engine.new( - Awestruct::Config.new( File.expand_path(File.dirname(__FILE__) + '/../') + '/test-data/handlers' )) + Awestruct::Config.new(File.expand_path(File.dirname(__FILE__) + '/../') + '/test-data/handlers')) @engine.load_default_site_yaml @site = @engine.site + end + before :each do @site.merge! additional_config if respond_to?("additional_config") end @@ -62,7 +64,7 @@ def create_handler(page) handler.output_extension.should == theory[:extension] end - if !theory[:format].nil? + unless theory[:format].nil? it "should set the engine format '#{theory[:format]}' for page '#{theory[:page]}'" do page = create_handler theory[:page] handler = page.handler @@ -74,13 +76,13 @@ def create_handler(page) end end - if !theory[:matcher].nil? + unless theory[:matcher].nil? it "should render page '#{theory[:page]}'" do if theory[:unless].nil? or !theory[:unless][:exp].call() handler = create_handler theory[:page] - handler.update(additional_config_page) {|k, oldval, newval| oldval } if respond_to?("additional_config_page") - output = handler.rendered_content( handler.create_context ) + handler.update(additional_config_page) { |k, oldval, newval| oldval } if respond_to?('additional_config_page') + output = handler.rendered_content(handler.create_context) output.should_not be_nil theory[:matcher].call(output, handler) if theory[:matcher].arity == 2