Ruby Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesRuby Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 12th, 2010, 09:37 AM
old_as_a_fossil old_as_a_fossil is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2010
Posts: 6 old_as_a_fossil User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 7 m 50 sec
Reputation Power: 0
Thumbs down Non empty string complained to be 'nil' in equality check

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="(blah url)", 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="(blah url)", 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?

Reply With Quote
  #2  
Old April 12th, 2010, 10:14 AM
TheOtherDino's Avatar
TheOtherDino TheOtherDino is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2010
Location: Katy, Texas
Posts: 489 TheOtherDino User rank is First Lieutenant (10000 - 20000 Reputation Level)TheOtherDino User rank is First Lieutenant (10000 - 20000 Reputation Level)TheOtherDino User rank is First Lieutenant (10000 - 20000 Reputation Level)TheOtherDino User rank is First Lieutenant (10000 - 20000 Reputation Level)TheOtherDino User rank is First Lieutenant (10000 - 20000 Reputation Level)TheOtherDino User rank is First Lieutenant (10000 - 20000 Reputation Level)TheOtherDino User rank is First Lieutenant (10000 - 20000 Reputation Level)TheOtherDino User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 4 Days 18 h 25 m 29 sec
Reputation Power: 198
As you say, this line is giving you the error:
Code:
if(response.message != exp_msg)

That error cannot happen on that line, unless response is nil, and based on how far you have gotten, that can't happen either.

I would suggest you add some more diagnostics to your code.

Reply With Quote
  #3  
Old April 12th, 2010, 10:44 AM
old_as_a_fossil old_as_a_fossil is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2010
Posts: 6 old_as_a_fossil User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 7 m 50 sec
Reputation Power: 0
I know it can't happen, I have no clue. Just before the if statement I'm printing response.message it is printing the value.
Never encountered something so weird.

Reply With Quote
  #4  
Old April 12th, 2010, 12:40 PM
old_as_a_fossil old_as_a_fossil is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2010
Posts: 6 old_as_a_fossil User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 7 m 50 sec
Reputation Power: 0
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesRuby Programming > Non empty string complained to be 'nil' in equality check

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap