Module: MockHTTP
- Defined in:
- lib/ramaze/spec/helper/mock_http.rb
Constant Summary collapse
- DEFAULTS =
{ 'REMOTE_ADDR' => '127.0.0.1' }
- MOCK_URI =
URI::HTTP.build( :host => 'localhost', :port => 80 )
- FISHING =
{ :input => :input, :referrer => 'HTTP_REFERER', :referer => 'HTTP_REFERER', :cookie => 'HTTP_COOKIE', :if_none_match=> 'HTTP_IF_NONE_MATCH', :if_modified_since=> 'HTTP_IF_MODIFIED_SINCE', }
- MOCK_REQUEST =
::Rack::MockRequest.new(Ramaze::Adapter::Fake)
Instance Method Summary collapse
- #create_url(path, query) ⇒ Object
- #delete(*args) ⇒ Object
- #get(*args) ⇒ Object
- #make_query(query) ⇒ Object
- #mock_request(meth, path, query = {}) ⇒ Object
- #post(*args) ⇒ Object
- #process_request(path, query) ⇒ Object
- #put(*args) ⇒ Object
- #raw_mock_request(meth, uri, options = {}) ⇒ Object
Instance Method Details
#create_url(path, query) ⇒ Object
51 52 53 54 55 56 |
# File 'lib/ramaze/spec/helper/mock_http.rb', line 51 def create_url(path, query) uri = MOCK_URI.dup uri.path = path uri.query = make_query(query) uri.to_s end |
#delete(*args) ⇒ Object
32 |
# File 'lib/ramaze/spec/helper/mock_http.rb', line 32 def delete(*args) mock_request(:delete, *args) end |
#get(*args) ⇒ Object
29 |
# File 'lib/ramaze/spec/helper/mock_http.rb', line 29 def get(*args) mock_request(:get, *args) end |
#make_query(query) ⇒ Object
58 59 60 61 62 63 |
# File 'lib/ramaze/spec/helper/mock_http.rb', line 58 def make_query query return query unless query and not query.is_a?(String) query.map{|key, value| "#{Rack::Utils.escape(key)}=#{Rack::Utils.escape(value)}" }.join('&') end |
#mock_request(meth, path, query = {}) ⇒ Object
34 35 36 37 |
# File 'lib/ramaze/spec/helper/mock_http.rb', line 34 def mock_request(meth, path, query = {}) uri, = process_request(path, query) MOCK_REQUEST.send(meth, uri, DEFAULTS.merge()) end |
#post(*args) ⇒ Object
31 |
# File 'lib/ramaze/spec/helper/mock_http.rb', line 31 def post(*args) mock_request(:post, *args) end |
#process_request(path, query) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/ramaze/spec/helper/mock_http.rb', line 43 def process_request(path, query) = {} FISHING.each do |key, value| [value] = query.delete(key) if query.key?(key) end if query.is_a?(Hash) [create_url(path, query), ] end |
#put(*args) ⇒ Object
30 |
# File 'lib/ramaze/spec/helper/mock_http.rb', line 30 def put(*args) mock_request(:put, *args) end |
#raw_mock_request(meth, uri, options = {}) ⇒ Object
39 40 41 |
# File 'lib/ramaze/spec/helper/mock_http.rb', line 39 def raw_mock_request(meth, uri, = {}) MOCK_REQUEST.send(meth, uri, DEFAULTS.merge()) end |