Last active
February 22, 2016 15:52
-
-
Save jordifierro/9d04b9a888553573c734 to your computer and use it in GitHub Desktop.
Example of an Rspec definition to test an ActiveSupport::Concern
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
require 'spec_helper' | |
module Api::V1 | |
describe Concerns::Authenticator, type: :controller do | |
controller(ApiController) do | |
def fake_current_user | |
render json: current_user | |
end | |
end | |
before do | |
routes.draw { get 'fake_current_user' => 'api/v1/api#fake_current_user' } | |
end | |
context "when correctly authenticated" do | |
before { signed_get :fake_current_user, nil } | |
it { expect(json_response['email']).to_not be_nil } | |
it { expect(response.status).to eq 200 } | |
end | |
context "when not authenticated" do | |
before { get :fake_current_user, nil } | |
it { expect(response.status).to eq 401 } | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment