require 'support/guards/application_guard'
require 'support/guards/user_guard'
require 'spec_helper'

RSpec.describe Guardsman::Guard do
  let(:request) { double }
  let(:scope) { double }

  # Stub out methods on the resource controller
  # because the inflector will fail in some
  # contrived scenarios. The resource controller
  # is supposed to represent a User class
  before do
    allow(scope).to receive(:to_s).and_return('User')
  end

  describe '#find!' do
    it 'returns an instantiated guard' do
      expect(Guardsman::Guard.find!(request, scope)).to be_an(ApplicationGuard)
    end

    it 'raises an error if the given guard cannot be found' do
      expect { Guardsman::Guard.find!(request, nil) }.to raise_error(NameError)
    end
  end
end
