Sha256: 2a861f5ae60617019e97ee51b0ef59ab64e8ad2b452558b44bab4f509f80a21c

Contents?: true

Size: 1.65 KB

Versions: 3

Compression:

Stored size: 1.65 KB

Contents

require 'spec_helper'

describe Linodians::Employee do
  let(:employee) do
    VCR.use_cassette('new_data') { Linodians::Group.new.lookup('marques') }
  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 'displague'
    end

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

    it 'supports symbols as keys' do
      expect(employee[:twitter]).to eql 'displague'
    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 'displague'
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
linodians-1.1.1 spec/linodians/employee_spec.rb
linodians-1.1.0 spec/linodians/employee_spec.rb
linodians-1.0.1 spec/linodians/employee_spec.rb