Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
DannyBen opened this issue Sep 30, 2018 · 4 comments
Open

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

DannyBen opened this issue Sep 30, 2018 · 4 comments

Comments

@DannyBen
Copy link

DannyBen commented Sep 30, 2018

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?

@phillbaker
Copy link
Owner

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?

@DannyBen
Copy link
Author

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.

@twalpole
Copy link
Contributor

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.

@DannyBen
Copy link
Author

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 {}
  #...

duleorlovic added a commit to duleorlovic/capybara-mechanize that referenced this issue Jan 12, 2020
This example will help all users that follow README but did not come across phillbaker#66
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants