Sha256: 0ed52e2b62f9426838b7a03f38b7e750decd4cae62ef2036da915dae57ca238e

Contents?: true

Size: 933 Bytes

Versions: 16

Compression:

Stored size: 933 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
    base.should == original_base
    
    # the number of parameters should match (avoid one being a subset of the other)
    query_hash.values.length.should == original_query_hash.values.length
    
    # and ensure all the keys and values match
    query_hash.each_pair do |key, value|
      original_query_hash[key].should == 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

16 entries across 16 versions & 2 rubygems

Version Path
koala-1.8.0 spec/support/custom_matchers.rb
koala-1.8.0rc1 spec/support/custom_matchers.rb
koala-1.7.0rc1 spec/support/custom_matchers.rb
edh-0.3 spec/support/custom_matchers.rb
edh-0.2 spec/support/custom_matchers.rb
edh-0.1 spec/support/custom_matchers.rb
koala-1.6.0 spec/support/custom_matchers.rb
koala-1.6.0.rc1 spec/support/custom_matchers.rb
koala-1.5.0 spec/support/custom_matchers.rb
koala-1.5.0rc1 spec/support/custom_matchers.rb
koala-1.4.1 spec/support/custom_matchers.rb
koala-1.4.0 spec/support/custom_matchers.rb
koala-1.4.0.rc1 spec/support/custom_matchers.rb
koala-1.3.0 spec/support/custom_matchers.rb
koala-1.3.0rc2 spec/support/custom_matchers.rb
koala-1.3.0rc1 spec/support/custom_matchers.rb