如何从此响应中获取状态?
我正在尝试对某些 gem 编写简单的测试: https://github.com/regedarek/soup-client
当我在控制台中运行时,我收到此响应:
ruby-1.9.2-p290 :022 > c.login
I, [2012-02-15T23:12:09.681772 #12908] INFO -- : post https://www.soup.io/login
D, [2012-02-15T23:12:09.681854 #12908] DEBUG -- request: Content-Type: "application/x-www-form-urlencoded"
I, [2012-02-15T23:12:10.157908 #12908] INFO -- Status: 302
D, [2012-02-15T23:12:10.158054 #12908] DEBUG -- response: server: "nginx/0.7.67"
date: "Wed, 15 Feb 2012 22:12:11 GMT"
content-type: "text/html; charset=utf-8"
connection: "close"
...
content-length: "94"
status: "302"
...
location: "http://soup-client.soup.io/?sessid=995f610405f8afe029b9038da6c22132"
content-length: "0"
status: "302"
...
set-cookie: "soup_session_id=995f610405f8afe029b9038da6c22132; path=/; expires=Sun, 15 Feb 2032 22:12:13 GMT; HttpOnly"
status: "200"
content-length: "16024"
我想对此进行测试,但如何从该响应中获取状态?
我已经尝试了 c.login["status"].should == 200
但它不起作用:
ruby-1.9.2-p290 :025 > c.login["status"]
...
status: "200"
vary: "Accept-Encoding"
content-length: "15700"
NoMethodError: undefined method `[]' for nil:NilClass
from (irb):25
from /home/rege/.rvm/rubies/ruby-1.9.2-p290/bin/irb:16:in `<main>'
这是 c.login.inspect
的输出 -> https://gist.github.com/1842529
Im trying to write simple test to some gem: https://github.com/regedarek/soup-client
I have this response when I run in the console:
ruby-1.9.2-p290 :022 > c.login
I, [2012-02-15T23:12:09.681772 #12908] INFO -- : post https://www.soup.io/login
D, [2012-02-15T23:12:09.681854 #12908] DEBUG -- request: Content-Type: "application/x-www-form-urlencoded"
I, [2012-02-15T23:12:10.157908 #12908] INFO -- Status: 302
D, [2012-02-15T23:12:10.158054 #12908] DEBUG -- response: server: "nginx/0.7.67"
date: "Wed, 15 Feb 2012 22:12:11 GMT"
content-type: "text/html; charset=utf-8"
connection: "close"
...
content-length: "94"
status: "302"
...
location: "http://soup-client.soup.io/?sessid=995f610405f8afe029b9038da6c22132"
content-length: "0"
status: "302"
...
set-cookie: "soup_session_id=995f610405f8afe029b9038da6c22132; path=/; expires=Sun, 15 Feb 2032 22:12:13 GMT; HttpOnly"
status: "200"
content-length: "16024"
I would like to test this but how do I get the status from this response?
I already tried c.login["status"].should == 200
but it's not working:
ruby-1.9.2-p290 :025 > c.login["status"]
...
status: "200"
vary: "Accept-Encoding"
content-length: "15700"
NoMethodError: undefined method `[]' for nil:NilClass
from (irb):25
from /home/rege/.rvm/rubies/ruby-1.9.2-p290/bin/irb:16:in `<main>'
This is output of c.login.inspect
-> https://gist.github.com/1842529
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您标记 rspec 时,我将为您提供 rspec 答案:
As you tagged rspec, I'm going to give you the rspec answer: