2012-02-15 8 views
1

임 몇 가지 보석 간단한 테스트를 작성하려고 : 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

+0

'c.login [ "status"]'는 콘솔에 무엇을 표시합니까? –

+0

'''NoMethodError : 정의되지 않은 메소드'[] 'for nil : NilClass'''' – tomekfranek

+0

어떤 종류의 객체가'c' ('c.class' 또는'pc')이고'# login' 메소드가 어떻게 정의되어 있습니까? ? – Koraktor

답변

0

당신이 RSpec에 태그, 나는 당신에게 RSpec에 대답을 줄거야 :

get '/login' 
last_response.status.should == 200 
+0

이것은 단지 보석 일 뿐이므로'''''''를 사용하지 않을 것 같아요. 그래서'<'RSpec :: Core :: ExampleGroup에 대해'''''정의되지 않은 메소드'get '을 받았습니다. :: Nested_1 : 0xa95a6dc> ''' – tomekfranek

관련 문제