addressalign-toparrow-leftarrow-rightbackbellblockcalendarcameraccwchatcheckchevron-downchevron-leftchevron-rightchevron-small-downchevron-small-leftchevron-small-rightchevron-small-upchevron-upcircle-with-crosscrosseditemptyheartfacebookfolderfullheartglobegmailgoogleimagesinstagramlinklocation-pinmagnifying-glassmailminusmoremuplabelShape 3 + Rectangle 1outlookpersonplusprice-ribbonImported LayersImported LayersImported Layersshieldstartrashtriangle-downtriangle-uptwitteruseryahoo

rails rspec integration_tests and http authentication

From: Jon S.
Sent on: Saturday, March 2, 2013 5:11 PM

I am using Rspec 2 and capybara and defined the basic integration test, i.e.

describe "EeRequisitions" do
  describe "GET /ee_requisitions" do
    it "works! (now write some real specs)" do
      get ee_requisitions_path
      response.status.should be(200)

Since the app uses HTTP basic authentication and since capybara says it includes Rack::Test, I expected that adding the line:

authorize 'user', 'password'

would handle it (I've since lost the stackoverflow post that told me that). Unfortunately it didn't - it kept throwing a 'method not found' error. I finally found the solution in a comment to this post: Rails/Rspec Make tests to pass with http basic authentication where Matt Connelly pointed me to this gist: which finally solved my problem.

So what I do now is call the function (defined in spec/support/auth_helper.rb)

and replace this line:
get ee_requistitions_path
get ee_requisitions_path, {}, @env

However, I'm still wondering why the Rack::Test approach failed as it seems to have worked for others.Any suggestions on where to look for greater understanding would be appreciated as this is pure magic.

Thanks much...jon

Jon Seidel, CMC®

EDP Consulting, Inc. / /

Effective Decisions... Priceless

Our Sponsors

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy