Sha256: 5cea9d78e96f8dda9c8faa347552087a4c965e18bc4fa1ff558b40b2888a6f99

Contents?: true

Size: 1.61 KB

Versions: 4

Compression:

Stored size: 1.61 KB

Contents

require 'test_helper'

module Vedeu

  describe Trigger do

    let(:described)  { Vedeu::Trigger }
    let(:instance)   { described.new(event_name, args) }
    let(:event_name) { :_testing_event_ }
    let(:args)       {}

    describe '.trigger' do
      before { Vedeu.bind(event_name) { :_only_one_result_ } }

      subject { described.trigger(event_name) }

      it { subject.must_equal(:_only_one_result_) }
    end

    describe '#initialize' do
      subject { instance }

      it { subject.must_be_instance_of(Vedeu::Trigger) }
      it { subject.instance_variable_get('@name').must_equal(event_name) }
      it { subject.instance_variable_get('@args').must_equal([args]) }
      it do
        subject.instance_variable_get('@repository').must_equal(Vedeu.events)
      end
    end

    describe '#trigger' do
      subject { instance.trigger }

      context 'when only one result occurs from triggering the event' do
        let(:event_name) { :_one_result_ }

        before { Vedeu.bind(event_name) { :_only_one_result_ } }

        it { subject.must_equal(:_only_one_result_) }
      end

      context 'when multiple results occur from triggering an event' do
        let(:event_name) { :_multiple_results_ }

        before do
          Vedeu::Event.register(event_name) { :_result_one_ }
          Vedeu::Event.register(event_name) { :_result_two_ }
        end

        it { subject.must_equal([:_result_one_, :_result_two_]) }
      end

      context 'when the event has not been registered' do
        let(:event_name) { :_not_found_ }

        it { subject.must_equal([]) }
      end
    end

  end # Trigger

end # Vedeu

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
vedeu-0.4.17 test/lib/vedeu/events/trigger_test.rb
vedeu-0.4.16 test/lib/vedeu/events/trigger_test.rb
vedeu-0.4.15 test/lib/vedeu/events/trigger_test.rb
vedeu-0.4.14 test/lib/vedeu/events/trigger_test.rb