remove rspec, convert everything to cucumber

This commit is contained in:
tdreyno 2010-09-06 10:59:51 -07:00
parent b3ee656a0e
commit 4ba90bf1c7
52 changed files with 201 additions and 151 deletions

View file

@ -1,18 +1,17 @@
require 'lib/middleman' require 'lib/middleman'
require 'rake' require 'rake'
require 'spec/rake/spectask'
require 'cucumber/rake/task' require 'cucumber/rake/task'
begin begin
require 'jeweler' require 'jeweler'
Jeweler::Tasks.new do |gem| Jeweler::Tasks.new do |gem|
gem.name = "middleman" gem.name = "middleman"
gem.summary = %Q{A static site generator utilizing Haml, Sass and providing YUI compression and cache busting} gem.summary = %Q{A static site generator utilizing Haml, Sass and providing YUI compression and cache busting}
gem.email = "tdreyno@gmail.com" gem.email = "tdreyno@gmail.com"
gem.homepage = "http://wiki.github.com/tdreyno/middleman" gem.homepage = "http://wiki.github.com/tdreyno/middleman"
gem.authors = ["Thomas Reynolds"] gem.authors = ["Thomas Reynolds"]
gem.rubyforge_project = "middleman" gem.rubyforge_project = "middleman"
gem.executables = %w(mm-init mm-build mm-server) gem.executables = %w(mm-init mm-build mm-server)
gem.add_dependency("rack", "~>1.0") gem.add_dependency("rack", "~>1.0")
gem.add_dependency("thin", "~>1.2.0") gem.add_dependency("thin", "~>1.2.0")
gem.add_dependency("shotgun", "~>0.8.0") gem.add_dependency("shotgun", "~>0.8.0")
@ -28,7 +27,6 @@ begin
gem.add_dependency("compass-slickmap", "~>0.4.0") gem.add_dependency("compass-slickmap", "~>0.4.0")
# gem.add_dependency("livereload", "~>1.4.0") # gem.add_dependency("livereload", "~>1.4.0")
gem.add_development_dependency("rspec")
gem.add_development_dependency("cucumber") gem.add_development_dependency("cucumber")
gem.add_development_dependency("jeweler") gem.add_development_dependency("jeweler")
end end
@ -38,15 +36,8 @@ rescue LoadError
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler" puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
end end
Spec::Rake::SpecTask.new(:spec) do |spec|
spec.libs << 'lib' << 'spec'
spec.spec_files = FileList['spec/**/*_spec.rb']
end
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 = "--color --tags ~@wip --strict --format #{ENV['CUCUMBER_FORMAT'] || 'pretty'}"
end end
task :spec => :check_dependencies task :default => :cucumber
task :default => [:cucumber, :spec]

16
features/builder.feature Normal file
View file

@ -0,0 +1,16 @@
Feature: Builder
In order to output static html and css for delivery
Scenario: Checking built folder for content
Given a built test app
Then "index.html" should exist and include "Comment in layout"
Then "javascripts/coffee_test.js" should exist and include "Array.prototype.slice"
Then "index.html" should exist and include "<h1>Welcome</h1>"
Then "static.html" should exist and include "Static, no code!"
Then "services/index.html" should exist and include "Services"
Then "stylesheets/site.css" should exist and include "html, body, div, span"
Then "stylesheets/site_scss.css" should exist and include "html, body, div, span"
Then "stylesheets/test_less.css" should exist and include "666"
Then "stylesheets/static.css" should exist and include "body"
Then "_partial.html" should not exist
And cleanup built test app

View file

@ -0,0 +1,7 @@
Feature: Support coffee-script
In order to offer an alternative when writing Javascript
Scenario: Rendering coffee script
Given the Server is running
When I go to "/javascripts/coffee_test.js"
Then I should see "Array.prototype.slice"

View file

