RSpec.describe OmniAuth::Strategies::Identity do attr_accessor :app let(:auth_hash) { last_response.headers['env']['omniauth.auth'] } let(:identity_hash) { last_response.headers['env']['omniauth.identity'] } let(:identity_options) { {} } let(:anon_ar) do AnonymousActiveRecord.generate( columns: %w[name provider], connection_params: { adapter: 'sqlite3', encoding: 'utf8', database: ':memory:' } ) do def balloon '🎈' end end end # customize rack app for testing, if block is given, reverts to default # rack app after testing is done def set_app!(identity_options = {}) old_app = app self.app = Rack::Builder.app do use Rack::Session::Cookie, secret: '1234567890qwertyuiop' use OmniAuth::Strategies::Identity, identity_options run ->(env) { [404, { 'env' => env }, ['HELLO!']] } end if block_given? yield self.app = old_app end app end before do opts = identity_options.reverse_merge({ model: anon_ar }) set_app!(opts) end describe '#request_phase' do context 'with default settings' do let(:identity_options) { { model: anon_ar } } it 'displays a form' do get '/auth/identity' expect(last_response.body).not_to eq('HELLO!') expect(last_response.body).to be_include('