Skip to content

Commit

Permalink
Made Sinatra specs work
Browse files Browse the repository at this point in the history
  • Loading branch information
Avdi Grimm committed May 26, 2008
1 parent bb36507 commit d98c9f6
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 50 deletions.
32 changes: 0 additions & 32 deletions application.rb

This file was deleted.

17 changes: 17 additions & 0 deletions config/config.ru
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,17 @@
# -*- mode: ruby -*-
require File.join(File.dirname(__FILE__), '..', 'lib', 'environment')

require 'sinatra'

Sinatra::Application.default_options.merge!(:run => false,
:env => :production
)
require 'curator'
require 'application'
require 'curator/middleware/event_machine'
require 'curator/middleware/curator_finder'
require 'socket'

use Curator::Middleware::EventMachine
use Curator::Middleware::CuratorFinder, Socket.gethostname
run Sinatra.application
28 changes: 28 additions & 0 deletions lib/application.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,28 @@
require File.join(File.dirname(__FILE__), 'environment')
require 'rubygems'
require 'sinatra'

helpers do
def curator
request.env['curator.curator']
end
end

template :layout do
<<-END
xhtml_strict do
head do
title "Curator"
end
body do
self << yield
end
end
END
end

get '/' do
mab do
div.foo! "Welcome! #{curator.inspect}"
end
end
6 changes: 6 additions & 0 deletions lib/environment.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,6 @@
require 'pathname'
ROOT = Pathname.new(__FILE__).expand_path.dirname.parent
Pathname.glob(ROOT + 'vendor' + '*' + 'lib').each do |path|
$LOAD_PATH.unshift(path.to_s)
end
$LOAD_PATH.unshift(ROOT + 'lib')
16 changes: 16 additions & 0 deletions spec/application_spec.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,16 @@
require File.dirname(__FILE__) + '/spec_helper.rb'
require 'sinatra'
require 'sinatra/test/spec'
require 'application'

describe "curator application" do
describe "GET /" do
before :each do
get_it '/'
end
it "should support getting /" do
@response.should be_ok
body.should =~ /Welcome!/
end
end
end
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
require 'spec' require 'spec'
end end


$:.unshift(File.dirname(__FILE__) + '/../lib') require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'environment'))
require 'curator' require 'curator'
26 changes: 13 additions & 13 deletions vendor/markaby/lib/markaby/builder.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ def self.set(option, value)
@@default[option] = value @@default[option] = value
end end


def self.ignored_helpers def self.ignored_helpers
@@ignored_helpers ||= [] @@ignored_helpers ||= []
end end

def self.ignore_helpers(*helpers) def self.ignore_helpers(*helpers)
ignored_helpers.concat helpers ignored_helpers.concat helpers
end end


attr_accessor :output_helpers, :tagset attr_accessor :output_helpers, :tagset


Expand Down Expand Up @@ -70,7 +70,7 @@ def initialize(assigns = {}, helpers = nil, &block)
@@default.each do |k, v| @@default.each do |k, v|
instance_variable_set("@#{k}", @assigns.delete(k) || v) instance_variable_set("@#{k}", @assigns.delete(k) || v)
end end

@assigns.each do |k, v| @assigns.each do |k, v|
instance_variable_set("@#{k}", v) instance_variable_set("@#{k}", v)
end end
Expand Down Expand Up @@ -119,11 +119,11 @@ def tag!(tag, *args, &block)
raise InvalidXhtmlError, "no element `#{tag}' for #{tagset.doctype}" raise InvalidXhtmlError, "no element `#{tag}' for #{tagset.doctype}"
elsif args.last.respond_to?(:to_hash) elsif args.last.respond_to?(:to_hash)
attrs = args.last.to_hash attrs = args.last.to_hash

if @tagset.forms.include?(tag) and attrs[:id] if @tagset.forms.include?(tag) and attrs[:id]
attrs[:name] ||= attrs[:id] attrs[:name] ||= attrs[:id]
end end

attrs.each do |k, v| attrs.each do |k, v|
atname = k.to_s.downcase.intern atname = k.to_s.downcase.intern
unless k =~ /:/ or @tagset.tagset[tag].include? atname unless k =~ /:/ or @tagset.tagset[tag].include? atname
Expand Down Expand Up @@ -179,7 +179,7 @@ def method_missing(sym, *args, &block)
instance_variable_get(ivar) instance_variable_get(ivar)
elsif !@helpers.nil? && @helpers.instance_variables.include?(ivar) elsif !@helpers.nil? && @helpers.instance_variables.include?(ivar)
@helpers.instance_variable_get(ivar) @helpers.instance_variable_get(ivar)
elsif ::Builder::XmlMarkup.instance_methods.include?(sym.to_s) elsif ::Builder::XmlMarkup.instance_methods.include?(sym.to_s)
@builder.__send__(sym, *args, &block) @builder.__send__(sym, *args, &block)
elsif @tagset.nil? elsif @tagset.nil?
tag!(sym, *args, &block) tag!(sym, *args, &block)
Expand Down Expand Up @@ -213,7 +213,7 @@ def #{k}(*args, &block)
end end


remove_method :head remove_method :head

# Builds a head tag. Adds a <tt>meta</tt> tag inside with Content-Type # Builds a head tag. Adds a <tt>meta</tt> tag inside with Content-Type
# set to <tt>text/html; charset=utf-8</tt>. # set to <tt>text/html; charset=utf-8</tt>.
def head(*args, &block) def head(*args, &block)
Expand Down Expand Up @@ -285,5 +285,5 @@ def self.method_missing(*args, &block)
class XmlMarkup < ::Builder::XmlMarkup class XmlMarkup < ::Builder::XmlMarkup
attr_accessor :target, :level attr_accessor :target, :level
end end

end end
1 change: 0 additions & 1 deletion vendor/sinatra/lib/sinatra.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -768,7 +768,6 @@ def render_mab(content, options ={}, &block)
require 'markaby' require 'markaby'
output = ::Markaby::Builder.new(options.fetch(:locals){{}}, output = ::Markaby::Builder.new(options.fetch(:locals){{}},
options.fetch(:scope){self}) options.fetch(:scope){self})
output.tagset = ::Markaby::XHTMLStrict
case content case content
when String then output.instance_eval(content) when String then output.instance_eval(content)
when Proc then output.capture(&content) when Proc then output.capture(&content)
Expand Down
6 changes: 3 additions & 3 deletions vendor/sinatra/lib/sinatra/test/spec.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,10 +1,10 @@
require File.dirname(__FILE__) + '/unit' require File.dirname(__FILE__) + '/unit'
require 'test/spec' require 'spec/interop/test'


class Test::Unit::TestCase class Test::Unit::TestCase

def should def should
@response.should @response.should
end end

end end

0 comments on commit d98c9f6

Please sign in to comment.