Non empty string complained to be 'nil' in equality check

Discussion in 'Ruby' started by Kannan Jay, Apr 12, 2010.

  1. Kannan Jay

    Kannan Jay Guest

    I have the below code
    response = Net::HTTP.start(url.host, url.port) do
    |http|
    http.request(request)
    end
    exp_code = 450
    if(response.code.to_i != exp_code)
    raise StandardError, "Expected #{exp_code} Received
    #{response.code.to_i}"
    end
    exp_msg = 'Blocked By Parental Controls'
    puts 'Received status msg: #{response.message}'
    if(response.message != exp_msg)
    raise StandardError, "Expected #{exp_msg} Received
    #{response.message}"
    end

    The received response is
    HTTP/1.1 450 Blocked By Parental Controls^M
    Date: Mon, 12 Apr 2010 10:28:15 GMT^M
    P3P: policyref="http://p3p.yahoo.com/w3c/p3p.xml", CP="CAO DSP COR CUR
    ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi
    PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE GOV"^M
    cache-control: public,must-revalidate^M
    Content-Length: 0^M
    Connection: close^M
    Content-Type: ^M
    ^M

    The "puts" statement is printing
    Received status msg: Blocked By Parental Controls

    But the next statement for inequality check fails with
    can't convert nil to string

    However for a different case, where the response is
    HTTP/1.1 200 OK^M
    Date: Mon, 12 Apr 2010 10:28:29 GMT^M
    P3P: policyref="http://p3p.yahoo.com/w3c/p3p.xml", CP="CAO DSP COR CUR
    ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi
    PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE GOV"^M
    cache-control: public,must-revalidate^M
    Content-Length: 0^M
    Connection: close^M
    Content-Type: ^M
    ^M

    and I have the ruby code as:
    exp_msg = 'OK'
    puts 'Received status msg: #{response.message}'
    if(response.message != exp_msg)
    raise StandardError, "Expected #{exp_msg} Received
    #{response.message}"
    end

    Here there is no nil problem.
    I have been breaking my head and don't have the slightest clue what is
    happening. Can somebody please shed some light?
    --
    Posted via http://www.ruby-forum.com/.
    Kannan Jay, Apr 12, 2010
    #1
    1. Advertising

  2. Kannan Jay

    Kannan Jay Guest

    goddammit, i was fooled because the if statement was teh last statement
    in the code. The error didnt happen there at all. This code is a Ruby
    testframework code so it supposed to return a true/false and I was not
    returning, and that has caused the cruelly meaningless error message.
    sorry for wasting everyone's time.

    --------------------------------------------------------------------------------

    --
    Posted via http://www.ruby-forum.com/.
    Kannan Jay, Apr 12, 2010
    #2
    1. Advertising

  3. Kannan Jay

    Alex DeCaria Guest

    Kannan Jay wrote:
    > goddammit, i was fooled because the if statement was teh last statement
    > in the code. The error didnt happen there at all. This code is a Ruby
    > testframework code so it supposed to return a true/false and I was not
    > returning, and that has caused the cruelly meaningless error message.
    > sorry for wasting everyone's time.
    >
    > ------------------------------------------------------------------------------It happens. I'm glad you figured it out.


    --Alex
    --
    Posted via http://www.ruby-forum.com/.
    Alex DeCaria, Apr 13, 2010
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brian Candler

    puts nil generates "nil\n"

    Brian Candler, Nov 6, 2004, in forum: Ruby
    Replies:
    1
    Views:
    101
  2. Christoffer Sawicki
    Replies:
    5
    Views:
    236
    Christoffer Sawicki
    Sep 2, 2006
  3. aidy
    Replies:
    8
    Views:
    101
    Rimantas Liubertas
    Sep 11, 2006
  4. Replies:
    1
    Views:
    132
    Peña, Botp
    May 27, 2008
  5. Bigmac Turdsplash
    Replies:
    15
    Views:
    160
    Paul Smith
    Sep 8, 2009
Loading...

Share This Page