Module: Sinatra::TestHelpers

Extended by:
Forwardable
Includes:
Rack::Test::Methods
Defined in:
lib/sinatra/test_helpers.rb

Defined Under Namespace

Classes: Session

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#settingsObject

Returns the value of attribute settings.



24
25
26
# File 'lib/sinatra/test_helpers.rb', line 24

def settings
  @settings
end

Instance Method Details

#appObject



47
48
49
50
# File 'lib/sinatra/test_helpers.rb', line 47

def app
  @app ||= Class.new Sinatra::Base
  Rack::Lint.new @app
end

#app=(base) ⇒ Object Also known as: set_app



41
42
43
# File 'lib/sinatra/test_helpers.rb', line 41

def app=(base)
  @app = base
end

#build_rack_test_session(name) ⇒ Object

:nodoc:



83
84
85
# File 'lib/sinatra/test_helpers.rb', line 83

def build_rack_test_session(name) # :nodoc:
  Session.new rack_mock_session(name)
end

#last_envObject



79
80
81
# File 'lib/sinatra/test_helpers.rb', line 79

def last_env
  last_request.env
end

#last_request?Boolean

Returns:

  • (Boolean)


66
67
68
69
70
71
# File 'lib/sinatra/test_helpers.rb', line 66

def last_request?
  last_request
  true
rescue Rack::Test::Error
  false
end

#mock_app(base = Sinatra::Base, &block) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/sinatra/test_helpers.rb', line 31

def mock_app(base = Sinatra::Base, &block)
  inner = nil
  @app  = Sinatra.new(base) do
    inner = self
    class_eval(&block)
  end
  @settings = inner
  app
end

#options(uri, params = {}, env = {}, &block) ⇒ Object



53
54
55
56
# File 'lib/sinatra/test_helpers.rb', line 53

def options(uri, params = {}, env = {}, &block)
  env = env_for(uri, env.merge(:method => "OPTIONS", :params => params))
  current_session.send(:process_request, uri, env, &block)
end

#patch(uri, params = {}, env = {}, &block) ⇒ Object



60
61
62
63
# File 'lib/sinatra/test_helpers.rb', line 60

def patch(uri, params = {}, env = {}, &block)
  env = env_for(uri, env.merge(:method => "PATCH", :params => params))
  current_session.send(:process_request, uri, env, &block)
end

#sessionObject

Raises:

  • (Rack::Test::Error)


73
74
75
76
77
# File 'lib/sinatra/test_helpers.rb', line 73

def session
  return {} unless last_request?
  raise Rack::Test::Error, "session not enabled for app" unless last_env["rack.session"] or app.session?
  last_request.session
end