Abridged version:
Using the omniauth gem for sinatra, I cannot get rspec to get into work and save the session for future requests.
Based on the suggestions of http://benprew.posterous.com/testing-sessions-with-sinatra and disconnecting sessions, I highlighted a problem:
app.send(:set, :sessions, false)
How do I get rspec to monitor redirection and save session variables? Is this possible in Sinatra?
From http://benprew.posterous.com/testing-sessions-with-sinatra it seems that I will have to send session variables in each receive / send request, for which I need a login for, but this will not work in case of redirection.
Details:
I am trying to use omniauth gem in sinatra with the following setting:
spec_helper.rb
ENV['RACK_ENV'] = 'test'
web_spec.rb
describe "Authentication:" do before do OmniAuth.config.test_mode = true OmniAuth.config.add_mock(:google_oauth2, { :uid => '222222222222222222222', :info => { :email => " someone@example.com ", :name => 'Someone' } }) end describe "Logging in as a new user" do it "should work" do get '/auth/google_oauth2/' last_response.body.should include("Welcome") end end end
When I try to authenticate, I get a response <h1>Not Found</h1>
. What am I missing?
The omniauth docs page integration test page mentions adding two environment variables:
before do request.env["devise.mapping"] = Devise.mappings[:user] request.env["omniauth.auth"] = OmniAuth.config.mock_auth[:twitter] end
But it seems to be for rails only, as I added
request.env["omniauth.auth"] = OmniAuth.config.mock_auth[:google_oauth2]
in my before
block in my specification, and I get this error:
Failure/Error: request.env["omniauth.auth"] = OmniAuth.config.mock_auth[:google_oauth2] ArgumentError: wrong number of arguments (0 for 1)
Edit:
Call get
with
get '/auth/google_oauth2/', nil, {"omniauth.auth" => OmniAuth.config.mock_auth[:google_oauth2]}
seems to me last_request.env["omniauth.auth"]
to be equal
{"provider"=>"google_oauth2", "uid"=>"222222222222222222222", "info"=>{"email"=>" someone@example.com ", "name"=>"Someone"}}
which seems correct, but last_response.body
still returns
<h1>Not Found</h1>