Sha256: 4b3b3d4ba5777bc772df6eb5b667d0924684cad18fd96dfcb05b824a7b6c8bfd

Contents?: true

Size: 1.38 KB

Versions: 2

Compression:

Stored size: 1.38 KB

Contents

require 'spec_helper'

describe Hipbot::ReactionFactory do
  subject { described_class.new(double) }

  let(:params) { [] }
  let(:block) { double }

  let(:options_stack) { [subject.get_reaction_options(params)] }
  let(:reaction) { subject.build(options_stack, block) }

  describe "taking a regexp" do
    let(:params) { [/.*/] }

    it "builds a reaction with regexp" do
      expect(reaction.regexps).to eq([/.*/i])
    end

    describe "with additional options" do
      let(:params) { [/.*/, { from: 'wat' }] }

      it "builds a reaction with proper options" do
        expect(reaction.options).to eq(from: 'wat', regexps: [/.*/], desc: nil)
      end
    end
  end

  describe "taking multiple regexps and options" do
    let(:params) { [/.*/, /wat/, { from: 'wat' }] }

    it "builds a reaction with proper options" do
      expect(reaction.options).to eq(from: 'wat', regexps: [/.*/, /wat/], desc: nil)
    end
  end

  describe "setting description" do
    before do
      subject.description('woot')
    end

    it "builds reaction with proper description" do
      expect(reaction.desc).to eq('woot')
    end

    it "resets description after first built reaction" do
      subject.build(params, block)
      expect(reaction.desc).to be_nil
    end
  end

  it "applies optional scope params as default" do
    expect(subject.build([{ from: 'dave' }], block).options[:from]).to eq('dave')
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hipbot-1.0.4 spec/unit/reaction_factory_spec.rb
hipbot-1.0.3 spec/unit/reaction_factory_spec.rb