Class: MockServer::Playback
- Inherits:
-
Object
- Object
- MockServer::Playback
- Includes:
- Utils
- Defined in:
- lib/mock_server/playback.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ Playback
constructor
A new instance of Playback.
Constructor Details
#initialize(app, options = {}) ⇒ Playback
Returns a new instance of Playback.
7 8 9 10 11 |
# File 'lib/mock_server/playback.rb', line 7 def initialize(app, = {}) = @app = app ||= end |
Instance Method Details
#call(env) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/mock_server/playback.rb', line 13 def call(env) return @app.call(env) unless and [:routes] and lazy_match [:routes], env["PATH_INFO"] .merge!() @request = Rack::Request.new(env) @data = load_data record = match_request if record [:success_stack] ||= [] [:success_stack] << @request.path response = record[:response] [response[:status], response[:headers], [response[:body]]] else [:errors_stack] ||= [] error = { @request.path => "Couldn't match #{@request.request_method} #{@request.path}" } [:errors_stack] << error [404, {}, ['RECORD NOT FOUND!']] end end |