require 'spec_helper' require 'securerandom' describe Vinz::Url do describe '#pack / #unpack' do let(:key) { SecureRandom.hex(128) } let(:crypto) { Vinz::Crypto.new(key) } let(:url) { 'http://localhost/foo' } let(:uri) { URI.parse(url) } it 'packs and unpacks the message' do message = {foo: 'bar'} packer = Vinz::Url.new(uri, crypto) packed = packer.pack(message) unpacker = Vinz::Url.new(packed, crypto) payload = unpacker.unpack expect(payload).to eq(message) end context 'when base64 is invalid' do it 'raises an error' do unpacker = Vinz::Url.new("#{url}?_creq=foobar", crypto) expect { unpacker.unpack }.to raise_error(Vinz::Error) end end end end