Sha256: 36f8e43b4a39ca70bb7f39a0eedc81abf55afb44b79b4cd483ed063c7869f392
Contents?: true
Size: 1.96 KB
Versions: 2
Compression:
Stored size: 1.96 KB
Contents
require File.dirname(__FILE__) + '/spec_helper' require File.dirname(__FILE__) + '/../lib/g5k/sinatra/helpers' describe G5K::Sinatra::Helpers do class Request include G5K::Sinatra::Helpers def initialize(options = {}) @format = options[:format] end def params; {:format => @format}; end end it "should throw a 406 error if it does not provide the requested format" do req = Request.new(:format => 'json') req.should_receive(:throw).with(:halt, [406, "The accepted types are: xml, js"]) req.provides(:xml, :js) end it "should not throw a 406 error if it can provide the requested format" do req = Request.new(:format => 'json') req.should_not_receive(:throw) req.provides(:xml, :json) end it "should format the error with the given parser" do require 'json' options = {:code => 500, :message => "message", :title => "title"} req = Request.new req.should_receive(:content_type).with(:json, :charset => 'utf-8') req.should_receive(:throw).with(:halt, [404, options.to_json]) req.formatted_error(404, options.merge({:parser => JSON, :format => 'json'})) end it "should format the error even when no parser is given" do options = {:code => 500, :message => "message", :title => "title"} req = Request.new req.should_receive(:content_type).with(:txt, :charset => 'utf-8') req.should_receive(:throw).with(:halt, [404, "code=500;message=message;title=title"]) req.formatted_error(404, options) end it "should log the error if a logger is defined in the Sinatra options" do options = {:code => 500, :message => "message", :title => "title"} module Sinatra module Application end end logger = mock('logger') req = Request.new req.stub!(:content_type) req.stub!(:throw) Sinatra::Application.should_receive(:logger).and_return(logger) logger.should_receive(:error).with(options.inspect) req.formatted_error(404, options) end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
cryx-g5k-0.2.4 | spec/sinatra_helpers_spec.rb |
cryx-g5k-0.2.5 | spec/sinatra_helpers_spec.rb |