Sha256: d6cb6e6358efe0deb8e39fe9c253d247e50e456790bf87c6bdd290773a8b4f9e

Contents?: true

Size: 1.05 KB

Versions: 3

Compression:

Stored size: 1.05 KB

Contents

require 'deas'
require 'ostruct'

class FakeApp

  # 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
    @request = FakeRequest.new('GET','/something', {}, OpenStruct.new)
    @params   = @request.params
    @session  = @request.session
    @response = FakeResponse.new
    @settings = OpenStruct.new(:deas_template_scope => Deas::Template::Scope)
  end

  def halt(*args)
    throw :halt, 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

  def to(relative_path)
    File.join("http://test.local", relative_path)
  end

  def redirect(*args)
    halt 302, { 'Location' => args[0] }
  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

3 entries across 3 versions & 1 rubygems

Version Path
deas-0.9.0 test/support/fake_app.rb
deas-0.8.0 test/support/fake_app.rb
deas-0.7.0 test/support/fake_app.rb