Sha256: 29c4a44434a375fa84e3f37d07bbb2e54c8692f9236a40a6fda0f8ad6278373c

Contents?: true

Size: 1.74 KB

Versions: 31

Compression:

Stored size: 1.74 KB

Contents

# frozen_string_literal: true

require 'test_helper'

module Vedeu

  module Events

    describe Trigger do

      let(:described)  { Vedeu::Events::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
        it { instance.must_be_instance_of(described) }
        it { instance.instance_variable_get('@name').must_equal(event_name) }
        it { instance.instance_variable_get('@args').must_equal([args]) }
        it do
          instance.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 {
            Vedeu::Events::Event.register(event_name) { :_result_one_ }
            Vedeu::Events::Event.register(event_name) { :_result_two_ }
          }

          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 # Events

end # Vedeu

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
vedeu-0.8.32 test/lib/vedeu/events/trigger_test.rb
vedeu-0.8.31 test/lib/vedeu/events/trigger_test.rb
vedeu-0.8.30 test/lib/vedeu/events/trigger_test.rb
vedeu-0.8.29 test/lib/vedeu/events/trigger_test.rb
vedeu-0.8.28 test/lib/vedeu/events/trigger_test.rb
vedeu-0.8.27 test/lib/vedeu/events/trigger_test.rb
vedeu-0.8.26 test/lib/vedeu/events/trigger_test.rb
vedeu-0.8.25 test/lib/vedeu/events/trigger_test.rb
vedeu-0.8.24 test/lib/vedeu/events/trigger_test.rb
vedeu-0.8.23 test/lib/vedeu/events/trigger_test.rb
vedeu-0.8.22 test/lib/vedeu/events/trigger_test.rb
vedeu-0.8.21 test/lib/vedeu/events/trigger_test.rb
vedeu-0.8.20 test/lib/vedeu/events/trigger_test.rb
vedeu-0.8.19 test/lib/vedeu/events/trigger_test.rb
vedeu-0.8.18 test/lib/vedeu/events/trigger_test.rb
vedeu-0.8.17 test/lib/vedeu/events/trigger_test.rb
vedeu-0.8.16 test/lib/vedeu/events/trigger_test.rb
vedeu-0.8.15 test/lib/vedeu/events/trigger_test.rb
vedeu-0.8.14 test/lib/vedeu/events/trigger_test.rb
vedeu-0.8.13 test/lib/vedeu/events/trigger_test.rb