Capybara redirects to www.example.com

Showing 1-15 of 15 messages
Capybara redirects to www.example.com Michael Franzl 12/20/11 1:44 AM
I'm using the current versions of RSpec and Capybara for Rails
(configured with Capybara.javascript_driver = :webkit). In one of my
integration/request specs (where I use :js => true) I have the code

     post(session_path, { :password => 'xxx' })

The test.log shows that the controller is called with the correct
parameters. The controller redirects with

     redirect_to '/vendors'

However, this redirects to example.com. The test log file shows:

    Redirected to http://www.example.com/vendors

I tried the settings

Capybara.default_host = "http://localhost:3000"
Capybara.app_host = "http://localhost:3000"

but to no avail.

Any hints are appreciated how to redirect it to http://localhost:3000

Michael

Re: [Capybara] Capybara redirects to www.example.com jnicklas 12/20/11 3:30 AM
a) Capybara has no method called `post`, whatever you're using there,
it's not Capybara
b) Redirects must always be to absolute paths according to the HTTP
spec. Don't do relative redirects.
c) Never change Capybara.default_host, just don't.
d) Why do you want to redirect to localhost:3000? You do know that
Capybara starts a server for you, right?

/Jonas

Re: [Capybara] Capybara redirects to www.example.com Michael Franzl 12/20/11 8:14 AM
On 12/20/2011 12:30 PM, Jonas Nicklas wrote:
> a) Capybara has no method called `post`, whatever you're using there,
> it's not Capybara

I found the post method here:

http://rubydoc.info/github/jnicklas/capybara/master/Capybara/RackTest/Driver:post

I use it to log in directly into my app. I need to circumvent my login
form, because, as it turned out, automating the jQuery onscreen keyboard
that I use is tricky.

> b) Redirects must always be to absolute paths according to the HTTP
> spec. Don't do relative redirects.

I'm not entirely sure what you mean here. The standard redirect_to
method of Rails, specified here

http://api.rubyonrails.org/classes/ActionController/Redirecting.html#method-i-redirect_to

takes a relative path, but the server responds correctly with the
absolute path inside of the 302 status code headers. I just checked this
in my browser debugging tool.

> d) Why do you want to redirect to localhost:3000? You do know that
> Capybara starts a server for you, right?

I didn't know that. It doesn't need to be localhost:3000, but it should
be the URL where the Capybara server listens, not www.exmpale.com

Thanks.

Re: [Capybara] Capybara redirects to www.example.com jnicklas 12/20/11 8:25 AM
a) no, that's not the method you're calling. And that's a private API
anyway, which you should not use. It doesn't work in Selenium anyway,
which you have to use if you want to use jQuery, RackTest doesn't run
JavaScript at all.

Please re-read the README, I think you're missing some fundamentals on
how Capybara works.

/Jonas

Re: Capybara redirects to www.example.com tolleiv 12/23/11 6:59 AM
Hi,

just to raise this again as I ran into the same issue and reading the
READMEs doesn't resolve it at all.

I've a setup with the capybara, capybara-webkit, capybara-screenshot,
cucumber and cucumber-rails gems. I've set "Capybara.javascript_driver
= :webkit" in env.rb and running the tests with @javascript produces
nice screenshots of the "http://www.example.com" (hosted by IANA).

The cucumber testcase for a very basic rails application is also quite
trivial:

When /^the prodcut details for "([^"]*)" are opened$/ do |title|
  visit(products_url)
  page.should have_xpath("//*[@class='show']")
end


So why is it using example.com in this context?

Cheers,
Tolleiv


On Dec 20, 5:25 pm, Jonas Nicklas <jonas.nick...@gmail.com> wrote:
> a) no, that's not the method you're calling. And that's a private API
> anyway, which you should not use. It doesn't work in Selenium anyway,
> which you have to use if you want to use jQuery, RackTest doesn't run
> JavaScript at all.
>
> Please re-read the README, I think you're missing some fundamentals on
> how Capybara works.
>
> /Jonas
>
>
>
>
>
>
>
> On Tue, Dec 20, 2011 at 5:14 PM, Michael Franzl <michaelfra...@gmx.at> wrote:
> > On 12/20/2011 12:30 PM, Jonas Nicklas wrote:
>
> >> a) Capybara has no method called `post`, whatever you're using there,
> >> it's not Capybara
>
> > I found the post method here:
>
> >http://rubydoc.info/github/jnicklas/capybara/master/Capybara/RackTest...
>
> > I use it to log in directly into my app. I need to circumvent my login form,
> > because, as it turned out, automating the jQuery onscreen keyboard that I
> > use is tricky.
>
> >> b) Redirects must always be to absolute paths according to the HTTP
> >> spec. Don't do relative redirects.
>
> > I'm not entirely sure what you mean here. The standard redirect_to method of
> > Rails, specified here
>
> >http://api.rubyonrails.org/classes/ActionController/Redirecting.html#...
Re: [Capybara] Re: Capybara redirects to www.example.com jnicklas 12/23/11 10:54 AM
Somewhere in your test suite, you are probably telling Capybara to go
to "http://www.example.com", maybe through setting Capybara.app_host,
or by using visit with an absolute URL, or something silly like that.
Capybara is very diligent, it will do what you tell it to ;)

/Jonas

Re: [Capybara] Re: Capybara redirects to www.example.com Michael Franzl 12/23/11 11:48 AM
On 12/23/2011 07:54 PM, Jonas Nicklas wrote:
> Somewhere in your test suite, you are probably telling Capybara to go
> to "http://www.example.com", maybe through setting Capybara.app_host,
> or by using visit with an absolute URL, or something silly like that.
> Capybara is very diligent, it will do what you tell it to ;)

