# 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