Use spork for forked cucumber tests, build images first to appease Compass

This commit is contained in:
Thomas Reynolds 2011-06-24 12:06:28 -07:00
parent b585e0775b
commit f977d284fc
8 changed files with 99 additions and 22 deletions

View file

@ -4,7 +4,19 @@ Bundler::GemHelper.install_tasks
require 'cucumber/rake/task' require 'cucumber/rake/task'
Cucumber::Rake::Task.new(:cucumber, 'Run features that should pass') do |t| Cucumber::Rake::Task.new(:cucumber, 'Run features that should pass') do |t|
t.cucumber_opts = "--color --tags ~@wip --strict --format #{ENV['CUCUMBER_FORMAT'] || 'pretty'}" t.cucumber_opts = "--drb --color --tags ~@wip --strict --format #{ENV['CUCUMBER_FORMAT'] || 'pretty'}"
end
namespace :spork do
desc "start spork in background"
task :start do
sh %{spork &}
end
desc "stop spork"
task :stop do
Process.kill(:TERM, `ps -ef | grep spork | grep -v grep | awk '{ print $2 }'`.to_i)
end
end end
#$LOAD_PATH.unshift 'lib' #$LOAD_PATH.unshift 'lib'
@ -12,7 +24,7 @@ end
require 'rake/testtask' require 'rake/testtask'
require 'rake/clean' require 'rake/clean'
task :test => :cucumber task :test => ["spork:start", "cucumber", "spork:stop"]
# rocco depends on rdiscount, which makes me sad. # rocco depends on rdiscount, which makes me sad.
unless defined?(JRUBY_VERSION) unless defined?(JRUBY_VERSION)

View file

