Hi
I’m using Mocha to mock a HTTP connection, so I can test higher level
application code without requiring a ‘live’ webserver host. However, I’m
having difficulty trying to stub some of the
connection handle parameters.
My connection class init opens the port as follows:
class NetConnection
def initialize(host, port)
# – Outgoing is an Https post @handle_tx = Net::HTTP.new(host, port) @handle_tx.use_ssl = true @handle_tx.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
end
In my test class, I’m mocking the Net::HTTP connection as follows:
The problem is in the following calls in the NetConnection constructor @handle_tx.use_ssl = true @handle_tx.verify_mode = OpenSSL::SSL::VERIFY_NONE
Since these are assignments, not methods with parameters, how do I stub
them? I couldn’t find an appropriate method in the Mocha API
I tried the following, but they don’t ‘match’ the actual call
net_mock.expects(:use_ssl).once.with(true)
net_mock.expects(:verify_mode).once.with(‘OpenSSL::SSL::VERIFY_NONE’)
I get the following error when I use the above expects for :use_ssl
Hi
I’m using Mocha to mock a HTTP connection, so I can test higher level
application code without requiring a ‘live’ webserver host. However, I’m
having difficulty trying to stub some of the
connection handle parameters.
This doesn’t really have anything to do with Rails, so it should have
been asked on the main Ruby list…but why not use WebMock? It already
does exactly what you’re trying to do.
On Tue, Dec 28, 2010 at 8:15 AM, Marnen Laibow-Koser [email protected]wrote:
Michael C. wrote in post #970988:
Hi
I’m using Mocha to mock a HTTP connection, so I can test higher level
application code without requiring a ‘live’ webserver host. However, I’m
having difficulty trying to stub some of the
connection handle parameters.
This doesn’t really have anything to do with Rails, so it should have
been asked on the main Ruby list…
OT, but what is the ‘main’ ruby list? I just looked for google groups
for
‘ruby’ and see a few, any recommendations?
On Tue, Dec 28, 2010 at 8:15 AM, Marnen Laibow-Koser [email protected]wrote:
Michael C. wrote in post #970988:
Hi
I’m using Mocha to mock a HTTP connection, so I can test higher level
application code without requiring a ‘live’ webserver host. However, I’m
having difficulty trying to stub some of the
connection handle parameters.
This doesn’t really have anything to do with Rails, so it should have
been asked on the main Ruby list…
OT, but what is the ‘main’ ruby list? I just looked for google groups
for
‘ruby’ and see a few, any recommendations?
I believe the main list is called ruby-talk. (I use ruby-forum.com for
my Web interface, though, not Google G…)
These are method calls (and the corresponding method name is foo= )
Fred
Fred
That worked - thank you. I figured it was something simple that I was
missing
Marnen/David
I apologize if this wasn’t the correct list to post this question. The
mocha-dev@rubyforge forum seems to be ‘dead’, and when I did a search
across all forums at www.ruby-forum.com for previous posts about
‘mocha’, this one gave me the most hits so I thought I’d start here
thanks everyone
Michael
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.