Sha256: a7fcc5a9c2fb654f734b65760e5ae3b2b402a0063f57d9e19529e9a9b5872e9e

Contents?: true

Size: 1.64 KB

Versions: 1

Compression:

Stored size: 1.64 KB

Contents

require 'spec_helper'

describe Linodians::Employee do
  let(:employee) do
    VCR.use_cassette('new_data') { Linodians::Group.new.lookup('rohara') }
  end

  describe '#photo' do
    let(:photo) { VCR.use_cassette('photo') { employee.photo } }

    it 'returns a string' do
      expect(photo).to be_an_instance_of String
    end

    it 'is a PNG' do
      expect(photo).to match "\x89PNG".force_encoding('binary')
    end
  end

  describe '#[]' do
    it 'accesses the employee info' do
      expect(employee[:twitter]).to eql 'sirrohara'
    end

    it 'supports strings as keys' do
      expect(employee['twitter']).to eql 'sirrohara'
    end

    it 'supports symbols as keys' do
      expect(employee[:twitter]).to eql 'sirrohara'
    end

    it 'returns nil if the key does not exist' do
      expect(employee[:other]).to be_nil
    end
  end

  describe '#to_json' do
    it 'returns data as json' do
      expect(JSON.parse(employee.to_json)).to be_an_instance_of Hash
    end
  end

  describe '#respond_to?' do
    it 'truthfully responds for proxied methods' do
      expect(employee.respond_to? :twitter).to be_truthy
    end

    it 'returns false for methods that it cannot handle' do
      expect(employee.respond_to? :other).to be_falsey
    end
  end

  describe '#to_h' do
    it 'returns a hash' do
      expect(employee.to_h).to be_an_instance_of Hash
    end

    it 'dups to allow modification' do
      copy = employee.to_h
      copy[:new_key] = :data
      expect(copy[:new_key]).to eql :data
      expect(employee[:new_key]).to be_nil
    end
  end

  it 'proxies methods as data hash keys' do
    expect(employee.twitter).to eql 'sirrohara'
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
linodians-1.0.0 spec/linodians/employee_spec.rb