Cucumber, webrat mechanize testing php/drupal application on MAMP, authentication issue
I've got cucumber testing my drupal application with passing tests like so:
Given /^I am authenticated as a "([^"]*)" user$/ do |role|
visit('/user')
fill_in "name", :with => "user_#{开发者_如何转开发role.downcase}"
fill_in "pass", :with => "password"
click_button
visit('/') #gets around a 302 redirect issue
response_body.should contain("Log out")
end
My env.rb is like so:
require 'rspec/expectations'
require 'webrat'
require 'test/unit/assertions'
World(Test::Unit::Assertions)
Webrat.configure do |config|
config.mode = :mechanize
end
World do
session = Webrat::Session.new
session.extend(Webrat::Methods)
session.extend(Webrat::Matchers)
session.visit('http://localhost')
session
end
This passes just fine when my virtual host on MAMP is the default localhost. But when I create another virtual host, with the same document (and update the session.visit to use the new root) this test fails. It seems the session is lost.
Does anyone know how to debug this? I've looked at the html output and it shows the content as an unauthenticated user which is why I think the session is being reset.
Edit
I checked the virtual hosts and they are exactly the same. The one with failing tests tends to be an order of magnitude slower.I eventually moved to capybara. There were versions of mechanize that had a few bugs around posting form data etc. Capybara works much better.
精彩评论