File: equivalent_uri_test.rb

package info (click to toggle)
ruby-mocha 3.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,652 kB
  • sloc: ruby: 12,324; javascript: 499; makefile: 14
file content (43 lines) | stat: -rw-r--r-- 1,520 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# frozen_string_literal: true

require File.expand_path('../../../test_helper', __FILE__)
require 'mocha/parameter_matchers/equivalent_uri'

class EquivalentUriTest < Mocha::TestCase
  include Mocha::ParameterMatchers::Methods

  def test_should_match_identical_uri
    matcher = equivalent_uri('http://example.com/foo?a=1&b=2')
    assert matcher.matches?(['http://example.com/foo?a=1&b=2'])
  end

  def test_should_match_uri_with_rearranged_query_string
    matcher = equivalent_uri('http://example.com/foo?b=2&a=1')
    assert matcher.matches?(['http://example.com/foo?a=1&b=2'])
  end

  def test_should_not_match_uri_with_different_query_string
    matcher = equivalent_uri('http://example.com/foo?a=1')
    assert !matcher.matches?(['http://example.com/foo?a=1&b=2'])
  end

  def test_should_not_match_uri_when_no_query_string_expected
    matcher = equivalent_uri('http://example.com/foo')
    assert !matcher.matches?(['http://example.com/foo?a=1&b=2'])
  end

  def test_should_not_match_uri_with_different_domain
    matcher = equivalent_uri('http://a.example.com/foo?a=1&b=2')
    assert !matcher.matches?(['http://b.example.com/foo?a=1&b=2'])
  end

  def test_should_match_uri_without_scheme_and_domain
    matcher = equivalent_uri('/foo?a=1&b=2')
    assert matcher.matches?(['/foo?a=1&b=2'])
  end

  def test_should_match_uri_with_query_string_containing_blank_value
    matcher = equivalent_uri('http://example.com/foo?a=&b=2')
    assert matcher.matches?(['http://example.com/foo?a=&b=2'])
  end
end