From 5c2defac6d941b55f13c26d1faa2bbe213e7b34a Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Sat, 23 Jul 2011 22:49:32 -0700 Subject: [PATCH] add tests for relative custom image paths. fixes #59 --- features/relative_assets.feature | 34 +++++++++++++++++- features/step_definitions/asset_host_steps.rb | 10 +++--- features/step_definitions/middleman_steps.rb | 19 +++++----- .../step_definitions/page_layout_steps.rb | 18 ++++------ fixtures/test-app/config.rb | 1 + fixtures/test-app/source/img/blank.gif | Bin 0 -> 43 bytes .../test-app/source/relative_image.html.erb | 1 + 7 files changed, 57 insertions(+), 26 deletions(-) create mode 100755 fixtures/test-app/source/img/blank.gif create mode 100644 fixtures/test-app/source/relative_image.html.erb diff --git a/features/relative_assets.feature b/features/relative_assets.feature index bfca1c8a..cb732b7e 100644 --- a/features/relative_assets.feature +++ b/features/relative_assets.feature @@ -3,10 +3,42 @@ Feature: Relative Assets Scenario: Rendering css with the feature disabled Given "relative_assets" feature is "disabled" + And the Server is running When I go to "/stylesheets/relative_assets.css" Then I should not see "url('../" + And I should see "url('/images/blank.gif" + + Scenario: Rendering html with the feature disabled + Given "relative_assets" feature is "disabled" + And the Server is running + When I go to "/relative_image.html" + Then I should see "/images/blank.gif" Scenario: Rendering css with the feature enabled Given "relative_assets" feature is "enabled" + And the Server is running When I go to "/stylesheets/relative_assets.css" - Then I should see "url('../" \ No newline at end of file + Then I should see "url('../images/blank.gif" + + Scenario: Rendering html with the feature disabled + Given "relative_assets" feature is "enabled" + And the Server is running + When I go to "/relative_image.html" + Then I should not see "/images/blank.gif" + And I should see "images/blank.gif" + + Scenario: Rendering html with a custom images_dir + Given "relative_assets" feature is "enabled" + And "images_dir" is set to "img" + And the Server is running + When I go to "/stylesheets/relative_assets.css" + Then I should see "url('../img/blank.gif" + + Scenario: Rendering css with a custom images_dir + Given "relative_assets" feature is "enabled" + And "images_dir" is set to "img" + And the Server is running + When I go to "/relative_image.html" + Then I should not see "/images/blank.gif" + Then I should not see "/img/blank.gif" + And I should see "img/blank.gif" \ No newline at end of file diff --git a/features/step_definitions/asset_host_steps.rb b/features/step_definitions/asset_host_steps.rb index 3987586c..c801f2c1 100644 --- a/features/step_definitions/asset_host_steps.rb +++ b/features/step_definitions/asset_host_steps.rb @@ -1,9 +1,7 @@ Given /^I am using an asset host$/ do - sandbox_server = Middleman.server do - activate :asset_host - set :asset_host do |asset| - "http://assets%d.example.com" % (asset.hash % 4) - end + @server ||= Middleman.server + @server.activate :asset_host + @server.set :asset_host do |asset| + "http://assets%d.example.com" % (asset.hash % 4) end - @browser = Rack::Test::Session.new(Rack::MockSession.new(sandbox_server.new)) end \ No newline at end of file diff --git a/features/step_definitions/middleman_steps.rb b/features/step_definitions/middleman_steps.rb index a4cfff01..eda0869d 100644 --- a/features/step_definitions/middleman_steps.rb +++ b/features/step_definitions/middleman_steps.rb @@ -1,11 +1,14 @@ Given /^"([^\"]*)" feature is "([^\"]*)"$/ do |feature, state| - sandbox_server = Middleman.server do - if state == "enabled" - activate(feature.to_sym) - end - set :environment, @current_env || :development + @server ||= Middleman.server + if state == "enabled" + @server.activate(feature.to_sym) end - @browser = Rack::Test::Session.new(Rack::MockSession.new(sandbox_server.new)) + @server.set :environment, @current_env || :development +end + +Given /^"([^\"]*)" is set to "([^\"]*)"$/ do |variable, value| + @server ||= Middleman.server + @server.set variable.to_sym, value end Given /^current environment is "([^\"]*)"$/ do |env| @@ -13,8 +16,8 @@ Given /^current environment is "([^\"]*)"$/ do |env| end Given /^the Server is running$/ do - sandbox_server = Middleman.server - @browser = Rack::Test::Session.new(Rack::MockSession.new(sandbox_server.new)) + @server ||= Middleman.server + @browser = Rack::Test::Session.new(Rack::MockSession.new(@server.new)) end When /^I go to "([^\"]*)"$/ do |url| diff --git a/features/step_definitions/page_layout_steps.rb b/features/step_definitions/page_layout_steps.rb index 68b42bca..0595e0bd 100644 --- a/features/step_definitions/page_layout_steps.rb +++ b/features/step_definitions/page_layout_steps.rb @@ -1,17 +1,13 @@ Given /^page "([^\"]*)" has layout "([^\"]*)"$/ do |url, layout| - sandbox_server = Middleman.server do - set :root, File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "fixtures", "test-app") - page(url, :layout => layout.to_sym) - end - @browser = Rack::Test::Session.new(Rack::MockSession.new(sandbox_server.new)) + @server ||= Middleman.server + @server.set :root, File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "fixtures", "test-app") + @server.page(url, :layout => layout.to_sym) end Given /^"([^\"]*)" with_layout block has layout "([^\"]*)"$/ do |url, layout| - sandbox_server = Middleman.server do - set :root, File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "fixtures", "test-app") - with_layout(layout.to_sym) do - page(url) - end + @server ||= Middleman.server + @server.set :root, File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "fixtures", "test-app") + @server.with_layout(layout.to_sym) do + page(url) end - @browser = Rack::Test::Session.new(Rack::MockSession.new(sandbox_server.new)) end \ No newline at end of file diff --git a/fixtures/test-app/config.rb b/fixtures/test-app/config.rb index 196a080a..aa15121d 100644 --- a/fixtures/test-app/config.rb +++ b/fixtures/test-app/config.rb @@ -7,6 +7,7 @@ page "/fake.html", :proxy => "/real.html", :layout => false end with_layout false do + page "/relative_image.html" page "/inline-css.html" page "/inline-js.html" page "/inline-coffeescript.html" diff --git a/fixtures/test-app/source/img/blank.gif b/fixtures/test-app/source/img/blank.gif new file mode 100755 index 0000000000000000000000000000000000000000..2498f1aac58dab923f0fd99b1c8ee6b8c53c7158 GIT binary patch literal 43 scmZ?wbhEHbWMp7uXkcKtd-pB_1B2pE79h#MpaUX6G7L;iE{qJ;0KEqWk^lez literal 0 HcmV?d00001 diff --git a/fixtures/test-app/source/relative_image.html.erb b/fixtures/test-app/source/relative_image.html.erb new file mode 100644 index 00000000..fb441334 --- /dev/null +++ b/fixtures/test-app/source/relative_image.html.erb @@ -0,0 +1 @@ +<%= image_tag "blank.gif" %> \ No newline at end of file