Created
February 2, 2016 13:01
-
-
Save vkurennov/b584859f0a61112022fb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ApiHelpers | |
def do_request(method, path, options = {}) | |
send method, path, { format: :json }.merge(options) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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