Sha256: 7450140675ec9550c2d291926228d7a4873f6431edebabf1dbc294f204a40186

Contents?: true

Size: 1.5 KB

Versions: 66

Compression:

Stored size: 1.5 KB

Contents

require 'curation_concerns/callbacks/registry'

describe CurationConcerns::Callbacks::Registry do
  subject { described_class.new }

  describe "#enabled?" do
    it "returns false if the specified callback has not been enabled" do
      expect(subject.enabled?(:foo))
    end

    it "returns true after enabling the specified callback" do
      subject.enable(:foo)
      expect(subject.enabled?(:foo)).to eq true
    end
  end

  describe "#set?" do
    it "returns false if the callback has not been set" do
      expect(subject.set?(:foo)).to eq false
    end

    it "returns true if the callback has been set" do
      subject.set(:foo) { nil }
      expect(subject.set?(:foo)).to eq true
    end
  end

  describe "#set" do
    it "raises an error if a block is not given" do
      expect { subject.set(:foo) }.to raise_error CurationConcerns::Callbacks::NoBlockGiven
    end

    it "raises an error if given no arguments" do
      expect { subject.set }.to raise_error ArgumentError
    end
  end

  describe "#run" do
    it "raises a NotEnabled error if the callback has not been enabled" do
      expect { subject.run(:foo) }.to raise_error CurationConcerns::Callbacks::NotEnabled
    end

    it "runs the specified callback with parameters" do
      subject.set(:foo) { |x, y| x + y }
      expect(subject.run(:foo, 1, 2)).to eq 3
    end

    it "runs the most recently set callback" do
      subject.set(:foo) { "first" }
      subject.set(:foo) { "second" }
      expect(subject.run(:foo)).to eq "second"
    end
  end
end

Version data entries

66 entries across 66 versions & 1 rubygems

Version Path
curation_concerns-1.7.8 spec/lib/curation_concerns/callbacks/registry_spec.rb
curation_concerns-1.7.7 spec/lib/curation_concerns/callbacks/registry_spec.rb
curation_concerns-2.0.0 spec/lib/curation_concerns/callbacks/registry_spec.rb
curation_concerns-2.0.0.rc2 spec/lib/curation_concerns/callbacks/registry_spec.rb
curation_concerns-1.7.6 spec/lib/curation_concerns/callbacks/registry_spec.rb
curation_concerns-1.7.5 spec/lib/curation_concerns/callbacks/registry_spec.rb
curation_concerns-1.7.4 spec/lib/curation_concerns/callbacks/registry_spec.rb
curation_concerns-1.7.3 spec/lib/curation_concerns/callbacks/registry_spec.rb
curation_concerns-1.7.2 spec/lib/curation_concerns/callbacks/registry_spec.rb
curation_concerns-2.0.0.rc1 spec/lib/curation_concerns/callbacks/registry_spec.rb
curation_concerns-1.7.1 spec/lib/curation_concerns/callbacks/registry_spec.rb
curation_concerns-1.7.0 spec/lib/curation_concerns/callbacks/registry_spec.rb
curation_concerns-1.7.0.beta1 spec/lib/curation_concerns/callbacks/registry_spec.rb
curation_concerns-1.6.3 spec/lib/curation_concerns/callbacks/registry_spec.rb
curation_concerns-1.6.2 spec/lib/curation_concerns/callbacks/registry_spec.rb
curation_concerns-1.6.1 spec/lib/curation_concerns/callbacks/registry_spec.rb
curation_concerns-1.6.0 spec/lib/curation_concerns/callbacks/registry_spec.rb
curation_concerns-1.5.0 spec/lib/curation_concerns/callbacks/registry_spec.rb
curation_concerns-1.4.0 spec/lib/curation_concerns/callbacks/registry_spec.rb
curation_concerns-1.3.3 spec/lib/curation_concerns/callbacks/registry_spec.rb