<commit_before>describe Bumbleworks do
  describe ".configure" do
    it 'yields the current configuration' do
      described_class.configure do |c|
        expect(c).to equal(described_class.configuration)
      end
    end
  end

  describe '.storage' do
    it 'can set directly' do
      storage = double("Storage")
      Bumbleworks.storage = storage
      Bumbleworks.storage.should == storage
      Bumbleworks.configuration.storage.should == storage
    end

    it 'can set with a block' do
      storage = double("Storage")
      Bumbleworks.configure {|c| c.storage = storage }
      Bumbleworks.storage.should == storage
      Bumbleworks.configuration.storage.should == storage
    end
  end

  describe '.register_participants' do
    it 'registers a block' do
      participant_block = lambda {}
      Bumbleworks.register_participants &participant_block
      Bumbleworks.participant_block.should == participant_block
    end
  end

  describe '.start!' do
    before :each do
      Bumbleworks.stub(:load_participants)
      Bumbleworks.stub(:load_process_definitions)
    end

    it 'loads and registers the participants' do
      participant_block = Proc.new do
      end

      Bumbleworks.storage = {}
      Bumbleworks.register_participants &participant_block
      Bumbleworks.engine.should_receive(:register).with(&participant_block)
      Bumbleworks.start!
    end

    it 'calls participant block to register them' do
      participant_block = Proc.new do
        catchall
      end

      Bumbleworks.storage = {}
      Bumbleworks.register_participants &participant_block
      Bumbleworks.engine.should_receive(:register).and_call_original
      Bumbleworks.start!
      Bumbleworks.engine.participant_list.first.should be_an_instance_of(Ruote::ParticipantEntry)

    it 'registers process definitions with engine' do
      described_class.storage = {}
      described_class.should_receive(:registered_process_definitions).and_return({'compile' => 'some definition'})
      described_class.start!
      described_class.engine.variables['compile'].should == 'some definition'
    end
  end

  describe '.engine' do
    before :each do
      Bumbleworks.reset!
    end

    it 'raises an error if no storage is defined' do
      Bumbleworks.storage = nil
      expect{Bumbleworks.engine}.to raise_error Bumbleworks::UndefinedSetting
    end

    it 'creates a new engine' do
      Bumbleworks.storage = {}
      Bumbleworks.engine.should be_an_instance_of(Ruote::Dashboard)
    end
  end

  describe '.define_process' do
    it 'delegates to ProcessDefinitions' do
      block = Proc.new {}
      Bumbleworks::ProcessDefinition.should_receive(:define_process).with('name', {}, &block)
      described_class.define_process('name', {}, &block)
    end


    it 'should raise an error when duplicate process names are detected' do
      described_class.define_process('foot-traffic') do
      end

      expect do<commit_msg>Refactor name (Bumbleworks => described_class) <commit_after>describe Bumbleworks do
  describe ".configure" do
    it 'yields the current configuration' do
      described_class.configure do |c|
        expect(c).to equal(described_class.configuration)
      end
    end
  end

  describe '.storage' do
    it 'can set directly' do
      storage = double("Storage")
      Bumbleworks.storage = storage
      Bumbleworks.storage.should == storage
      Bumbleworks.configuration.storage.should == storage
    end

    it 'can set with a block' do
      storage = double("Storage")
      Bumbleworks.configure {|c| c.storage = storage }
      Bumbleworks.storage.should == storage
      Bumbleworks.configuration.storage.should == storage
    end
  end

  describe '.register_participants' do
    it 'registers a block' do
      participant_block = lambda {}
      Bumbleworks.register_participants &participant_block
      Bumbleworks.participant_block.should == participant_block
    end
  end

  describe '.start!' do
    before :each do
      described_class.stub(:load_participants)
      described_class.stub(:load_process_definitions)
    end

    it 'loads and registers the participants' do
      participant_block = Proc.new do
      end

      described_class.storage = {}
      described_class.register_participants &participant_block
      described_class.engine.should_receive(:register).with(&participant_block)
      described_class.start!
    end

    it 'calls participant block to register them' do
      participant_block = Proc.new do
        catchall
      end

      described_class.storage = {}
      described_class.register_participants &participant_block
      described_class.engine.should_receive(:register).and_call_original
      described_class.start!
      described_class.engine.participant_list.first.should be_an_instance_of(Ruote::ParticipantEntry)
    end

    it 'registers process definitions with engine' do
      described_class.storage = {}
      described_class.should_receive(:registered_process_definitions).and_return({'compile' => 'some definition'})
      described_class.start!
      described_class.engine.variables['compile'].should == 'some definition'
    end
  end

  describe '.engine' do
    before :each do
      described_class.reset!
    end

    it 'raises an error if no storage is defined' do
      described_class.storage = nil
      expect{described_class.engine}.to raise_error Bumbleworks::UndefinedSetting
    end

    it 'creates a new engine' do
      described_class.storage = {}
      described_class.engine.should be_an_instance_of(Ruote::Dashboard)
    end
  end

  describe '.define_process' do
    it 'delegates to ProcessDefinitions' do
      block = Proc.new {}
      Bumbleworks::ProcessDefinition.should_receive(:define_process).with('name', {}, &block)
      described_class.define_process('name', {}, &block)
    end


    it 'should raise an error when duplicate process names are detected' do
      described_class.define_process('foot-traffic') do
      end

      expect do
{'fraction_non_alphanumeric': 0.0805324459234609, 'fraction_numerical': 0.0, 'mean_word_length': 3.242060691601976, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3685242', 'n_tokens_mistral': 1714, 'n_tokens_neox': 1646, 'n_words': 408}