0

I'm trying to use the Ruby gem Mechanize in an app I'm building, but I'm getting an error.

Performing the following in IRB with Ruby 1.9.3-p0:

require 'Mechanize'
agent = Mechanize.new
page = agent.get('http://www.google.com')

Gives me the following error:

NoMethodError: undefined method `info' for nil:NilClass
from ~/.rvm/gems/ruby-1.9.3-p0@global/gems/net-http-spy-0.2.1/lib/net-http-spy.rb:24:in 'initialize'

The initialize block of net-http-spy.rb looks like this:

def initialize(*args, &block)
  self.class.http_logger_options ||= {}
  defaults =  {:body => false, :trace => false, :verbose => false, :limit => -1}
  self.class.http_logger_options = (self.class.http_logger_options == :default) ? defaults : self.class.http_logger_options
  @logger_options = defaults.merge(self.class.http_logger_options)
  @params_limit = @logger_options[:params_limit] || @logger_options[:limit]
  @body_limit   = @logger_options[:body_limit]   || @logger_options[:limit]

  self.class.http_logger.info "CONNECT: #{args.inspect}" if !@logger_options[:verbose]

  old_initialize(*args, &block)
  @debug_output   = self.class.http_logger if @logger_options[:verbose]
end

It appears to be the line starting self.class.http_logger.info which is causing problem, I'm just not sure why. Can anyone shed any light as to what I'm doing wrong?

purpletonic
  • 1,858
  • 2
  • 18
  • 29
  • This isn't really a Mechanize issue. I'd uninstall net-http-spy. There seems to be an incompatibility somewhere. If you want to record your Mechanize interactions, try [VCR](https://www.relishapp.com/myronmarston/vcr). – Mark Thomas Jan 30 '12 at 21:10
  • Hmmm. Wondering if this is maybe down to RVM, as net-http-spy is in my global gemset, whereis Mechanize is in the project gemset. I tried un/reinstalling net-http-spy, but I'm still having the same issue. – purpletonic Jan 30 '12 at 22:53

0 Answers0