@ -0,0 +1,17 @@
Feature: Built-in auto_stylesheet_link_tag view helper
In order to simplify including css files
Scenario: Viewing the root path
Given the Server is running
When I go to "/auto-css.html"
Then I should see "stylesheets/auto-css.css"
Scenario: Viewing a tier-1 path
Given the Server is running
When I go to "/sub1/auto-css.html"
Then I should see "stylesheets/sub1/auto-css.css"
Scenario: Viewing a tier-2 path
Given the Server is running
When I go to "/sub1/sub2/auto-css.html"
Then I should see "stylesheets/sub1/sub2/auto-css.css"

View file

@ -0,0 +1,17 @@
Feature: Built-in page_classes view helper
In order to generate body classes for views
Scenario: Viewing the root path
Given the Server is running
When I go to "/page-class.html"
Then I should see "page-class"
Scenario: Viewing a tier-1 path
Given the Server is running
When I go to "/sub1/page-class.html"
Then I should see "sub1 sub1_page-class"
Scenario: Viewing a tier-2 path
Given the Server is running
When I go to "/sub1/sub2/page-class.html"
Then I should see "sub1 sub1_sub2 sub1_sub2_page-class"

View file

@ -0,0 +1,31 @@
Feature: Built-in macro view helpers
In order to simplify generating HTML
Scenario: Using the link_to helper
Given the Server is running
When I go to "/link_to.html"
Then I should see '<a href="#">No Href</a>'
And I should see '<a href="test.com">Has Href</a>'
And I should see '<a class="test" href="test2.com">Has param</a>'
Scenario: Using the image_tag helper
Given the Server is running
When I go to "/image_tag.html"
Then I should see '<img src="/images/test.png" alt="" />'
And I should see '<img src="/images/test2.png" alt="alt" />'
Scenario: Using the javascript_include_tag helper
Given the Server is running
When I go to "/javascript_include_tag.html"
Then I should see '<script type="text/javascript" src="/javascripts/test1.js"></script>'
Then I should see '<script type="text/javascript" src="/javascripts/test2.js"></script>'
Then I should see '<script type="text/javascript" src="/javascripts/test3.js"></script>'
Then I should see '<script type="text/javascript" src="http://test.com/javascripts/test4.js"></script>'
Scenario: Using the stylesheet_link_tag helper
Given the Server is running
When I go to "/stylesheet_link_tag.html"
Then I should see '<link type="text/css" rel="stylesheet" href="/stylesheets/test1.css" />'
Then I should see '<link type="text/css" rel="stylesheet" href="/stylesheets/test2.css" />'
Then I should see '<link type="text/css" rel="stylesheet" href="/stylesheets/test3.css" />'
Then I should see '<link type="text/css" rel="stylesheet" href="http://test.com/stylesheets/test4.css" />'

View file

@ -0,0 +1,7 @@
Feature: Support Less CSS
In order to offer an alternative when writing CSS
Scenario: Rendering Less
Given the Server is running
When I go to "/stylesheets/test_less.css"
Then I should see "666"

View file

@ -0,0 +1,7 @@
Feature: Support SCSS Syntax
In order to offer an alternative when writing Sass
Scenario: Rendering scss
Given the Server is running
When I go to "/stylesheets/site_scss.css"
Then I should see "html,body,div,span,applet,object,iframe"

View file

@ -0,0 +1,45 @@
require 'fileutils'
Given /^a built test app$/ do
target = File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "fixtures", "test-app")
build_cmd = File.expand_path(File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "bin", "mm-build"))
`cd #{target} && MM_DIR="#{target}" #{build_cmd}`
end
Given /^cleanup built test app$/ do
target = File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "fixtures", "test-app", "build")
FileUtils.rm_rf(target)
end
Then /^"([^"]*)" should exist and include "([^"]*)"$/ do |target_file, expected|
target = File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "fixtures", "test-app", "build", target_file)
File.exists?(target).should be_true
File.read(target).should include(expected)
end
Then /^"([^"]*)" should not exist$/ do |target_file|
target = File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "fixtures", "test-app", "build", target_file)
File.exists?(target).should be_false
end
# require 'fileutils'
#
# describe "Builder" do
# def project_file(*parts)
# File.expand_path(File.join(File.dirname(__FILE__), "..", *parts))
# end
#
# before :all do
# @root_dir = project_file("spec", "fixtures", "sample")
# end
#
# before :each do
# build_cmd = project_file("bin", "mm-build")
# `cd #{@root_dir} && MM_DIR="#{@root_dir}" #{build_cmd}`
# end
#
# after :each do
# FileUtils.rm_rf(File.join(@root_dir, "build"))
# end

