I’m trying to write an integration that tests the whole Twitter authentication process. Every example (except for one) that I’ve found suggests mocking the response out, which I’d rather not do.
The problem
The app sends people to the Twitter OAuth permission page. Then Twitter redirects the person back to my app, I get the token and go on my way.
Here’s the test in question:
it "should follow on twitter" do
visit "/"
click_link "Follow us on Twitter" # Sends them to the permission page
fill_in "username_or_email", with: "secretaccount"
fill_in "password", with: "secretpassword"
click_button "Authorize app" # Where Twitter redirects back to my site
end
In development, Twitter redirects back to local.host:3000 just fine. When testing, though, it redirects to www.example.com, which has nothing to do with my app. Everything works perfectly until this point.
How can I get Twitter to redirect the test person to my app in the test environment?
What I’m using
- Capybara
- Capybara-mechanize
- Minitest
- Rails 3.1.2
- Ruby 1.9.2
Any help would be awesome. If I left anything out, let me know. Thanks!
capybara uses “www.example.com” as a default host. Try putting this in your spec_helper:
But you have to actually run a server in port 3001 during testing for this to work. Capybara also supports this
And you must also use a driver that uses that server. The default goes through the rack stack, so use selenium or webkit.