Sha256: e0ca2e1363cbbfc5f5df069c1a28ab3ab4badf28bfe376fb31b56a97e76f5de6

Contents?: true

Size: 1.76 KB

Versions: 5

Compression:

Stored size: 1.76 KB

Contents

# encoding: utf-8
require "spec_helper"

module Okei
  describe GetUnits do

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

    let!(:nmile) { create :unit, measure: "ДЛИНА" }
    let!(:mole)  { create :unit, measure: "ПРОЧИЕ" }

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

    let(:listener) { double "listener" }

    def prepare_case(params = {})
      use_case = GetUnits.new params
      use_case.subscribe(listener)
      use_case
    end

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

    describe "#run" do

      context "without params" do

        subject(:use_case) { prepare_case }

        it "returns all units" do
          expect(use_case.run.to_a).to eq Unit.all.order(:code).to_a
        end

        it "sends 'success' to subscribers" do
          expect(listener).to receive(:success) do |units|
            expect(units.to_a).to eq Unit.all.order(:code).to_a
          end
          use_case.run
        end
      end

      context "with some measure" do

        subject(:use_case) { prepare_case "measure" => "ДЛИНА" }

        it "returns matched units" do
          expect(use_case.run.to_a).to eq [nmile]
        end

        it "sends 'success' to subscribers" do
          expect(listener).to receive(:success) do |units|
            expect(units.to_a).to eq [nmile]
          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_units_spec.rb
okei-1.0.1 spec/use_cases/okei/get_units_spec.rb
okei-1.0.0 spec/use_cases/okei/get_units_spec.rb
okei-1.0.0.pre.rc spec/use_cases/okei/get_units_spec.rb
okei-0.0.2 spec/use_cases/okei/get_units_spec.rb