Skip to content

Commit

Permalink
test: extract shared examples for "a paginated response"
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Jun 19, 2023
1 parent 749b464 commit 80cd234
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
14 changes: 2 additions & 12 deletions spec/features/get_pacticipants_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,11 @@
context "with pagination options" do
subject { get(path, { "pageSize" => "2", "pageNumber" => "1" }) }

it "paginates the response" do
it "only returns the number of items specified in the pageSize" do
expect(response_body_hash[:_links][:"pacticipants"].size).to eq 2
end

it "includes the pagination relations" do
expect(response_body_hash[:_links]).to have_key(:next)
end

it "includes the page section" do
expect(response_body_hash).to have_key(:page)
end

it "outputs a whole number for total pages" do
expect(response_body_hash[:page][:totalPages]).to eq(2)
end
it_behaves_like "a paginated response"
end
end
end
Expand Down
19 changes: 19 additions & 0 deletions spec/support/shared_examples_for_responses.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,25 @@

end

shared_examples_for "a paginated response" do
let(:response_body_hash) { JSON.parse(subject.body, symbolize_names: true) }

it "includes the pagination relations" do
expect(response_body_hash[:_links]).to have_key(:next)
end

it "includes the page details" do
expect(response_body_hash).to include(
page: {
number: instance_of(Integer),
size: instance_of(Integer),
totalElements: instance_of(Integer),
totalPages: instance_of(Integer),
}
)
end
end

require "rspec/expectations"

RSpec::Matchers.define :be_a_hal_json_success_response do
Expand Down

0 comments on commit 80cd234

Please sign in to comment.