-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
specs: default context, shared groups
- Loading branch information
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
RSpec.shared_context "default endpoint context" do | ||
let(:bearer_token) { "Bearer token" } | ||
|
||
let(:arguments) do | ||
args = {} | ||
args[:connected] = connected if defined?(connected) | ||
args[:basic] = basic if defined?(basic) | ||
args[:body] = body if defined?(body) | ||
args.merge!(params) if defined?(params) | ||
args.compact! | ||
|
||
args | ||
end | ||
|
||
let(:scalingo_client) do | ||
scalingo = Scalingo::Client.new | ||
scalingo.authenticate_with(bearer_token: bearer_token) if bearer_token | ||
scalingo | ||
end | ||
|
||
let(:api_path) { URI.parse("http://localhost") } | ||
|
||
let(:api_client) { described_class.module_parent.new(api_path.to_s, scalingo: scalingo_client) } | ||
let(:instance) { described_class.new(api_client) } | ||
|
||
subject do | ||
response # need to be defined in the including context | ||
WebMock # returning this lets us use the one-liner `have_requested` syntax | ||
end | ||
end | ||
|
||
RSpec.shared_examples "requires authentication" do | ||
context "when the client is not authenticated" do | ||
let(:bearer_token) { nil } | ||
|
||
it "raises an exception" do | ||
expect { subject }.to raise_error(Scalingo::Error::Unauthenticated) | ||
end | ||
end | ||
end | ||
|
||
RSpec.shared_examples "requires some params" do |*keys| | ||
keys.each do |key| | ||
context "when #{key} is missing" do | ||
before { params.delete(key) } | ||
|
||
it "raises an exception" do | ||
expect { subject }.to raise_error(ArgumentError) | ||
end | ||
end | ||
end | ||
end |