Created
August 31, 2015 23:44
-
-
Save t33chong/b1f7bf41dd8da85c4b3e to your computer and use it in GitHub Desktop.
lita http.post debugging
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Lita | |
| module Handlers | |
| class Temp < Handler | |
| http.post '/foo/:bar', :foo | |
| def foo(request, response) | |
| bar = request.env['router.params'][:bar] | |
| baz = request.params['baz'] | |
| response.write("#{bar}\n#{baz}") | |
| end | |
| end | |
| Lita.register_handler(Temp) | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'json' | |
| require "spec_helper" | |
| describe Lita::Handlers::Temp, lita_handler: true do | |
| it { is_expected.to route_http(:post, '/foo/123').to(:foo) } | |
| describe '#foo' do | |
| it 'replies with the text contained in the baz field' do | |
| params = { :baz => 'luhrmann' }.to_json | |
| #params = { :baz => 'luhrmann' } | |
| http_response = http.post( | |
| '/foo/123', | |
| params, | |
| 'Content-Type' => 'application/json' | |
| ) | |
| #http_response = http.post('/foo/123?baz=luhrmann') | |
| expect(http_response.body).to eq("123\nluhrmann") | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment