Hi Cameron,
Thanks for your advice and code, this solved the problem. I'm now able
to integration test open id authentication using webrat and cucumber.
I'll try and give you feedback on how this process was for me.
1) I'm not familiar with mechanize so it was a change in thought
process to start a rails application (e.g. ./script/server) and then
run my cucumber tests against it. Do you have any rake tasks to
automatically start/stop the server before and after testing or do you
just leave it running?
2) I initially kept getting errors requiring an absolute url for the
webrat 'visit' method. It was a bit confusing as to fix this but I
just prefixed all the relative urls with localhost:3000 etc..
Coincidently I was reading a blog post (
http://bit.ly/ZUX3B) about how
case statements always return an object, therefore my case statement
for determining url paths can just be prefixed with "localhost:3000"
to solve this relative url problem. I've posted an example here
(
http://gist.github.com/175970).
3) Since I'm testing against the development database I need to switch
the cucumber database parameters in database.yml. This was important
because I wanted to do things like User.delete_all to clear all users
before testing. If the database parameters aren't changed then any
cucumber code using models interacts with the testing database while
I'm integration testing the development database. I guess you can also
start ./script/server to use the test database which would do the
same?
4) One final note - webrat seems to be producing some behaviour that I
can't replicate in the browser. However this may because I don't
understand rails or authlogic fully. After I register a new user I set
the controller to redirect back to the application root url. This
works in the browser but webrat instead ends up on '/users' the
controller managing authentication. The returned HTML however matches
what I see when I test authentication in the browser. Could you
suggest where I'm going wrong? I've posted the relevant lines from
webrat.log at the end of this email.
Thanks again for your help and code you sent. I would have been stuck
otherwise. I asked the same question on Stack Overflow (
http://bit.ly/
3h3AXb) as well as asking my local ruby users group but hadn't got
anywhere.
Cheers
Mike
Webrat log
----------
REQUESTING PAGE: GET
http://0.0.0.0:3000/register with {} and HTTP
headers {}
REQUESTING PAGE: POST /users with {"commit"=>"Submit", "user
[username]"=>"john", "user[openid_identifier]"=>"
http://localhost:1123/
john.doe?openid.success=true",
"authenticity_token"=>"I7siuYgiWPa5I2oak07lFh/A6hhr06V7uxU3a5QpK+0=",
"user[email]"=>"
jo...@doe.com"} and HTTP headers
{"HTTP_REFERER"=>"
http://0.0.0.0:3000/register"}
On Aug 26, 7:13 pm, "cee-dub (Cameron Walters)"