# encoding: utf-8 require 'spec_helper' class GAuthApp < Sinatra::Base register Sinatra::GAuth set :gauth_redirect, '/not-protected' get '/not-protected' do "Hello! I'm not protected." end get '/protected' do protect_with_gauth! "Hello! I'm protected with gauth." end end describe Sinatra::GAuth do include Rack::Test::Methods def app GAuthApp.new end describe "if route is not protected" do it 'will not redirect user' do get '/not-protected' last_response.status.must_equal 200 end end describe "if route is protected" do it 'will redirect user for authentication' do get '/protected' last_response.status.must_equal 302 end it 'will redirect to /auth/g' do get '/protected' last_response.original_headers['Location'].must_equal 'http://example.org/auth/g' end end end