Sha256: 6d416e1ae53900c7eb0430737dd3ae0b3366e556d9703beffcd5cc895fdb794d

Contents?: true

Size: 1.87 KB

Versions: 5

Compression:

Stored size: 1.87 KB

Contents

require 'rest_in_peace'

describe RESTinPeace do

  let(:struct) { Struct.new(:name) }
  let(:extended_class) do
    Class.new(struct) do
      include RESTinPeace
    end
  end
  let(:attributes) { { name: 'test' } }
  let(:instance) { extended_class.new(attributes) }

  describe '::api' do
    subject { extended_class }
    specify { expect(subject).to respond_to(:api).with(0).arguments }
  end

  describe '::rest_in_peace' do
    subject { extended_class }
    specify { expect(subject).to respond_to(:rest_in_peace).with(0).arguments }
    let(:definition_proxy) { object_double(RESTinPeace::DefinitionProxy) }


    it 'evaluates the given block inside the definition proxy' do
      allow(RESTinPeace::DefinitionProxy).to receive(:new).with(subject).and_return(definition_proxy)
      expect(definition_proxy).to receive(:instance_eval) do |&block|
        expect(block).to be_instance_of(Proc)
      end
      subject.rest_in_peace { }
    end
  end

  describe '::rip_registry' do
    subject { extended_class }
    specify { expect(extended_class).to respond_to(:rip_registry) }
    specify { expect(extended_class.rip_registry).to eq(collection: [], resource: []) }
  end

  describe '#api' do
    subject { instance }
    specify { expect(subject).to respond_to(:api).with(0).arguments }
  end

  describe '#to_h' do
    subject { instance }
    specify { expect(subject).to respond_to(:to_h).with(0).arguments }
  end

  describe '#initialize' do
    subject { instance }
    specify { expect(subject.name).to eq('test') }

    context 'unknown params' do
      let(:attributes) { { name: 'test42', email: 'yolo@example.org' } }
      specify { expect(subject.name).to eq('test42') }
      specify { expect { subject.email }.to raise_error(NoMethodError) }
    end

    context 'not given param' do
      let(:attributes) { {} }
      specify { expect(subject.name).to eq(nil) }
    end
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rest-in-peace-1.3.1 spec/rest_in_peace_spec.rb
rest-in-peace-1.3.0 spec/rest_in_peace_spec.rb
rest-in-peace-1.2.1 spec/rest_in_peace_spec.rb
rest-in-peace-1.2.0 spec/rest_in_peace_spec.rb
rest-in-peace-1.1.1 spec/rest_in_peace_spec.rb