Permalink
Browse files

Made Sinatra specs work

  • Loading branch information...
1 parent bb36507 commit d98c9f6066645647ec26805c753267ee0f25b574 Avdi Grimm committed May 26, 2008
View
@@ -1,32 +0,0 @@
-require 'pathname'
-ROOT = Pathname.new(__FILE__).dirname
-Pathname.glob(ROOT + 'vendor' + '*' + 'lib').each do |path|
- $LOAD_PATH.unshift(path.to_s)
-end
-
-require 'rubygems'
-require 'sinatra'
-require 'builder'
-require 'markaby'
-
-helpers do
- def name
- "Curator"
- end
-end
-
-template :layout do
-<<-END
- div do
- div "Above"
- self << yield
- div "Below"
- end
-END
-end
-
-get '/' do
- mab do
- div.foo! "Welcome to #{name}"
- end
-end
View
@@ -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
View
@@ -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
View
@@ -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')
@@ -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
View
@@ -6,5 +6,5 @@
require 'spec'
end
-$:.unshift(File.dirname(__FILE__) + '/../lib')
+require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'environment'))
require 'curator'
@@ -36,13 +36,13 @@ def self.set(option, value)
@@default[option] = value
end
- def self.ignored_helpers
- @@ignored_helpers ||= []
- end
-
- def self.ignore_helpers(*helpers)
- ignored_helpers.concat helpers
- end
+ def self.ignored_helpers
+ @@ignored_helpers ||= []
+ end
+
+ def self.ignore_helpers(*helpers)
+ ignored_helpers.concat helpers
+ end
attr_accessor :output_helpers, :tagset
@@ -70,7 +70,7 @@ def initialize(assigns = {}, helpers = nil, &block)
@@default.each do |k, v|
instance_variable_set("@#{k}", @assigns.delete(k) || v)
end
-
+
@assigns.each do |k, v|
instance_variable_set("@#{k}", v)
end
@@ -119,11 +119,11 @@ def tag!(tag, *args, &block)
raise InvalidXhtmlError, "no element `#{tag}' for #{tagset.doctype}"
elsif args.last.respond_to?(:to_hash)
attrs = args.last.to_hash
-
+
if @tagset.forms.include?(tag) and attrs[:id]
attrs[:name] ||= attrs[:id]
end
-
+
attrs.each do |k, v|
atname = k.to_s.downcase.intern
unless k =~ /:/ or @tagset.tagset[tag].include? atname
@@ -179,7 +179,7 @@ def method_missing(sym, *args, &block)
instance_variable_get(ivar)
elsif !@helpers.nil? && @helpers.instance_variables.include?(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)
elsif @tagset.nil?
tag!(sym, *args, &block)
@@ -213,7 +213,7 @@ def #{k}(*args, &block)
end
remove_method :head
-
+
# Builds a head tag. Adds a <tt>meta</tt> tag inside with Content-Type
# set to <tt>text/html; charset=utf-8</tt>.
def head(*args, &block)
@@ -285,5 +285,5 @@ def self.method_missing(*args, &block)
class XmlMarkup < ::Builder::XmlMarkup
attr_accessor :target, :level
end
-
+
end
@@ -768,7 +768,6 @@ def render_mab(content, options ={}, &block)
require 'markaby'
output = ::Markaby::Builder.new(options.fetch(:locals){{}},
options.fetch(:scope){self})
- output.tagset = ::Markaby::XHTMLStrict
case content
when String then output.instance_eval(content)
when Proc then output.capture(&content)
@@ -1,10 +1,10 @@
require File.dirname(__FILE__) + '/unit'
-require 'test/spec'
+require 'spec/interop/test'
class Test::Unit::TestCase
-
+
def should
@response.should
end
-
+
end

0 comments on commit d98c9f6

Please sign in to comment.