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

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

On 16 Mar 2009, at 23:35, Erik P. 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 W.
http://blog.mattwynne.net