Forum: RSpec Is there any way to use a second webrat session temporarily?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
B56c79aacc04f148f4205e0ff308b39a?d=identicon&s=25 Erik Pukinskis (Guest)
on 2009-03-17 01:12
(Received via mailing list)
Dear Rspecucumberatubyists,

I have a Rails app that creates subdomains, and I'd like to verify
them in a cucumber feature like so:

  When I visit http://blingo.myapp.com
  Then I should see "Welcome to blingo!"

The trouble is, webrat's visit method strips the domain off, and keeps
only the path, so it ends up going to my site root instead of the
subdomain.

I tried creating a separate mechanize session that is used for full
urls:

require 'webrat/mechanize'

Given /^I visit (.*)$/ do |url|
  if url.match(/^http:\/\//)
    session = Webrat::MechanizeSession.new
    session.visit(url)
    response = session.response.body
  else
    visit url
  end
end

And that seems to work, but then when my "Then" step goes to find the
response, it doesn't find anything.  The "response" variable becomes
nil somewhere along the way. The step that's matching there is the
default one that ships with cucumber:

Then /^I should see "([^"]*)"$/ do |text|
  response.should contain(text)
end

Why is my response getting erased?

Love,
Erik
Cdf378de2284d8acf137122e541caa28?d=identicon&s=25 Matt Wynne (mattwynne)
on 2009-03-17 15:00
(Received via mailing list)
On 16 Mar 2009, at 23:35, Erik Pukinskis wrote:

> subdomain.
>    response = session.response.body
> Then /^I should see "([^"]*)"$/ do |text|
>  response.should contain(text)
> end
>
> Why is my response getting erased?
>
> Love,
> Erik

I think response is a method or read-only property, set by webrat when
you call #visit, so it's not something you can just set like that. I
would have a look in the webrat source code and see if you can figure
out why the subdomain is being stripped out of the request. I have a
feeling I remember someone asking about this before.

Also note that webrat has its own mailing list on google groups which
might be a better place to find answers.

HTH,

Matt Wynne
http://blog.mattwynne.net
http://www.songkick.com
This topic is locked and can not be replied to.