Commits

Michael Granger committed 53d5540

Finish specs, prep for release.

  • Participants
  • Parent commits abcce61

Comments (0)

Files changed (7)

 # .gems generated gem export file. Note that any env variable settings will be missing. Append these after using a ';' field separator
 inversion -v0.9.0
-strelka -v0.0.1
+#strelka -v0.0.1
-## 0.0.1 [2012-04-23] Michael Granger <ged@FaerieMUD.org>
+== v0.0.1 [2012-05-03] Michael Granger <ged@FaerieMUD.org>
 
 Initial release.
 
 
 	self.developer 'Michael Granger', 'ged@FaerieMUD.org'
 
-	self.dependency 'strelka', '~> 0.1'
+	self.dependency 'strelka', '~> 0.0.1.pre'
 	self.dependency 'inversion', '~> 0.9'
 	self.dependency 'hoe-deveiate', '~> 0.1', :developer
 

data/strelka-fancyerrors/templates/client-error.tmpl

-<!-- FIX (set up the main content template) -->
+<!-- Client Error Template -->
 
-<p>Your request looked this:</p>
+<!-- :FIXME: (set up the main content template) -->
+<p>Your request looked like this:</p>
 
 <pre><code>
 <?pp request ?>

data/strelka-fancyerrors/templates/server-error.tmpl

+<!-- Server Error Template -->
 <?import request ?>
 
 <header>

lib/strelka/app/fancyerrors.rb

 # vim: set nosta noet ts=4 sw=4:
 # encoding: utf-8
 
+require 'inversion'
+
 require 'strelka' unless defined?( Strelka )
 require 'strelka/app' unless defined?( Strelka::App )
 
 		self.log.info "[:fancyerrors] Handling %d status response." % [ status_info[:status] ]
 		content = self.template( key )
 		content.status_info = status_info
+		self.log.debug "  error content template loaded from %s" % [ content.source_file || 'memory' ]
 
 		# If there's a layout template, just return the template as-is so
 		# templating will wrap it correctly
 		return content if self.layout
-		self.log.debug "Using the fancyerrors layout template."
+		self.log.debug "  using the fancyerrors layout template."
 
 		# Otherwise, wrap it in a simple layout of our own
 		layout = self.template( :fancy_error_layout )
 		layout.body = content
 		layout.status_info = status_info
 
+		self.log.debug "  error layout template loaded from %s" % [ layout.source_file || 'memory' ]
+
 		# :templating method
 		self.set_common_attributes( layout, response.request )
+
+		return layout
 	end
 
 end # module Strelka::App::Errors

spec/strelka/app/fancyerrors_spec.rb

 }
 
 require 'rspec'
-require 'strelka/_fancy_errors'
+require 'mongrel2/testing'
+require 'strelka'
+require 'strelka/app'
+require 'strelka/logging'
+require 'strelka/app/fancyerrors'
+require 'strelka/behavior/plugin'
 
-describe Strelka-FancyErrors do
 
-	it "is well-tested" do
-		fail "it isn't"
+class ArrayLogger
+	### Create a new ArrayLogger that will append content to +array+.
+	def initialize( array )
+		@array = array
+	end
+
+	### Write the specified +message+ to the array.
+	def write( message )
+		@array << message
+	end
+
+	### No-op -- this is here just so Logger doesn't complain
+	def close; end
+
+end # class ArrayLogger
+
+
+class FancyErrorTestingApp < Strelka::App
+	include Strelka::Constants
+
+	plugins :routing, :fancyerrors
+
+
+	# Set defaults for all arguments to avoid having to provide them every time
+	def initialize( appid='fancyerrors-test', sspec=TEST_SEND_SPEC, rspec=TEST_RECV_SPEC )
+		super
+	end
+
+	get 'server' do |req|
+		finish_with HTTP::SERVER_ERROR, "This response intentionally left blank."
+	end
+
+	get 'client' do |req|
+		finish_with HTTP::BAD_REQUEST, "You call that a request?!"
+	end
+end
+
+
+describe Strelka::App::FancyErrors do
+
+	TEST_SEND_SPEC = 'tcp://127.0.0.1:9997'
+	TEST_RECV_SPEC = 'tcp://127.0.0.1:9996'
+
+	before( :all ) do
+		Strelka.log.level = Logger::FATAL
+
+		# Only do this when executing from a spec in TextMate
+		if ENV['HTML_LOGGING'] || (ENV['TM_FILENAME'] && ENV['TM_FILENAME'] =~ /_spec\.rb/)
+			Thread.current['logger-output'] = []
+			logdevice = ArrayLogger.new( Thread.current['logger-output'] )
+			Strelka.logger = Logger.new( logdevice )
+			# Strelka.logger.level = level
+			Strelka.logger.formatter = Strelka::Logging::HtmlFormatter.new( Strelka.logger )
+			Mongrel2.logger = Strelka.logger
+		end
+
+		@request_factory = Mongrel2::RequestFactory.new( route: '' )
+	end
+
+	before( :each ) do
+		@app = FancyErrorTestingApp.new
+	end
+
+
+	it_should_behave_like( "A Strelka::App Plugin" )
+
+
+	it "renders server errors using the server error template" do
+		req = @request_factory.get( '/server' )
+		res = @app.handle( req )
+
+		res.body.should =~ /server error template/i
+	end
+
+	it "renders client errors using the client error template" do
+		req = @request_factory.get( '/client' )
+		res = @app.handle( req )
+
+		res.body.should =~ /client error template/i
+	end
+
+	it "renders errors using the existing layout template if one is set" do
+		@app.layout = Inversion::Template.new( '<!-- common layout --><?attr body ?>' )
+
+		req = @request_factory.get( '/client' )
+		res = @app.handle( req )
+
+		res.body.should =~ /common layout/i
 	end
 
 end