@ -14,7 +14,7 @@ end
Given /^cleanup built test app$/ do Given /^cleanup built test app$/ do
target = File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "fixtures", "test-app", "build") target = File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "fixtures", "test-app", "build")
FileUtils.rm_rf(target) # FileUtils.rm_rf(target)
end end
Then /^"([^"]*)" should exist and include "([^"]*)"$/ do |target_file, expected| Then /^"([^"]*)" should exist and include "([^"]*)"$/ do |target_file, expected|

View file

@ -1,9 +0,0 @@
ENV["MM_DIR"] = File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "fixtures", "test-app")
require File.join(File.dirname(File.dirname(File.dirname(__FILE__))), 'lib', 'middleman')
require "rack/test"
# absolute views path
# otherwise resolve_template (padrino-core) can't find templates
Before do
Middleman::Server.views = File.join(Middleman::Server.root, "source")
end

53
features/support/env.rb Normal file
View file

@ -0,0 +1,53 @@
require 'rubygems'
require 'spork'
root_path = File.dirname(File.dirname(File.dirname(__FILE__)))
Spork.prefork do
# Loading more in this block will cause your tests to run faster. However,
# if you change any configuration or code from libraries loaded here, you'll
# need to restart spork for it take effect.
ENV["MM_DIR"] = File.join(root_path, "fixtures", "test-app")
end
Spork.each_run do
# This code will be run each time you run your specs.
require File.join(root_path, 'lib', 'middleman')
require "rack/test"
# absolute views path
# otherwise resolve_template (padrino-core) can't find templates
Before do
Middleman::Server.views = File.join(Middleman::Server.root, "source")
end
end
# --- Instructions ---
# Sort the contents of this file into a Spork.prefork and a Spork.each_run
# block.
#
# The Spork.prefork block is run only once when the spork server is started.
# You typically want to place most of your (slow) initializer code in here, in
# particular, require'ing any 3rd-party gems that you don't normally modify
# during development.
#
# The Spork.each_run block is run each time you run your specs. In case you
# need to load files that tend to change during development, require them here.
# With Rails, your application modules are loaded automatically, so sometimes
# this block can remain empty.
#
# Note: You can modify files loaded *from* the Spork.each_run block without
# restarting the spork server. However, this file itself will not be reloaded,
# so if you change any of the code inside the each_run block, you still need to
# restart the server. In general, if you have non-trivial code in this file,
# it's advisable to move it into a separate file so you can easily edit it
# without restarting spork. (For example, with RSpec, you could move
# non-trivial code into a file spec/support/my_helper.rb, making sure that the
# spec/support/* files are require'd from inside the each_run block.)
#
# Any code that is left outside the two blocks will be run during preforking
# *and* during each_run -- that's probably not what you want.
#
# These instructions should self-destruct in 10 seconds. If they don't, feel
# free to delete them.

View file

@ -84,7 +84,25 @@ module Middleman
def handle_directory(lookup) def handle_directory(lookup)
lookup = File.join(lookup, '*') lookup = File.join(lookup, '*')
Dir[lookup].sort.each do |file_source| results = Dir[lookup].sort do |a, b|
simple_a = a.gsub(Middleman::Server.root + "/", '')
.gsub(Middleman::Server.views + "/", '')
simple_b = b.gsub(Middleman::Server.root + "/", '')
.gsub(Middleman::Server.views + "/", '')
a_dir = simple_a.split("/").first
b_dir = simple_b.split("/").first
if a_dir == Middleman::Server.images_dir
-1
elsif b_dir == Middleman::Server.images_dir
1
else
0
end
end
results.each do |file_source|
if File.directory?(file_source) if File.directory?(file_source)
handle_directory(file_source) handle_directory(file_source)
next next

View file

@ -78,7 +78,7 @@ module Middleman::Features
autoload :Blog, "middleman/features/blog" autoload :Blog, "middleman/features/blog"
# Proxy web services requests in dev mode only # Proxy web services requests in dev mode only
# autoload :Proxy, "middleman/features/proxy" autoload :Proxy, "middleman/features/proxy"
# Automatically resize images for mobile devises # Automatically resize images for mobile devises
# autoload :TinySrc, "middleman/features/tiny_src" # autoload :TinySrc, "middleman/features/tiny_src"

View file

@ -9,25 +9,27 @@ module Middleman
class << self class << self
def registered(app) def registered(app)
app.after_feature_init do app.after_feature_init do
views_root = File.basename(self.views)
::Compass.configuration do |config| ::Compass.configuration do |config|
config.cache_path = File.join(self.root, ".sass-cache") # For sassc files config.cache_path = File.join(self.root, ".sass-cache") # For sassc files
config.project_path = self.root config.project_path = self.root
config.sass_dir = File.join(File.basename(self.views), self.css_dir) config.sass_dir = File.join(views_root, self.css_dir)
config.output_style = :nested config.output_style = :nested
config.fonts_dir = File.join(File.basename(self.views), self.fonts_dir) config.fonts_dir = File.join(views_root, self.fonts_dir)
config.css_dir = File.join(File.basename(self.views), self.css_dir) config.css_dir = File.join(views_root, self.css_dir)
config.images_dir = File.join(File.basename(self.views), self.images_dir) config.images_dir = File.join(views_root, self.images_dir)
config.http_images_path = self.http_images_path rescue File.join(self.http_prefix || "/", self.images_dir) config.http_images_path = self.http_images_path rescue File.join(self.http_prefix || "/", self.images_dir)
config.http_stylesheets_path = self.http_css_path rescue File.join(self.http_prefix || "/", self.css_dir) config.http_stylesheets_path = self.http_css_path rescue File.join(self.http_prefix || "/", self.css_dir)
config.asset_cache_buster { false } config.asset_cache_buster :none
config.add_import_path(config.sass_dir) config.add_import_path(config.sass_dir)
end end
configure :build do configure :build do
build_root = File.basename(self.build_dir)
::Compass.configuration do |config| ::Compass.configuration do |config|
config.css_dir = File.join(File.basename(self.build_dir), self.css_dir) config.css_dir = File.join(build_root, self.css_dir)
config.images_dir = File.join(File.basename(self.build_dir), self.images_dir) config.images_dir = File.join(build_root, self.images_dir)
end end
end end
end end

View file

@ -31,10 +31,11 @@ Gem::Specification.new do |s|
s.add_runtime_dependency("haml", ["~> 3.1.0"]) s.add_runtime_dependency("haml", ["~> 3.1.0"])
s.add_runtime_dependency("coffee-filter", ["~> 0.1.0"]) s.add_runtime_dependency("coffee-filter", ["~> 0.1.0"])
s.add_runtime_dependency("sass", ["~> 3.1.0"]) s.add_runtime_dependency("sass", ["~> 3.1.0"])
s.add_runtime_dependency("compass", ["0.11.2"]) s.add_runtime_dependency("compass", ["~> 0.11.3"])
s.add_runtime_dependency("compass-susy-plugin", ["~> 0.9.0"]) s.add_runtime_dependency("compass-susy-plugin", ["~> 0.9.0"])
s.add_runtime_dependency("coffee-script", ["~> 2.2.0"]) s.add_runtime_dependency("coffee-script", ["~> 2.2.0"])
s.add_runtime_dependency("httparty", ["~> 0.7.0"]) s.add_runtime_dependency("httparty", ["~> 0.7.0"])
s.add_development_dependency("spork", ["~> 0.9.0.rc8"])
s.add_development_dependency("cucumber", ["~> 0.10.0"]) s.add_development_dependency("cucumber", ["~> 0.10.0"])
s.add_development_dependency("rake", ["0.8.7"]) s.add_development_dependency("rake", ["0.8.7"])
s.add_development_dependency("rspec", [">= 0"]) s.add_development_dependency("rspec", [">= 0"])