Class: Alice::Adapter::Test
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
Classes: Stub, Stubs
Class Method Summary
collapse
Instance Method Summary
collapse
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, , body = stub.block.call(env)
env.update \
:status => status,
:response_headers => ,
:body => body
else
env.update \
:status => 404,
:response_headers => {},
:body => 'no stubbed requests'
end
@app.call(env)
end
|
69
70
71
|
# File 'lib/alice/adapter/test.rb', line 69
def configure
yield stubs
end
|
73
74
75
|
# File 'lib/alice/adapter/test.rb', line 73
def stubs
@stubs ||= Stubs.new
end
|