[rspec-users] Cucumber, Webrat and http basic auth

kwe kwevans at gmail.com
Thu Nov 20 05:32:30 EST 2008

Starting out with Cucumber and webrat and seem to be hitting a problem
with a resource protected with http basic auth.


The following feature..

Feature: Manage Pages
  In order to add a reference pages
  As a administrator
  I want to create a page

	Scenario: Add a page
		Given I am logged in
	  And I am on the new page page
		Then I should see "New page"
		When I fill in "page_title" with "Demo Page"
		And I fill in "page_summary" with "A short trip to the loo"
		And I fill in "page_body" with "A very long long long story"
		And I press "Create"
		Then I should see "Show Page: Demo Page"

with the step "Given I am logged in" defined as..

Given /^I am logged in$/ do
	basic_auth('username', 'apassword')

All the steps work and a record is created, but the last step fails
with a "HTTP Basic: Access denied"

test.log has a

Processing PagesController#show (for at 2008-11-19 22:52:23)
  Session ID:
  Parameters: {"action"=>"show", "id"=>"1-demo-page",
Filter chain halted as [:authenticate] rendered_or_redirected.
Completed in 0.00095 (1053 reqs/sec) | Rendering: 0.00081 (85%) | DB:
0.00000 (0%) | 401 Unauthorized [http://www.example.com/admin/pages/1-

The :authenticate it refers to is a pretty standard..

  def authenticate
     authenticate_or_request_with_http_basic("no peeping") do |
username, password|
       username == 'username' && password == 'apassword'

I'm assuming it's possibly an implementation problem with webrat?!?!
Given that the steps to fill out the form and press the create button
work fine (HTTP_AUTHORIZATION is passed in the heads for each action),
but sadly not for the redirect that follows the creation of a record.

Any ideas how I should proceed?

with thanks

More information about the rspec-users mailing list