phillbaker / capybara-mechanize

RackTest driver for Capybara with remote request support

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error: mechanize requires a rack application, but none was given

DannyBen opened this issue · comments

I was hoping Mechanize can be a replacement for the outdated webkit / poltergeist drivers, so that I can just visit "http://some.domain.com" and it will work, even when called without any Rack application.

Was I wrong?

Hi @DannyBen, I don't know if this project is a full replacement for webkit/poltergesit, but I think mechanize should accept any URL. I believe this is described in the README here: https://github.com/jeroenvandijk/capybara-mechanize/#remote-testing

Can you share your current configuration or an example that is't working?

Hi,

Well, for me this can definitely be a full replacement. I am not testing complex javascript pages, but rather clicking links and filling out basic forms.

So here is the situation:

With the help of someone at the Capybara group, I realized that this:

Capybara.register_driver :mechanize do |app|
  Capybara::Mechanize::Driver.new app
end

should be changed to this:

Capybara.register_driver :mechanize do |app|
  Capybara::Mechanize::Driver.new(proc {})
end

And then things are working without a rack app.

Here is the most minimal example repo I have created for the occasion.

Perhaps the initializer for Capybara::Mechanize::Driver.new can have its "app" argument optional, and default to proc {}? Or, if not, maybe something in the README to mention how to use this without a rack app?

Also, as for the default app that you pointed me to - yes, I am aware of this, but I only care about testing fully qualified external URLs, so I guess it will not come into play.

TL;DR; It's not that capybara-mechanize requires an app, it's that the rack-test driver does.

The issue here is that capybara-mechanize derives from the rack-test driver, and the rack-test driver requires an app. If the user sticks to only visiting fully qualified urls then only the capybara-mechanize version of visit is used, and the rack-test driver version of visit (which is what requires the app to route to) is never called and therefore the app isn't strictly necessary.

I understand, assuming that my understanding is also correct when saying that even when using relative URLs, it will still bypass the default Rack::Test if Capybara.app_host is set.

What I am saying (now that there is a solution) is this:

The original intention of Capybara-Mechanize (so it seems) was to be a "Rack::Test + external links" driver.

I think that it can also act as a very lightweight way to do general purpose acceptance tests on sites that are external (to the point of view of the feature definitions).

I have this kind of setup, and up until now I was working with the heavy weights webkit / selenium / poltergeist.

For this to be fully true, it should be able to initialize without a rack app. Right now it sort of does, by using the proc {} app above, I wish this "implementation detail" would be hidden.

In other words, would it make sense to change line 6 here:

https://github.com/jeroenvandijk/capybara-mechanize/blob/1428d6a96f0ab91c18aa88e76e21661e0e30e96b/lib/capybara/mechanize/driver.rb#L5-L7

to something like:

def initialize(app=nil, **options)
  app ||= proc {}
  #...