Merge branch 'master' of github.com:johnbintz/flowerbox

This commit is contained in:
John Bintz 2012-03-21 17:36:25 -04:00
commit ed00ba476a
10 changed files with 78 additions and 136 deletions

View File

@ -3,5 +3,5 @@ source 'https://rubygems.org'
# Specify your gem's dependencies in flowerbox.gemspec
gemspec
gem 'flowerbox-delivery', :path => '../flowerbox-delivery'
gem 'guard-flowerbox', :path => '../guard-flowerbox'

16
Guardfile Normal file
View File

@ -0,0 +1,16 @@
# A sample Guardfile
# More info at https://github.com/guard/guard#readme
guard 'rspec', :version => 2 do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
end
if false
guard 'cucumber' do
watch(%r{^features/.+\.feature$})
watch(%r{^features/support/.+$}) { 'features' }
watch(%r{^features/step_definitions/.*$}) { 'features' }
end
end

View File

@ -17,11 +17,21 @@ Gem::Specification.new do |gem|
gem.add_development_dependency 'cucumber'
gem.add_development_dependency 'rspec'
gem.add_development_dependency 'simplecov'
gem.add_development_dependency 'mocha'
gem.add_development_dependency 'fakefs'
gem.add_development_dependency 'guard'
gem.add_development_dependency 'guard-flowerbox'
gem.add_development_dependency 'guard-rspec'
gem.add_development_dependency 'guard-cucumber'
gem.add_dependency 'jasmine-core'
gem.add_dependency 'thor'
gem.add_dependency 'selenium-webdriver'
gem.add_dependency 'sinatra'
gem.add_dependency 'rainbow'
gem.add_dependency 'sprockets'
gem.add_dependency 'sprockets-vendor_gems'
gem.add_dependency 'thin'
end

View File

@ -9,29 +9,33 @@ module Flowerbox
class Server
attr_reader :options
class MissingRackApp < StandardError ; end
class ServerDiedError < StandardError ; end
def initialize(options = {})
@options = { :logging => false }.merge(options || {})
end
def app
options[:app] || raise(MissingRackApp.new)
end
def start
@server_thread = Thread.new do
server_options = { :Port => port, :Host => interface }
app = options[:app]
Thin::Logging.silent = !options[:logging]
rack_app = app
if options[:logging]
real_app = app
app = ::Rack::Builder.new do
rack_app = ::Rack::Builder.new do
use ::Rack::CommonLogger, STDOUT
run real_app
run app
end
end
::Rack::Handler::Thin.run(app, server_options) do |server|
::Rack::Handler::Thin.run(rack_app, server_options) do |server|
Thread.current[:server] = server
trap('QUIT') { server.stop }

View File

@ -1,59 +0,0 @@
require 'spec_helper'
describe Flowerbox::Delivery::TemplateRenderer do
let(:template_renderer) { described_class.new(:template => template, :files => files) }
let(:template) { 'template' }
let(:files) { 'files' }
let(:rendered_template) { 'rendered template' }
let(:erb_template) { "#{rendered_template} <%= resource_tags %>" }
describe '#render' do
subject { template_renderer.render }
let(:rendered_files) { 'with files' }
let(:result) { "#{rendered_template} #{rendered_files}" }
before do
template_renderer.expects(:resource_tags).returns(rendered_files)
template_renderer.expects(:template).returns(erb_template)
end
it { should == result }
end
describe '#template' do
include FakeFS::SpecHelpers
before do
File.open(template, 'wb') { |fh| fh.print erb_template }
end
subject { template_renderer.template }
it { should == erb_template }
end
describe '#resource_tags' do
subject { template_renderer.resource_tags }
context 'success' do
let(:files) { [ js, css ] }
let(:js) { 'file.js' }
let(:css) { 'file.css' }
it { should == [
%{<script src="#{js}" type="text/javascript"></script>},
%{<link rel="stylesheet" href="#{css}" type="text/css" />}
].join }
end
context 'failure' do
let(:files) { [ 'what.ever' ] }
it 'should raise error' do
expect { subject }.to raise_error(Flowerbox::Delivery::TemplateRenderer::FileTypeError)
end
end
end
end

