[rspec-users] Mocking Resolv::DNS?
pergesu at gmail.com
Tue Jul 24 08:12:54 EDT 2007
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)
> 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
> So, my last unsuccessfull attempt at mocking this out is:
> @dns = mock(Resolv::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?
> rspec-users mailing list
> rspec-users at rubyforge.org
I'm not sure if this will work, but try
More information about the rspec-users