Class: Syntropy::TestHarness

Inherits:
Object
  • Object
show all
Defined in:
lib/syntropy/test.rb

Overview

TestHarness provides glue code for performing HTTP requests against a Syntropy app.

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ void

Initializes the test harness with the given app.

Parameters:



142
143
144
145
# File 'lib/syntropy/test.rb', line 142

def initialize(app)
  @app = app
  @app.raise_internal_server_error = true if @app.respond_to?(:raise_internal_server_error=)
end

Instance Method Details

#no_raise_internal_server_errorObject

Temporarily disables raising an exception in case of an internal server error while running the given block.



160
161
162
163
164
165
166
167
168
169
# File 'lib/syntropy/test.rb', line 160

def no_raise_internal_server_error
  return yield if !@app.respond_to?(:raise_internal_server_error=)

  begin
    @app.raise_internal_server_error = false
    yield
  ensure
    @app.raise_internal_server_error = true
  end
end

#request(headers, body = nil) ⇒ Syntropy::Request

Perfrms a request against the associated app.

Parameters:

  • headers (Hash)

    request headers

  • body (String, nil) (defaults to: nil)

    request body

Returns:



152
153
154
155
156
# File 'lib/syntropy/test.rb', line 152

def request(headers, body = nil)
  req = mock_req(headers, body)
  @app.call(req)
  req
end