Class: Steam::Connection::Mock
- Inherits:
-
Object
- Object
- Steam::Connection::Mock
- Defined in:
- lib/steam/connection/mock.rb
Class Method Summary collapse
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize ⇒ Mock
constructor
A new instance of Mock.
- #mock(*args) ⇒ Object
- #response(method, url) ⇒ Object
Constructor Details
#initialize ⇒ Mock
Returns a new instance of Mock.
17 18 19 |
# File 'lib/steam/connection/mock.rb', line 17 def initialize @responses = {} end |
Class Method Details
.default_content_types ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/steam/connection/mock.rb', line 7 def default_content_types { :html => 'text/html', :xml => 'application/xml', :javascript => 'application/javascript', :stylesheet => 'text/css' } end |
Instance Method Details
#call(env) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/steam/connection/mock.rb', line 21 def call(env) request = Rack::Request.new(env) response = response(request.request_method, request.url) response = response.call if response.is_a?(Proc) response.to_a end |
#mock(*args) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/steam/connection/mock.rb', line 32 def mock(*args) headers = args.last.is_a?(Hash) ? args.pop : {} response, url, method = *args.reverse responses(method || :get)[url] = case response when Array Rack::Response.new(*response) when String Rack::Response.new(response, 200, headers) else response end end |
#response(method, url) ⇒ Object
28 29 30 |
# File 'lib/steam/connection/mock.rb', line 28 def response(method, url) responses(method)[CGI::unescape(url)] || Rack::Response.new('', 404) end |