View File

@ -1,62 +0,0 @@
require 'spec_helper'
describe Flowerbox::Delivery::Tilt::JSTemplate do
let(:js_template) { described_class.new { '' } }
describe '#evaluate' do
subject { js_template.evaluate(Object.new, {}) }
before do
js_template.stubs(:file).returns(file)
end
context '.js' do
let(:file) { 'file.js' }
it { should == file }
end
context 'other extension' do
let(:file) { 'file.coffee' }
let(:temp_file) { 'temp file' }
before do
js_template.expects(:save).returns(temp_file)
end
it { should == temp_file }
end
end
describe '#save' do
include FakeFS::SpecHelpers
let(:temp_file) { 'dir/temp file' }
let(:data) { 'data' }
before do
js_template.stubs(:temp_file).returns(temp_file)
js_template.stubs(:data).returns(data)
end
it 'should save the file to disk and return the temp path' do
js_template.save.should == temp_file
File.read(temp_file).should == data
end
end
describe '#temp_file' do
subject { js_template.temp_file }
let(:filename) { "#{root_filename}.ext" }
let(:root_filename) { "dir/file.js" }
before do
js_template.stubs(:file).returns(filename)
end
it { should == File.join(Dir.pwd, '.tmp/sprockets', root_filename) }
end
end

View File

@ -2,7 +2,9 @@ require 'spec_helper'
require 'socket'
require 'thread'
describe Flowerbox::Delivery::Server do
require 'flowerbox/server'
describe Flowerbox::Server do
let(:server) { described_class.new(options) }
let(:options) { nil }
@ -17,6 +19,30 @@ describe Flowerbox::Delivery::Server do
its(:interface) { should == interface }
end
describe '#app' do
subject { server.app }
context 'no app defined' do
before do
server.stubs(:options).returns({})
end
it 'should raise an error' do
expect { server.app }.to raise_error(Flowerbox::Server::MissingRackApp)
end
end
context 'app defined' do
let(:app) { 'app' }
before do
server.stubs(:options).returns(:app => app)
end
it { should == app }
end
end
describe '#start' do
let(:port) { 12345 }
let(:interface) { '127.0.0.1' }

View File

@ -1,6 +1,7 @@
require 'spec_helper'
require 'flowerbox/sprockets_handler'
describe Flowerbox::Delivery::SprocketsHandler do
describe Flowerbox::SprocketsHandler do
let(:sprockets_handler) { described_class.new(options) }
let(:options) { { :asset_paths => asset_paths } }
let(:asset_paths) { [ File.expand_path('asset path') ] }

View File

@ -1,12 +1,14 @@
require 'spec_helper'
require 'flowerbox/unique_asset_list'
describe Flowerbox::Delivery::UniqueAssetList do
let(:unique_asset_list) { described_class.new }
describe Flowerbox::UniqueAssetList do
let(:unique_asset_list) { described_class.new(sprockets) }
let(:sprockets) { stub }
describe "#add" do
let(:first) { Pathname.new('one') }
let(:second) { Pathname.new('one') }
let(:third) { Pathname.new('two') }
let(:first) { stub(:pathname => Pathname.new('one')) }
let(:second) { stub(:pathname => Pathname.new('one')) }
let(:third) { stub(:pathname => Pathname.new('two')) }
it 'should not add assets already added' do
unique_asset_list.add(first)

View File

@ -1,7 +1,11 @@
require 'flowerbox-delivery'
require 'simplecov'
SimpleCov.start
require 'mocha'
require 'fakefs/spec_helpers'
require 'flowerbox'
RSpec.configure do |c|
c.mock_with :mocha
end