Sha256: dbb78478fcc2af6b84dda8cacd372d0eb18926644af579b8c845eda4a5bdc504

Contents?: true

Size: 1.99 KB

Versions: 7

Compression:

Stored size: 1.99 KB

Contents

require 'rspec'
require 'hyperion_test/kim'
require 'hyperion_test/kim/matchers'

describe Hyperion::Kim::Matchers do
  include Hyperion::Kim::Matchers
  describe '#res' do
    it 'matches resource paths' do
      m = res('/people/:name/birthplace/:city')
      r = m.call(req(path: '/people/kim/birthplace/la'))
      expect(r.params.name).to eql 'kim'
      expect(r.params.city).to eql 'la'
      expect(m.call(req(path: '/people/kim/home/la'))).to be_falsey
    end
  end
  describe '#verb' do
    it 'matches the HTTP verb' do
      expect(verb('GET').call(req(verb: 'GET'))).to be_truthy
      expect(verb('PUT').call(req(verb: 'put'))).to be_truthy
      expect(verb(:post).call(req(verb: 'POST'))).to be_truthy
      expect(verb('GET').call(req(verb: 'PUT'))).to be_falsey
    end
  end
  describe '#req_headers' do
    it 'matches headers' do
      m = req_headers('Allow' => 'application/json')
      expect(m.call(req(headers: {'Allow' => 'application/json'}))).to be_truthy
      expect(m.call(req(headers: {'Allow' => 'text/html'}))).to be_falsey
      expect(m.call(req(headers: {}))).to be_falsey
    end
    it 'only checks for presence if value is nil' do
      m = req_headers('Allow' => nil)
      expect(m.call(req(headers: {'Allow' => 'application/json'}))).to be_truthy
      expect(m.call(req(headers: {'Allow' => 'text/html'}))).to be_truthy
      expect(m.call(req(headers: {}))).to be_falsey
    end
  end
  describe '#req_params' do
    it 'matches params' do
      m = req_params(a: 1, 'b' => 2)
      expect(m.call(req(params: params(a: 1, b: 2)))).to be_truthy
    end
    it 'only checks for presence if value is nil' do
      m = req_params(c: nil)
      expect(m.call(req(params: params(c: 1)))).to be_truthy
      expect(m.call(req(params: params(c: 2)))).to be_truthy
      expect(m.call(req(params: params(z: 2)))).to be_falsey
    end
  end

  def req(attrs)
    Hyperion::Kim::Request.new(*attrs.values_at(*Hyperion::Kim::Request.members))
  end

  def params(*args)
    OpenStruct.new(*args)
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
hyperion_http-0.6.0 spec/lib/hyperion_test/kim/matchers_spec.rb
hyperion_http-0.5.0 spec/lib/hyperion_test/kim/matchers_spec.rb
hyperion_http-0.3.0 spec/lib/hyperion_test/kim/matchers_spec.rb
hyperion_http-0.2.4 spec/lib/hyperion_test/kim/matchers_spec.rb
hyperion_http-0.2.3 spec/lib/hyperion_test/kim/matchers_spec.rb
hyperion_http-0.2.2 spec/lib/hyperion_test/kim/matchers_spec.rb
hyperion_http-0.2.1 spec/lib/hyperion_test/kim/matchers_spec.rb