Sha256: 1ed6487877bfa5cd78a296b09c976a6e1bdaa76ef9f3ea2b85b91e67e946bdd3

Contents?: true

Size: 1.04 KB

Versions: 4

Compression:

Stored size: 1.04 KB

Contents

# encoding: utf-8

require 'spec_helper'

describe Dispatcher::Action, '.coerce' do

  subject { described_class.coerce(config) }

  let(:action)  { Spec::Action::Success }
  let(:coerced) { Dispatcher::Action.new(action, observer) }

  context "when coercion is possible" do

    let(:config) {{
        :action   => action,
        :observer => observer_value
    }}

    before do
      Observer.should_receive(:coerce).with(observer_value).and_return(observer)
      Utils.should_receive(:coerce_callable).with(action).and_return(action)
    end

    context 'with an action and an observer' do
      let(:observer_value) { observer }
      let(:observer)       { Spec::Observer }

      it { should eql(coerced) }
    end

    context 'with an action and no observer' do
      let(:observer_value) { nil }
      let(:observer)       { Observer::NULL }

      it { should eql(coerced) }
    end
  end

  context 'with no action' do
    let(:config) { {} }

    specify {
      expect { subject }.to raise_error(described_class::MissingHandlerError)
    }
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
substation-0.0.4 spec/unit/substation/dispatcher/action/class_methods/coerce_spec.rb
substation-0.0.3 spec/unit/substation/dispatcher/action/class_methods/coerce_spec.rb
substation-0.0.2 spec/unit/substation/dispatcher/action/class_methods/coerce_spec.rb
substation-0.0.1 spec/unit/substation/dispatcher/action/class_methods/coerce_spec.rb