Sha256: 01673000e7eb9dc3a38e4be11995063cf9cdfefc78743778c2e58059c04db6b4

Contents?: true

Size: 1.74 KB

Versions: 45

Compression:

Stored size: 1.74 KB

Contents

require File.expand_path('../../test_helper', __FILE__)

class ValueMatchersTest < ActionController::TestCase

  def test_matches_value_any
    assert(matches_value?(:any, 'a'))
    assert(matches_value?(:any, nil))
  end

  def test_matches_value_not_nil
    assert(matches_value?(:not_nil, 'a'))
    refute(matches_value?(:not_nil, nil))
  end

  def test_matches_value_array
    assert(matches_value?(['a', 'b', 'c'], ['b', 'c', 'a']))
    assert(matches_value?(['a', 'b', 'c'], ['a', 'b', 'c']))
    refute(matches_value?(['a', 'b', 'c'], ['a', 'a']))
    refute(matches_value?(['a', 'b', 'c'], ['a', 'b', 'd']))

    assert(matches_value?(['a', 'b', :any], ['a', 'b', 'c']))
    assert(matches_value?(['a', 'b', :not_nil], ['a', 'b', 'c']))
    refute(matches_value?(['a', 'b', :not_nil], ['a', 'b', nil]))
  end

  def test_matches_value_hash
    assert(matches_value?({a: 'a', b: 'b', c: 'c'}, {a: 'a', b: 'b', c: 'c'}))
    assert(matches_value?({a: 'a', b: 'b', c: 'c'}, {b: 'b', c: 'c', a: 'a'}))
    refute(matches_value?({a: 'a', b: 'b', c: 'c'}, {b: 'a', c: 'c', a: 'b'}))

    assert(matches_value?({a: 'a', b: 'b', c: {a: 'a', d: 'e'}}, {b: 'b', c: {a: 'a', d: 'e'}, a: 'a'}))
    refute(matches_value?({a: 'a', b: 'b', c: {a: 'a', d: 'd'}}, {b: 'b', c: {a: 'a', d: 'e'}, a: 'a'}))

    assert(matches_value?({a: 'a', b: 'b', c: {a: 'a', d: {a: :not_nil}}}, {b: 'b', c: {a: 'a', d: {a: 'b'}}, a: 'a'}))
    refute(matches_value?({a: 'a', b: 'b', c: {a: 'a', d: {a: :not_nil}}}, {b: 'b', c: {a: 'a', d: {a: nil}}, a: 'a'}))

    assert(matches_value?({a: 'a', b: 'b', c: {a: 'a', d: {a: :any}}}, {b: 'b', c: {a: 'a', d: {a: 'b'}}, a: 'a'}))
    assert(matches_value?({a: 'a', b: 'b', c: {a: 'a', d: {a: :any}}}, {b: 'b', c: {a: 'a', d: {a: nil}}, a: 'a'}))
  end
end

Version data entries

45 entries across 45 versions & 1 rubygems

Version Path
jsonapi-resources-0.3.3 test/helpers/value_matchers_test.rb
jsonapi-resources-0.3.2 test/helpers/value_matchers_test.rb
jsonapi-resources-0.3.1 test/helpers/value_matchers_test.rb
jsonapi-resources-0.3.0 test/helpers/value_matchers_test.rb
jsonapi-resources-0.3.0.pre2 test/helpers/value_matchers_test.rb
jsonapi-resources-0.3.0.pre1 test/helpers/value_matchers_test.rb
jsonapi-resources-0.2.0 test/helpers/value_matchers_test.rb
jsonapi-resources-0.1.1 test/helpers/value_matchers_test.rb
jsonapi-resources-0.1.0 test/helpers/value_matchers_test.rb
jsonapi-resources-0.0.16 test/helpers/value_matchers_test.rb
jsonapi-resources-0.0.15 test/helpers/value_matchers_test.rb
jsonapi-resources-0.0.14 test/helpers/value_matchers_test.rb
jsonapi-resources-0.0.13 test/helpers/value_matchers_test.rb
jsonapi-resources-0.0.12 test/helpers/value_matchers_test.rb
jsonapi-resources-0.0.11 test/helpers/value_matchers_test.rb
jsonapi-resources-0.0.10 test/helpers/value_matchers_test.rb
jsonapi-resources-0.0.9 test/helpers/value_matchers_test.rb
jsonapi-resources-0.0.8 test/helpers/value_matchers_test.rb
jsonapi-resources-0.0.7 test/helpers/value_matchers_test.rb
jsonapi-resources-0.0.6 test/helpers/value_matchers_test.rb