Sha256: 3d933c2ed04bfd60a9cf715cfd4dcc2286d26d094d0f8853a72d7a7a371e5359

Contents?: true

Size: 1.62 KB

Versions: 5

Compression:

Stored size: 1.62 KB

Contents

# encoding: utf-8
require "spec_helper"

module Okei
  describe GetUnit do

    # ==========================================================================
    # Prepare context
    # ==========================================================================

    let!(:unit) { create :unit }

    # ==========================================================================
    # Prepare variables
    # ==========================================================================

    let!(:params)  { { uuid: unit.uuid } }
    let(:listener) { double "listener" }

    def prepare_case(params)
      use_case = GetUnit.new params
      use_case.subscribe(listener)
      use_case
    end

    # ==========================================================================
    # Run tests
    # ==========================================================================

    describe "#run" do

      context "with proper uuid" do

        subject(:use_case) { prepare_case params }

        it "returns unit" do
          expect(use_case.run).to eq unit
        end

        it "sends 'found' to subscribers" do
          expect(listener).to receive(:found).with(unit)
          use_case.run
        end
      end

      context "with wrong uuid" do

        before { params[:uuid] = "wrong" }
        subject(:use_case) { prepare_case params }

        it "returns nil" do
          expect(use_case.run).to be_nil
        end

        it "sends 'not_found' to subscribers" do
          expect(listener).to receive :not_found do |messages|
            expect(messages).not_to be_blank
          end
          use_case.run
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
okei-1.0.2 spec/use_cases/okei/get_unit_spec.rb
okei-1.0.1 spec/use_cases/okei/get_unit_spec.rb
okei-1.0.0 spec/use_cases/okei/get_unit_spec.rb
okei-1.0.0.pre.rc spec/use_cases/okei/get_unit_spec.rb
okei-0.0.2 spec/use_cases/okei/get_unit_spec.rb