Sha256: 0d9f88e4f46a5c7996091ed20669a5d1a940b2e117219656351e1abd7be34e8e

Contents?: true

Size: 1.33 KB

Versions: 5

Compression:

Stored size: 1.33 KB

Contents

require 'deas'
require 'ostruct'

class FakeSinatraCall

  # Mimic's the context that is accessible in a Sinatra' route. Should provide
  # any methods needed to replace using an actual Sinatra app.

  attr_accessor :request, :response, :params, :settings, :session, :logger

  def initialize(settings={})
    @request = FakeRequest.new('GET','/something', {}, OpenStruct.new)
    @params   = @request.params
    @session  = @request.session
    @response = FakeResponse.new
    @logger   = Deas::NullLogger.new
    @settings = OpenStruct.new(settings.merge({
      :deas_template_scope => Deas::Template::Scope,
      :deas_default_charset => 'utf-8'
    }))
  end

  def halt(*args)
    throw :halt, args
  end

  def redirect(*args)
    halt 302, { 'Location' => args[0] }
  end

  def content_type(*args); args; end
  def status(*args);       args; end
  def headers(*args);      args; end

  # return the template name for each nested calls

  RenderArgs = Struct.new(:template_name, :opts, :block_call_result)

  def erb(template_name, opts, &block)
    if block
      RenderArgs.new(template_name, opts, block.call)
    else
      RenderArgs.new(template_name, opts, nil)
    end
  end

end

class FakeRequest < Struct.new(:http_method, :path, :params, :session)
  alias :request_method :http_method
end
FakeResponse = Struct.new(:status, :headers, :body)

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
deas-0.23.4 test/support/fake_sinatra_call.rb
deas-0.23.3 test/support/fake_sinatra_call.rb
deas-0.23.2 test/support/fake_sinatra_call.rb
deas-0.23.1 test/support/fake_sinatra_call.rb
deas-0.23.0 test/support/fake_sinatra_call.rb