Sha256: 6766c52c6096fef2e086e5ef377cb7760b20ee0505d5a8801760a93d461cea45

Contents?: true

Size: 1.51 KB

Versions: 2

Compression:

Stored size: 1.51 KB

Contents

require 'spec_helper'

class Thing
  include Hallmonitor::Monitored
end

RSpec::Matchers.define :an_event_with_name do |expected_name|
  match{ |actual| actual.name == expected_name}
end

describe Hallmonitor::Monitored do
  subject {Thing.new}

  describe "#watch" do
    let(:retval) {"Hello World"}
    let(:name) {"foo"}
    before do
      expect(Hallmonitor::Outputter).to receive(:output).with(an_event_with_name(name))
    end
    it "should return the value the block returns" do
      value = subject.watch(name) do
        retval
      end
      expect(value).to eq(retval)
    end
  end

  describe "#emit" do
    describe "with a string parameter" do
      let(:name) {"foo"}
      before do
        expect(Hallmonitor::Outputter).to receive(:output).with(an_event_with_name(name))
      end

      it "should emit an event with the passed in name" do
        subject.emit(name)
      end
    end

    describe "with a block" do
      it "should yield to the block" do
        yielded = false
        var = nil
        subject.emit("foo") do |thing|
          var = thing
          yielded = true
        end
        expect(var).to_not be_nil
        expect(var.name).to eq("foo")
        expect(yielded).to be_truthy
      end
    end

    describe 'with an event parameter' do
      let(:event) {Hallmonitor::Event.new("bar")}
      before do
        expect(Hallmonitor::Outputter).to receive(:output).with(event)
      end

      it "should emit the passed in event" do
        subject.emit(event)
      end
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hallmonitor-0.2.0 spec/monitored_spec.rb
hallmonitor-0.1.1 spec/monitored_spec.rb