The original setting of example.com is in lib/capybara.rb:

config.default_host = "http://www.example.com"

Michael

Re: [Capybara] Re: Capybara redirects to www.example.com jnicklas 12/23/11 1:25 PM
No, default_host is only used by RackTest, something else is at work
here. Most likely you are doing something like this:

visit foo_url

This is wrong, do this instead:

visit foo_path

/Jonas

Re: Capybara redirects to www.example.com tolleiv 12/28/11 7:10 AM
Hi,

I finally figured out how to work around these issues. That's what I'm
using to get it running:

Capybara.run_server = true
Capybara.server_port = 7787
Before '@javascript' do
  Capybara.app_host = "http://127.0.0.1:#{Capybara.server_port}"
end

Source: http://stackoverflow.com/questions/8620283/capybara-webkit-tries-to-open-example-com
/ http://www.emmanueloga.com/2011/07/26/taming-a-capybara.html

What also turned out to be very important was to use "*_path" instead
of "*_url".

Anyways thanks for the feedback.

Cheers,
Tolleiv

On Dec 23, 10:25 pm, Jonas Nicklas <jonas.nick...@gmail.com> wrote:
> No, default_host is only used by RackTest, something else is at work
> here. Most likely you are doing something like this:
>
> visit foo_url
>
> This is wrong, do this instead:
>
> visit foo_path
>
> /Jonas
>
>
>
>
>
>
>
Re: [Capybara] Re: Capybara redirects to www.example.com jnicklas 12/29/11 5:44 AM
You should not need to add any of these settings. Just don't use *_url
and you should be good.

/Jonas

Re: Capybara redirects to www.example.com Chris 12/29/11 8:16 PM
I'm not using *_url in my app and it's still redirecting to
http://www.example.com, unfortunately.

I searched through my code and verified that I don't have any
references to the example.com domain.

Jonas would frown on this (sorry!), but as an experiment I also tried
adding:

    Capybara.run_server = true
    Capybara.server_port = 3000
    Capybara.app_host = "http://localhost:#{Capybara.server_port}"

and my app now redirects to localhost:3000. However, I'm getting
connection refused errors so I'm guessing Capybara's internal server
isn't actually running there.

Anything else I can try to make this work?

On Dec 29, 5:44 am, Jonas Nicklas <jonas.nick...@gmail.com> wrote:
> You should not need to add any of these settings. Just don't use *_url
> and you should be good.
>
> /Jonas
>
>
>
>
>
>
>
> On Wed, Dec 28, 2011 at 4:10 PM, tolleiv <tolleiv.niet...@googlemail.com> wrote:
> > Hi,
>
> > I finally figured out how to work around these issues. That's what I'm
> > using to get it running:
>
> > Capybara.run_server = true
> > Capybara.server_port = 7787
> > Before '@javascript' do
> >  Capybara.app_host = "http://127.0.0.1:#{Capybara.server_port}"
> > end
>
> > Source:http://stackoverflow.com/questions/8620283/capybara-webkit-tries-to-o...
> > /http://www.emmanueloga.com/2011/07/26/taming-a-capybara.html
Re: [Capybara] Re: Capybara redirects to www.example.com jnicklas 12/30/11 1:08 AM
Are you guys *sure* you are not setting app host or calling visit
anywhere with an absolute URL? Please, please check it again. These
configuration options should not be necessary, if they are, then
that's an utterly bizarre and quite serious bug. So please, check it
again. I would bet heavily on the fact that you guys are still doing
something, somewhere instructing Capybara to go to an absolute URL.

/Jonas

Re: [Capybara] Re: Capybara redirects to www.example.com Michael Franzl 12/30/11 2:10 AM
On 12/30/2011 10:08 AM, Jonas Nicklas wrote:
> Are you guys *sure* you are not setting app host or calling visit
> anywhere with an absolute URL? Please, please check it again. These
> configuration options should not be necessary, if they are, then
> that's an utterly bizarre and quite serious bug. So please, check it
> again. I would bet heavily on the fact that you guys are still doing
> something, somewhere instructing Capybara to go to an absolute URL.

As for me, I am very sure that I never use absolute paths and I
*nowhere* had example.com in my Rails app.

The only thing I maybe did wrong was using the `post` command in my
request specs as explained earlier, which was met by a `redirect_to`
inside of Rails. Since I no longer use this, this error is gone.

Michael

Re: Capybara redirects to www.example.com María Rosa Sánchez 1/6/12 3:55 PM
Hi:

Jonas I don't understand very well the problem but I also had the same
problem. I had an app with rails 3.0.5 and I upgraded it to rails
3.1.0. After that, I couldn't get my cucumber tests running. The
problem was that for some reason my host was now "http://
www.example.com". I added the lines Chris mentioned and now my tests
are running again.

PS. I am not using absolute paths neither.
Re: [Capybara] Re: Capybara redirects to www.example.com jnicklas 1/6/12 4:50 PM
If this is indeed an issue, someone needs to either create a
repeatable test case or debug it and isolate the cause. As long as
this is in your test suites, there are too many factors that could be
causing this, so please, someone who has this problem, isolate it. I'm
very sure you will find that Capybara is not the culprit, but maybe
this will give us a better understanding of how these problems arise.

/Jonas

2012/1/7 María Rosa Sánchez <ro...@innku.com>: