Skip to content

Instantly share code, notes, and snippets.

@vkurennov
Created February 2, 2016 13:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vkurennov/b584859f0a61112022fb to your computer and use it in GitHub Desktop.
Save vkurennov/b584859f0a61112022fb to your computer and use it in GitHub Desktop.
shared_examples_for "API Authenticable" do
context "unauthorized" do
it 'returns 401 status if request has not access token' do
do_request(method, api_path)
expect(response.status).to eq 401
end
it 'returns 401 status if access token is invalid' do
do_request(method, api_path, access_token: '1234')
expect(response.status).to eq 401
end
end
end
module ApiHelpers
def do_request(method, path, options = {})
send method, path, { format: :json }.merge(options)
end
end
RSpec.describe "Questions API" do
describe "GET /index" do
it_behaves_like "API Authenticable" do
let(:method) { :get }
let(:api_path) { '/api/v1/questions' }
end
end
end
RSpec.configure do |config|
# ..
config.include ApiHelpers
# ..
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment