Sha256: e8e68de4e9badf93473f20946c6fdb20592894d73d68d7b21da34a354d14396e

Contents?: true

Size: 1.58 KB

Versions: 14

Compression:

Stored size: 1.58 KB

Contents

require 'spec_helper'
require "bootic_client/whiny_uri"

describe BooticClient::WhinyURI do
  describe '#expand' do
    let(:uri) {
      described_class.new('http://www.host.com/shops/{id}/{?foo}')
    }

    it 'complains if missing a path segment' do
      expect{
        uri.expand(foo: 1)
      }.to raise_error BooticClient::InvalidURLError
    end

    it 'understand different path segment syntax' do
      uri = described_class.new('http://www.host.com/shops{/id}/{?foo}')
      expect{
        uri.expand(foo: 1)
      }.to raise_error BooticClient::InvalidURLError
    end

    it 'expands if all path variables provided' do
      expect(uri.expand(id: 123))
        .to eql 'http://www.host.com/shops/123/'
    end

    it 'complains if passing undeclared params' do
      expect{
        uri.expand(id: 123, nope: 'nope')
      }.to raise_error BooticClient::InvalidURLError
    end

    it 'understand variable lists in query' do
      uri = described_class.new('http://www.host.com/shops{/id}/{?foo,bar}')
      expect{
        uri.expand(id: 123, foo: 'foo', bar: 'bar', nope: 'nope')
      }.to raise_error BooticClient::InvalidURLError
    end

    it 'expands if passing declared query variables' do
      expect(uri.expand(id: 123, foo: 'yes'))
        .to eql 'http://www.host.com/shops/123/?foo=yes'
    end

    it 'expands if passing declared query variables defined as list' do
      uri = described_class.new('http://www.host.com/shops{/id}/{?foo,bar}')
      expect(uri.expand(id: 123, foo: 'yes', bar: 'no'))
        .to eql 'http://www.host.com/shops/123/?foo=yes&bar=no'
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
bootic_client-0.0.32 spec/whiny_uri_spec.rb
bootic_client-0.0.31 spec/whiny_uri_spec.rb
bootic_client-0.0.30 spec/whiny_uri_spec.rb
bootic_client-0.0.29 spec/whiny_uri_spec.rb
bootic_client-0.0.28 spec/whiny_uri_spec.rb
bootic_client-0.0.27 spec/whiny_uri_spec.rb
bootic_client-0.0.26 spec/whiny_uri_spec.rb
bootic_client-0.0.25 spec/whiny_uri_spec.rb
bootic_client-0.0.24 spec/whiny_uri_spec.rb
bootic_client-0.0.23 spec/whiny_uri_spec.rb
bootic_client-0.0.22 spec/whiny_uri_spec.rb
bootic_client-0.0.21 spec/whiny_uri_spec.rb
bootic_client-0.0.20 spec/whiny_uri_spec.rb
bootic_client-0.0.19 spec/whiny_uri_spec.rb