Class: Alice::Adapter::Test
- Inherits:
-
Middleware
- Object
- Middleware
- Alice::Adapter::Test
- Defined in:
- lib/alice/adapter/test.rb
Overview
test = Alice::Connection.new do
use Alice::Adapter::Test do |stub|
stub.get '/nigiri/sake.json' do
[200, {}, 'hi world']
end
end
end
resp = test.get ‘/nigiri/sake.json’ resp.body # => ‘hi world’
Defined Under Namespace
Class Method Summary collapse
Instance Method Summary collapse
- #call(env) ⇒ Object
- #configure {|stubs| ... } ⇒ Object
-
#initialize(app, &block) ⇒ Test
constructor
A new instance of Test.
- #stubs ⇒ Object
Methods inherited from Middleware
#create_form_params, #full_path_for, #process_body_for_request, setup_parallel_manager
Constructor Details
#initialize(app, &block) ⇒ Test
Returns a new instance of Test.
64 65 66 67 |
# File 'lib/alice/adapter/test.rb', line 64 def initialize app, &block super(app) configure(&block) if block end |
Class Method Details
.loaded? ⇒ Boolean
15 |
# File 'lib/alice/adapter/test.rb', line 15 def self.loaded?() false end |
Instance Method Details
#call(env) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/alice/adapter/test.rb', line 77 def call(env) if stub = stubs.match(env[:method], env[:url].path) status, headers, body = stub.block.call(env) env.update \ :status => status, :response_headers => headers, :body => body else env.update \ :status => 404, :response_headers => {}, :body => 'no stubbed requests' end @app.call(env) end |
#configure {|stubs| ... } ⇒ Object
69 70 71 |
# File 'lib/alice/adapter/test.rb', line 69 def configure yield stubs end |
#stubs ⇒ Object
73 74 75 |
# File 'lib/alice/adapter/test.rb', line 73 def stubs @stubs ||= Stubs.new end |