[rspec-users] Is there any way to use a second webrat session temporarily?
matt at mattwynne.net
Tue Mar 17 09:53:10 EDT 2009
On 16 Mar 2009, at 23:35, Erik Pukinskis wrote:
> 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
> I tried creating a separate mechanize session that is used for full
> require 'webrat/mechanize'
> Given /^I visit (.*)$/ do |url|
> if url.match(/^http:\/\//)
> session = Webrat::MechanizeSession.new
> response = session.response.body
> visit url
> 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)
> Why is my response getting erased?
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.
More information about the rspec-users