Sha256: 5f6f6f0be3c359884890f752a819e83e85f9c8449a2d088fecb8bb551cd3db85

Contents?: true

Size: 948 Bytes

Versions: 32

Compression:

Stored size: 948 Bytes

Contents

# Verifies that two URLs are equal, ignoring the order of the query string parameters
RSpec::Matchers.define :match_url do |url|
  match do |original_url|
    base, query_string = url.split("?")
    original_base, original_query_string = original_url.split("?")
    query_hash = query_to_params(query_string)
    original_query_hash = query_to_params(original_query_string)

    # the base URLs need to match
    expect(base).to eq(original_base)
    
    # the number of parameters should match (avoid one being a subset of the other)
    expect(query_hash.values.length).to eq(original_query_hash.values.length)
    
    # and ensure all the keys and values match
    query_hash.each_pair do |key, value|
      expect(original_query_hash[key]).to eq(value)
    end
  end
  
  def query_to_params(query_string)
    query_string.split("&").inject({}) do |hash, segment|
      k, v = segment.split("=")
      hash[k] = v
      hash
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
koala-3.6.0 spec/support/custom_matchers.rb
koala-3.5.0 spec/support/custom_matchers.rb
koala-3.4.0 spec/support/custom_matchers.rb
koala-3.3.0 spec/support/custom_matchers.rb
koala-3.2.0 spec/support/custom_matchers.rb
koala-3.1.0 spec/support/custom_matchers.rb
koala-3.0.0 spec/support/custom_matchers.rb
koala-3.0.0.rc2 spec/support/custom_matchers.rb
koala-3.0.0.rc spec/support/custom_matchers.rb
koala-3.0.0.beta3 spec/support/custom_matchers.rb
koala-3.0.0.beta2 spec/support/custom_matchers.rb
koala-3.0.0.beta1 spec/support/custom_matchers.rb
koala-2.5.0 spec/support/custom_matchers.rb
koala-2.5.0rc1 spec/support/custom_matchers.rb
koala-2.4.0 spec/support/custom_matchers.rb
koala-2.3.0 spec/support/custom_matchers.rb
koala-2.3.0rc1 spec/support/custom_matchers.rb
koala-2.2.0 spec/support/custom_matchers.rb
koala-2.2.0rc3 spec/support/custom_matchers.rb
koala-2.2.0rc2 spec/support/custom_matchers.rb