View file

@ -1,3 +1,3 @@
ENV["MM_DIR"] = File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "spec", "fixtures", "sample") 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 File.join(File.dirname(File.dirname(File.dirname(__FILE__))), 'lib', 'middleman')
require "rack/test" require "rack/test"

View file

@ -1,7 +1,13 @@
require 'fileutils' require 'fileutils'
Given /^generated directory at "([^\"]*)"$/ do |dirname|
target = File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "fixtures", dirname)
init_cmd = File.expand_path(File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "bin", "mm-init"))
`cd #{File.dirname(target)} && #{init_cmd} #{File.basename(target)}`
end
Then /^template files should exist at "([^\"]*)"$/ do |dirname| Then /^template files should exist at "([^\"]*)"$/ do |dirname|
target = File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "spec", "fixtures", dirname) target = File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "fixtures", dirname)
template_glob = File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "lib", "middleman", "template", "*/**/*") template_glob = File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "lib", "middleman", "template", "*/**/*")
Dir[template_glob].each do |f| Dir[template_glob].each do |f|
@ -11,7 +17,7 @@ Then /^template files should exist at "([^\"]*)"$/ do |dirname|
end end
Then /^empty directories should exist at "([^\"]*)"$/ do |dirname| Then /^empty directories should exist at "([^\"]*)"$/ do |dirname|
target = File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "spec", "fixtures", dirname) target = File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "fixtures", dirname)
%w(views/stylesheets public/stylesheets public/javascripts public/images).each do |d| %w(views/stylesheets public/stylesheets public/javascripts public/images).each do |d|
File.exists?("#{target}/#{d}").should be_true File.exists?("#{target}/#{d}").should be_true
@ -19,6 +25,6 @@ Then /^empty directories should exist at "([^\"]*)"$/ do |dirname|
end end
Then /^cleanup at "([^\"]*)"$/ do |dirname| Then /^cleanup at "([^\"]*)"$/ do |dirname|
target = File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "spec", "fixtures", dirname) target = File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "fixtures", dirname)
FileUtils.rm_rf(target) FileUtils.rm_rf(target)
end end

View file

@ -4,10 +4,8 @@ Given /^"([^\"]*)" feature is "([^\"]*)"$/ do |feature, state|
@browser = Rack::Test::Session.new(Rack::MockSession.new(Middleman::Server.new)) @browser = Rack::Test::Session.new(Rack::MockSession.new(Middleman::Server.new))
end end
Given /^generated directory at "([^\"]*)"$/ do |dirname| Given /^the Server is running$/ do
target = File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "spec", "fixtures", dirname) @browser = Rack::Test::Session.new(Rack::MockSession.new(Middleman::Server.new))
init_cmd = File.expand_path(File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "bin", "mm-init"))
`cd #{File.dirname(target)} && #{init_cmd} #{File.basename(target)}`
end end
When /^I go to "([^\"]*)"$/ do |url| When /^I go to "([^\"]*)"$/ do |url|
@ -17,6 +15,9 @@ end
Then /^I should see "([^\"]*)"$/ do |expected| Then /^I should see "([^\"]*)"$/ do |expected|
@browser.last_response.body.should include(expected) @browser.last_response.body.should include(expected)
end end
Then /^I should see '([^\']*)'$/ do |expected|
@browser.last_response.body.should include(expected)
end
Then /^I should not see "([^\"]*)"$/ do |expected| Then /^I should not see "([^\"]*)"$/ do |expected|
@browser.last_response.body.should_not include(expected) @browser.last_response.body.should_not include(expected)

View file

@ -1,11 +1,11 @@
Given /^page "([^\"]*)" has layout "([^\"]*)"$/ do |url, layout| Given /^page "([^\"]*)" has layout "([^\"]*)"$/ do |url, layout|
Middleman::Server.set :root, File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "spec", "fixtures", "sample") Middleman::Server.set :root, File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "fixtures", "test-app")
Middleman::Server.page(url, :layout => layout.to_sym) Middleman::Server.page(url, :layout => layout.to_sym)
@browser = Rack::Test::Session.new(Rack::MockSession.new(Middleman::Server.new)) @browser = Rack::Test::Session.new(Rack::MockSession.new(Middleman::Server.new))
end end
Given /^"([^\"]*)" with_layout block has layout "([^\"]*)"$/ do |url, layout| Given /^"([^\"]*)" with_layout block has layout "([^\"]*)"$/ do |url, layout|
Middleman::Server.set :root, File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "spec", "fixtures", "sample") Middleman::Server.set :root, File.join(File.dirname(File.dirname(File.dirname(__FILE__))), "fixtures", "test-app")
Middleman::Server.with_layout(:layout => layout.to_sym) do Middleman::Server.with_layout(:layout => layout.to_sym) do
page(url) page(url)
end end

View file

Before

Width:  |  Height:  |  Size: 43 B

After

Width:  |  Height:  |  Size: 43 B

View file

@ -0,0 +1,2 @@
= image_tag "test.png"
= image_tag "test2.png", :alt => "alt"

View file

@ -0,0 +1,4 @@
= javascript_include_tag "test1"
= javascript_include_tag :test2
= javascript_include_tag "test3.js"
= javascript_include_tag "http://test.com/javascripts/test4.js"

View file

@ -0,0 +1,3 @@
= link_to "No Href"
= link_to "Has Href", "test.com"
= link_to "Has param", "test2.com", :class => "test"

View file

@ -0,0 +1,4 @@
= stylesheet_link_tag "test1"
= stylesheet_link_tag :test2
= stylesheet_link_tag "test3.css"
= stylesheet_link_tag "http://test.com/stylesheets/test4.css"

View file

@ -45,22 +45,32 @@ class Middleman::Features::DefaultHelpers
def image_tag(path, params={}) def image_tag(path, params={})
params[:alt] ||= "" params[:alt] ||= ""
prefix = settings.http_images_path rescue settings.images_dir prefix = settings.http_images_path rescue settings.images_dir
params = params.merge(:src => asset_url(path, prefix))
params = params.map { |k,v| %Q{#{k}="#{v}"}}.join(' ') params = params.map { |k,v| %Q{#{k}="#{v}"}}.join(' ')
"<img #{params} />" params << " " if params.length > 0
"<img src=\"#{asset_url(path, prefix)}\" #{params}/>"
end end
def javascript_include_tag(path, params={}) def javascript_include_tag(path, params={})
params = params.merge(:src => asset_url(path, settings.js_dir), :type => "text/javascript") path = path.to_s
path << ".js" unless path =~ /\.js$/
params.delete(:type)
params.delete(:src)
params = params.map { |k,v| %Q{#{k}="#{v}"}}.join(' ') params = params.map { |k,v| %Q{#{k}="#{v}"}}.join(' ')
"<script #{params}></script>" params = " " + params if params.length > 0
"<script type=\"text/javascript\" src=\"#{asset_url(path, settings.js_dir)}\"#{params}></script>"
end end
def stylesheet_link_tag(path, params={}) def stylesheet_link_tag(path, params={})
params[:rel] ||= "stylesheet" path = path.to_s
params = params.merge(:href => asset_url(path, settings.css_dir), :type => "text/css") path << ".css" unless path =~ /\.css$/
params.delete(:type)
params.delete(:rel)
params.delete(:href)
params = params.map { |k,v| %Q{#{k}="#{v}"}}.join(' ') params = params.map { |k,v| %Q{#{k}="#{v}"}}.join(' ')
"<link #{params} />" params << " " if params.length > 0
"<link type=\"text/css\" rel=\"stylesheet\" href=\"#{asset_url(path, settings.css_dir)}\" #{params}/>"
end end
end end
end end

View file

@ -1,67 +0,0 @@
require 'fileutils'
describe "Builder" do
def project_file(*parts)
File.expand_path(File.join(File.dirname(__FILE__), "..", *parts))
end
before :all do
@root_dir = project_file("spec", "fixtures", "sample")
end
before :each do
build_cmd = project_file("bin", "mm-build")
`cd #{@root_dir} && MM_DIR="#{@root_dir}" #{build_cmd}`
end
after :each do
FileUtils.rm_rf(File.join(@root_dir, "build"))
end
it "should use layout" do
File.exists?("#{@root_dir}/build/index.html").should be_true
File.read("#{@root_dir}/build/index.html").should include("Comment in layout")
end
it "should build coffee files" do
File.exists?("#{@root_dir}/build/javascripts/coffee_test.js").should be_true
File.read("#{@root_dir}/build/javascripts/coffee_test.js").should include("Array.prototype.slice")
end
it "should build haml files" do
File.exists?("#{@root_dir}/build/index.html").should be_true
File.read("#{@root_dir}/build/index.html").should include("<h1>Welcome</h1>")
end
it "should build static files" do
File.exists?("#{@root_dir}/build/static.html").should be_true
File.read("#{@root_dir}/build/static.html").should include("Static, no code!")
end
it "should build subdirectory files" do
File.exists?("#{@root_dir}/build/services/index.html").should be_true
end
it "should build sass files" do
File.exists?("#{@root_dir}/build/stylesheets/site.css").should be_true
File.read("#{@root_dir}/build/stylesheets/site.css").gsub(/\s/, "").should include("html,body,div,span,applet,object,iframe")
end
it "should build less files" do
File.exists?("#{@root_dir}/build/stylesheets/test_less.css").should be_true
File.read("#{@root_dir}/build/stylesheets/test_less.css").should include("666")
end
it "should build scss files" do
File.exists?("#{@root_dir}/build/stylesheets/site_scss.css").should be_true
File.read("#{@root_dir}/build/stylesheets/site_scss.css").gsub(/\s/, "").should include("html,body,div,span,applet,object,iframe")
end
it "should build static css files" do
File.exists?("#{@root_dir}/build/stylesheets/static.css").should be_true
end
it "should not build partial files" do
File.exists?("#{@root_dir}/build/_partial.html").should be_false
end
end

View file

@ -1,43 +0,0 @@
require File.join(File.dirname(__FILE__), "spec_helper")
base = ::Middleman::Server
describe "page_classes helper" do
it "should generate root paths correctly" do
browser = Rack::Test::Session.new(Rack::MockSession.new(base.new))
browser.get("/page-class.html")
browser.last_response.body.chomp.should == "page-class"
end
it "should generate 1-deep paths correctly" do
browser = Rack::Test::Session.new(Rack::MockSession.new(base.new))
browser.get("/sub1/page-class.html")
browser.last_response.body.chomp.should == "sub1 sub1_page-class"
end
it "should generate 2-deep paths correctly" do
browser = Rack::Test::Session.new(Rack::MockSession.new(base.new))
browser.get("/sub1/sub2/page-class.html")
browser.last_response.body.chomp.should == "sub1 sub1_sub2 sub1_sub2_page-class"
end
end
describe "auto_stylesheet_link_tag helper" do
it "should generate root paths correctly" do
browser = Rack::Test::Session.new(Rack::MockSession.new(base.new))
browser.get("/auto-css.html")
browser.last_response.body.chomp.should include("stylesheets/auto-css.css")
end
it "should generate 1-deep paths correctly" do
browser = Rack::Test::Session.new(Rack::MockSession.new(base.new))
browser.get("/sub1/auto-css.html")
browser.last_response.body.chomp.should include("stylesheets/sub1/auto-css.css")
end
it "should generate 2-deep paths correctly" do
browser = Rack::Test::Session.new(Rack::MockSession.new(base.new))
browser.get("/sub1/sub2/auto-css.html")
browser.last_response.body.chomp.should include("stylesheets/sub1/sub2/auto-css.css")
end
end

View file

@ -1,8 +0,0 @@
ENV["MM_DIR"] = File.join(File.dirname(__FILE__), "fixtures", "sample")
require File.join(File.dirname(File.dirname(__FILE__)), 'lib', 'middleman')
require 'spec'
require 'rack/test'
Spec::Runner.configure do |config|
end