[rspec-users] Mocking Resolv::DNS?
raasdnil at gmail.com
Tue Jul 24 09:02:38 EDT 2007
Thank you, works perfectly!
On 7/24/07, Pat Maddox <pergesu at gmail.com> wrote:
> On 7/24/07, Mikel Lindsaar <raasdnil at gmail.com> wrote:
> > Hello Rspecers,
> > I have a rails project where I am calling Resolv::DNS.open and then
> > using the block to check a domain name.
> > The code snippet in question is:
> > domain = "mytest.com"
> > Resolv::DNS.open do |dns|
> > @mx = dns.getresources(domain, Resolv::DNS::Resource::IN::MX)
> > end
> > I obviously want to stub this out, especially for speed but can't
> > quite work out how.
> > I have done:
> > >From what I can tell, Resolv::DNS first is receiving :open and it will
> > then be yielding instances of Resolv::DNS to be using inside the
> > block.
> > So, my last unsuccessfull attempt at mocking this out is:
> > @dns = mock(Resolv::DNS)
> > Resolv::DNS.should_receive(:open).and_return([@dns])
> > @dns.should_receive(:getresources).and_return("MX Record")
> > The errors I am getting are not about mocks receiving unexpected
> > messages. The :open message mock gets called. The second one (on
> > @dns.should_receive(:getresources) also does not complain.
> > But @mx in the above code ends up as nil, when I would think it should
> > end up as "MX Record".
> > Any pointers?
> > Regards
> > Mikel
> > --
> > http://www.blognow.com.au/q
> > _______________________________________________
> > rspec-users mailing list
> > rspec-users at rubyforge.org
> > http://rubyforge.org/mailman/listinfo/rspec-users
> I'm not sure if this will work, but try
> rspec-users mailing list
> rspec-users at rubyforge.org
More information about the rspec-users