Sha256: 73f6a614f370823e9f3bb80a16aa63d751f87548e94fb76fed57f0d4abd13c90
Contents?: true
Size: 1.47 KB
Versions: 1
Compression:
Stored size: 1.47 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(:error).with(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(:error).with(404, "code=500;message=message;title=title") req.formatted_error(404, options) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
cryx-g5k-0.2.3 | spec/sinatra_helpers_spec.rb |