[rspec-users] Is there any way to use a second webrat session temporarily?

Erik Pukinskis erikpukinskis at gmail.com
Mon Mar 16 19:35:36 EDT 2009


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


More information about the rspec-users mailing list