Sha256: e76dc0d3ad1aad394d43cafc95fb199ccd2eecb344967b7b9afec36a42b60be5

Contents?: true

Size: 1.17 KB

Versions: 2

Compression:

Stored size: 1.17 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

  def initialize(settings={})
    @request = FakeRequest.new('GET','/something', {}, OpenStruct.new)
    @params   = @request.params
    @session  = @request.session
    @response = FakeResponse.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
  def erb(name, opts, &block)
    if block
      [ name, opts, block.call ].flatten
    else
      [ name, opts ]
    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

2 entries across 2 versions & 1 rubygems

Version Path
deas-0.14.1 test/support/fake_sinatra_call.rb
deas-0.14.0 test/support/fake_sinatra_call.rb