From 27f7aa5ee85003837b87e741034ebd08c73a75d8 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Wed, 21 Mar 2012 12:21:00 -0400 Subject: [PATCH] changes and junk --- Gemfile | 2 +- Guardfile | 16 +++++ flowerbox.gemspec | 10 +++ lib/flowerbox/server.rb | 17 +++-- .../delivery/template_renderer_spec.rb | 59 ------------------ .../delivery/tilt/js_template_spec.rb | 62 ------------------- spec/flowerbox/server_spec.rb | 28 ++++++++- spec/flowerbox/sprockets_handler_spec.rb | 3 +- spec/flowerbox/unique_asset_list_spec.rb | 12 ++-- spec/spec_helper.rb | 6 +- 10 files changed, 79 insertions(+), 136 deletions(-) create mode 100644 Guardfile delete mode 100644 spec/flowerbox/delivery/template_renderer_spec.rb delete mode 100644 spec/flowerbox/delivery/tilt/js_template_spec.rb diff --git a/Gemfile b/Gemfile index 766ec5d..65f4904 100644 --- a/Gemfile +++ b/Gemfile @@ -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' diff --git a/Guardfile b/Guardfile new file mode 100644 index 0000000..155dfd9 --- /dev/null +++ b/Guardfile @@ -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 diff --git a/flowerbox.gemspec b/flowerbox.gemspec index 85fc657..75adbe7 100644 --- a/flowerbox.gemspec +++ b/flowerbox.gemspec @@ -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 + diff --git a/lib/flowerbox/server.rb b/lib/flowerbox/server.rb index 2e64e27..e746db6 100644 --- a/lib/flowerbox/server.rb +++ b/lib/flowerbox/server.rb @@ -8,27 +8,32 @@ module Flowerbox class Server attr_reader :options + class MissingRackApp < 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 } diff --git a/spec/flowerbox/delivery/template_renderer_spec.rb b/spec/flowerbox/delivery/template_renderer_spec.rb deleted file mode 100644 index 7c790d0..0000000 --- a/spec/flowerbox/delivery/template_renderer_spec.rb +++ /dev/null @@ -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 == [ - %{}, - %{} - ].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 diff --git a/spec/flowerbox/delivery/tilt/js_template_spec.rb b/spec/flowerbox/delivery/tilt/js_template_spec.rb deleted file mode 100644 index 41a680b..0000000 --- a/spec/flowerbox/delivery/tilt/js_template_spec.rb +++ /dev/null @@ -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 - diff --git a/spec/flowerbox/server_spec.rb b/spec/flowerbox/server_spec.rb index 5a73362..33431bd 100644 --- a/spec/flowerbox/server_spec.rb +++ b/spec/flowerbox/server_spec.rb @@ -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' } diff --git a/spec/flowerbox/sprockets_handler_spec.rb b/spec/flowerbox/sprockets_handler_spec.rb index 2635a7a..6cc5fdc 100644 --- a/spec/flowerbox/sprockets_handler_spec.rb +++ b/spec/flowerbox/sprockets_handler_spec.rb @@ -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') ] } diff --git a/spec/flowerbox/unique_asset_list_spec.rb b/spec/flowerbox/unique_asset_list_spec.rb index 1def2c1..a9a9ff8 100644 --- a/spec/flowerbox/unique_asset_list_spec.rb +++ b/spec/flowerbox/unique_asset_list_spec.rb @@ -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) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index fe4f8b5..51b7759 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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