Created
April 20, 2017 14:34
-
-
Save erikdstock/686c039943ca274619c59c238943147d to your computer and use it in GitHub Desktop.
Query param matchers for rspec/rails
This file contains hidden or 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
# Match query params on some url somewhere in a text [actually a mail.body, hence the to_s] | |
# Not tested in production | |
RSpec::Matchers.define :include_query_params do |expected| | |
match do |actual| | |
query_finder = /http\S+\?(\S+)["\s'>]/ | |
queries = query_finder.match actual.to_s | |
queries.captures.any? do |q| | |
q_hash = Rack::Utils.parse_nested_query(q).symbolize_keys | |
q_hash.merge(expected) == q_hash | |
end | |
end | |
end | |
# Match a single query parameter somewhere in the a url [very dumb] | |
RSpec::Matchers.define :query_param do |expected| | |
expected = expected.to_query | |
match do |actual| | |
actual.include?(expected) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment