I am beginning my first real Ruby app and having some problems
understanding how to use basic auth in webunit.
I have created a test case like so:
require ‘webunit/webunit’
class LoggerTest < WebUnit::TestCase
def setup
super
$DEBUG=true
@url
="http://myhostname:10405/mbean?objectname=Portal:name=JVM"
end
def testAuthenticate
user="fred"
pass="opensesame"
response = WebUnit::Response::get( @url , nil,
%w(user pass) )
assert_title( “MX4J - MBean View”, response )
puts response.inspect()
end
end
test = LoggerTest.new(“testAuthenticate”)
test.setup
test.testAuthenticate
Can anyone tell me what %w(user pass) does?
but the program fails with the following (with debug enabled)
C:/ruby/lib/ruby/site_ruby/webunit/response.rb:94: undefined method
to_str’ for nil’ (NameError)
C:/ruby/lib/ruby/site_ruby/webunit/response.rb:94: undefined method
to_str’ for nil’ (NameError)
C:/ruby/lib/ruby/site_ruby/webunit/response.rb:102: undefined method
to_ary’ for “/mbean?objectname=Portal:name=JVM”:String’ (NameError)
/mbean?objectname=Portal:name=JVM
C:/ruby/lib/ruby/1.6/net/protocol.rb:630: End of file reached' (EOFError) from C:/ruby/lib/ruby/1.6/net/http.rb:1296:in
read_body_0’
from C:/ruby/lib/ruby/1.6/net/http.rb:1262:in read_body' from C:/ruby/lib/ruby/1.6/net/http.rb:1281:in
terminate’
from C:/ruby/lib/ruby/1.6/net/http.rb:631:in __send__' from C:/ruby/lib/ruby/1.6/net/http.rb:631:in
connecting’
from C:/ruby/lib/ruby/1.6/net/http.rb:602:in request' from C:/ruby/lib/ruby/1.6/net/http.rb:598:in
request’
from C:/ruby/lib/ruby/1.6/net/http.rb:597:in start' from C:/ruby/lib/ruby/1.6/net/http.rb:597:in
request’
from C:/ruby/lib/ruby/1.6/net/http.rb:583:in get2' from C:/ruby/lib/ruby/site_ruby/webunit/response.rb:103:in
init_http’
from C:/ruby/lib/ruby/site_ruby/webunit/response.rb:32:in get' from C:\apps\workspace\rubyDev\src\test.rb:18:in
testAuthenticate’
from C:\apps\workspace\rubyDev\src\test.rb:32
C:/ruby/lib/ruby/1.6/net/protocol.rb:630: @buffer << @socket.sysread(
READ_SIZE )
Does this error mean anything to anyone?
Has anyone else got basic auth working in webunit?
Peter Booth.