Skip to content

Commit

Permalink
refactor: update specs to reflect the changes in internal API
Browse files Browse the repository at this point in the history
  • Loading branch information
ksol committed Feb 11, 2024
1 parent 1cd8a92 commit 38a9e5d
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 15 deletions.
4 changes: 2 additions & 2 deletions spec/scalingo/auth/tokens_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
let(:stub_pattern) { "exchange-200" }

it "is successful" do
expect(response).to be_successful
expect(response.data[:token]).to be_present
expect(response).to be_success
expect(response.body).to be_present
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/scalingo/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
it "is successful with valid token" do
fake_response = OpenStruct.new(
successful?: true,
data: {token: "response token"}
data: "response token"
)

expect(subject.auth.tokens).to receive(:exchange).and_return(fake_response)
Expand Down
2 changes: 2 additions & 0 deletions spec/scalingo/regional/addons_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
context "success" do
let(:arguments) { [meta[:app_id], meta[:provision][:valid]] }
let(:stub_pattern) { "provision-201" }
let(:expected_keys) { %i[addon message] }

it_behaves_like "a singular object response", 201
end
Expand Down Expand Up @@ -139,6 +140,7 @@
context "success" do
let(:arguments) { [meta[:app_id], meta[:id], meta[:update][:valid]] }
let(:stub_pattern) { "update-200" }
let(:expected_keys) { %i[addon message] }

it_behaves_like "a singular object response"
end
Expand Down
1 change: 1 addition & 0 deletions spec/scalingo/regional/apps_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
context "success" do
let(:arguments) { meta[:id] }
let(:stub_pattern) { "logs_url" }
let(:expected_keys) { %i[app logs_url] }

it_behaves_like "a singular object response"
end
Expand Down
1 change: 0 additions & 1 deletion spec/scalingo/regional/collaborators_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
context "success" do
let(:arguments) { meta[:accept][:valid] }
let(:stub_pattern) { "accept-200" }
let(:expected_keys) { %i[app] }

it_behaves_like "a singular object response"
end
Expand Down
2 changes: 1 addition & 1 deletion spec/scalingo/regional/logs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
let(:stub_pattern) { "archives-200" }

it_behaves_like "a collection response"
it_behaves_like "a non-paginated collection"
it_behaves_like "a cursor paginated collection"
end
end
end
26 changes: 16 additions & 10 deletions spec/support/shared.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,30 @@
end
end

RSpec.shared_examples "a not found response" do
it "cannot be found" do
expect(response).not_to be_successful
expect(response.status).to eq 404
end
end

RSpec.shared_examples "a client error" do
it "is a generic client error" do
expect(response).not_to be_successful
expect(response).to be_client_error
expect(response.status).to eq 400
end
end

RSpec.shared_examples "a server error" do
it "is a generic server error" do
expect(response).not_to be_successful
expect(response).to be_server_error
expect(response.status).to eq 500
end
end

RSpec.shared_examples "a not found response" do
it "cannot be found" do
expect(response).to be_client_error
expect(response.status).to eq 404
end
end

RSpec.shared_examples "an unprocessable request" do
it "cannot be found" do
expect(response).not_to be_successful
expect(response).to be_client_error
expect(response.status).to eq 422
end
end
Expand Down Expand Up @@ -119,6 +119,12 @@
end
end

RSpec.shared_examples "a cursor paginated collection" do |code = 200|
it "is cursor paginated" do
expect(response).to be_cursor_paginated
end
end

RSpec.shared_examples "a non-paginated collection" do |code = 200|
it "is not paginated" do
expect(response).not_to be_paginated
Expand Down

0 comments on commit 38a9e5d

Please sign in to comment.