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: def test_open_port net_mock = mock(''Net::HTTP'') Net::HTTP.expects(:new).once.with(exp_host, exp_port).returns(net_mock) net_connection = NetConnection.new(exp_host, exp_port) end 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 1) Failure: unexpected invocation: #<Mock:Net::HTTP>.use_ssl=(true) unsatisfied expectations: - expected exactly once, not yet invoked: #<Mock:Net::HTTP>.use_ssl(true) satisfied expectations: - expected exactly once, already invoked once: - expected exactly once, already invoked once: Net::HTTP.new(exp_host, exp_port) Any suggestions? thanks Michael -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Michael Corr 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...but why not use WebMock? It already does exactly what you''re trying to do. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org Sent from my iPhone -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Tue, Dec 28, 2010 at 8:15 AM, Marnen Laibow-Koser <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>wrote:> Michael Corr 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?> but why not use WebMock? It already > does exactly what you''re trying to do. > > Best, > -- > Marnen Laibow-Koser > http://www.marnen.org > marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org > > Sent from my iPhone > > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
David Kahn wrote in post #971102:> On Tue, Dec 28, 2010 at 8:15 AM, Marnen Laibow-Koser > <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>wrote: > >> Michael Corr 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 Groups.) Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org Sent from my iPhone -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Dec 28, 1:07 am, Michael Corr <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> > 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 >These *are* method calls (and the corresponding method name is foo= ) Fred -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung wrote in post #971106:> These *are* method calls (and the corresponding method name is foo= ) > > FredFred 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 -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.