tenderlove/mechanize — Issue #185: undefined method `flush' for nil:NilClass (NoMethodError) raised when running Google example
Author: jana4u
Created: 2012-01-08 10:47:09+00:00
State: open

Running Google example from https://github.com/tenderlove/mechanize/blob/master/EXAMPLES.rdoc using mechanize 2.1 raises exception. I tried both ruby 1.8.7 and 1.9.2 with same results.

```
c:\Projects\ruby\mechanize>ruby google.rb
C:/Ruby187/lib/ruby/gems/1.8/gems/mechanize-2.1/lib/mechanize/http/agent.rb:720:in `response_content_encoding': undefined method `flush' for nil:NilClass (NoMethodError)
from C:/Ruby187/lib/ruby/gems/1.8/gems/mechanize-2.1/lib/mechanize/http/agent.rb:274:in `fetch'
from C:/Ruby187/lib/ruby/gems/1.8/gems/mechanize-2.1/lib/mechanize.rb:319:in `get'
from C:/Ruby187/lib/ruby/gems/1.8/gems/mechanize-2.1/lib/mechanize.rb:428:in `submit'
from C:/Ruby187/lib/ruby/gems/1.8/gems/mechanize-2.1/lib/mechanize/form.rb:178:in `submit'
from google.rb:9
from C:/Ruby187/lib/ruby/gems/1.8/gems/mechanize-2.1/lib/mechanize.rb:321:in `get'
from google.rb:8
```

Everything works fine when I use older mechanize (2.0.1).

Commenting line with setting user agent solves the issue, but I want to be able to set my own user agent even in the latest version...

```ruby
require 'rubygems'
require 'mechanize'

a = Mechanize.new { |agent|
#agent.user_agent_alias = 'Mac Safari'
}

a.get('http://google.com/') do |page|
search_result = page.form_with(:name => 'f') do |search|
search.q = 'Hello world'
end.submit

search_result.links.each do |link|
puts link.text
end
end
```