Sha256: 1f526cc6e64f9876bcfa890791298a00d8dc1ed5e9b8aa21b3c3cd62367e601f

Contents?: true

Size: 1.37 KB

Versions: 2

Compression:

Stored size: 1.37 KB

Contents

require 'spec_helper'

module ChefAPI
  describe Resource::Base do
    before do
      # Unset all instance variables (which are actually cached on the parent
      # class) to prevent caching.
      described_class.instance_variables.each do |instance_variable|
        described_class.send(:remove_instance_variable, instance_variable)
      end
    end

    describe '.schema' do
      it 'sets the schema for the class' do
        block = Proc.new {}
        described_class.schema(&block)
        expect(described_class.schema).to be_a(Schema)
      end
    end

    describe '.collection_path' do
      it 'raises an exception if the collection name is not set' do
        expect { described_class.collection_path }.to raise_error
      end

      it 'sets the collection name' do
        described_class.collection_path('bacons')
        expect(described_class.collection_path).to eq('bacons')
      end

      it 'converts the symbol to a string' do
        described_class.collection_path(:bacons)
        expect(described_class.collection_path).to eq('bacons')
      end
    end

    describe '.build' do
      it 'creates a new instance' do
        described_class.stub(:new)
        described_class.stub(:schema).and_return(double(attributes: {}))

        expect(described_class).to receive(:new).with({foo: 'bar'}, {})
        described_class.build(foo: 'bar')
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
chef-api-0.2.1 spec/unit/resources/base_spec.rb
chef-api-0.2.0 spec/unit/resources/base_spec.rb