Skip to content

Instantly share code, notes, and snippets.

@myronmarston
Last active December 21, 2015 07:48
Show Gist options
  • Save myronmarston/6273546 to your computer and use it in GitHub Desktop.
Save myronmarston/6273546 to your computer and use it in GitHub Desktop.
shared_examples_for "a search endpoint" do |queries_to_test|
queries_to_test.each do |query, expected_results|
context "for query: #{query}" do
let(:url) { build_url(resource, query) }
it 'is a valid endpoint' do
get url
expect(last_response.status).to eq 200
end
end
end
def build_url(resource, query)
escaped_query = URI.escape(query)
"/#{resource}/search?query=#{escaped_query}"
end
end
describe 'A Sample Resource API' do
context 'GET /resource/search' do
it_should_behave_like 'a search endpoint', "foo" => 1, "bar" => 1 do
let(:resource) { "resource_name" }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment