Sha256: ed4dbeb5bffde0abe8d62a8e4b18f0bee3fb514bb38b284f6e9b9b95877080cf

Contents?: true

Size: 1.32 KB

Versions: 6

Compression:

Stored size: 1.32 KB

Contents

require 'spec_helper'

RSpec.describe OmniHooks::Builder do
  describe '#provider' do
    it 'translates a symbol to a constant' do
      expect(OmniHooks::Strategies).to receive(:const_get).with('MyStrategy').and_return(Class.new)
      OmniHooks::Builder.new(nil) do
        provider :my_strategy
      end
    end

    it 'accepts a class' do
      class ExampleClass; end
      expect do
        OmniHooks::Builder.new(nil) do
          provider ::ExampleClass
        end
      end.not_to raise_error
    end

    it "raises a helpful LoadError message if it can't find the class" do
      expect do
        OmniHooks::Builder.new(nil) do
          provider :lorax
        end
      end.to raise_error(LoadError, 'Could not find matching strategy for :lorax. You may need to install an additional gem (such as omnihooks-lorax).')
    end
  end
  describe '#options' do
    it 'merges provided options in' do
      k = Class.new
      b = OmniHooks::Builder.new(nil)
      expect(b).to receive(:use).with(k, :foo => 'bar', :baz => 'tik')

      b.options :foo => 'bar'
      b.provider k, :baz => 'tik'
    end

    it 'adds an argument if no options are provided' do
      k = Class.new
      b = OmniHooks::Builder.new(nil)
      expect(b).to receive(:use).with(k, :foo => 'bar')

      b.options :foo => 'bar'
      b.provider k
    end
  end  
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
omnihooks-0.1.0 spec/omnihooks/builder_spec.rb
omnihooks-0.0.5 spec/omnihooks/builder_spec.rb
omnihooks-0.0.4 spec/omnihooks/builder_spec.rb
omnihooks-0.0.3 spec/omnihooks/builder_spec.rb
omnihooks-0.0.2 spec/omnihooks/builder_spec.rb
omnihooks-0.0.1 spec/omnihooks/builder_spec.rb