<commit_before>require "spec_helper"

describe Nark::Plugin::Event do
  describe "#type" do
    it "stores the trigger type" do
      event = Nark::Plugin::Event.new :type => :before_call
      event.type.should eql :before_call
    end

    it "can be a string" do
      event = Nark::Plugin::Event.new :type => 'before_call'
      event.type.should eql 'before_call'
    end
  end

  describe "#method_block" do
    it "stores a block" do
      plugin_method_block = Proc.new {|p| p }
      params = {
        :type => 'before_call',
        :method_block => plugin_method_block
      }
      event = Nark::Plugin::Event.new params
      event.method_block.should eql plugin_method_block
    end

    it "throws an exception if a block is not passed"
  end

  describe "#plugin" do
    it "stores the plugin's name" do
      params = {
        :plugin => :some_plugin,
      }
      event = Nark::Plugin::Event.new params
      event.plugin.should eql :some_plugin
    end
  end

  describe "#to_hash" do
    it "returns the attributes as a Hash" do
      plugin_method_block = Proc.new {|p| p }
      params = {
        :plugin => :some_plugin,
        :type => 'before_call',
        :method_block => plugin_method_block
      }
      event = Nark::Plugin::Event.new params
      event.to_hash.should eql params
    end
  end

  describe "#exists?" do
    let(:plugin_method_block) { Proc.new {|p| p } }
    let(:params) {
      { :plugin => :some_plugin, :type => 'before_call', :method_block => plugin_method_block }
    }

    before :each do
      class EventsWrapper
        include Nark::Events
      end
    end

    after :each do
      Object.send :remove_const, :EventsWrapper
    end

    it "returns false if it does not exist" do
      first_event = Nark::Plugin::Event.new params
      new_event = Nark::Plugin::Event.new params
      EventsWrapper.add_trigger first_event
      new_event.should exist
    end

    it "returns true if it does exist" do
      event = Nark::Plugin::Event.new params
      event.should_not exist
    end
  end
end<commit_msg>Refactor specs<commit_after>require "spec_helper"

describe Nark::Plugin::Event do
  describe "#type" do
    it "stores the trigger type" do
      event = Nark::Plugin::Event.new :type => :before_call
      event.type.should eql :before_call
    end

    it "can be a string" do
      event = Nark::Plugin::Event.new :type => 'before_call'
      event.type.should eql 'before_call'
    end
  end

  describe "#method_block" do
    it "stores a block" do
      plugin_method_block = Proc.new {|p| p }
      params = {
        :type => 'before_call',
        :method_block => plugin_method_block
      }
      event = Nark::Plugin::Event.new params
      event.method_block.should eql plugin_method_block
    end

    it "throws an exception if a block is not passed"
  end

  describe "#plugin" do
    it "stores the plugin's name" do
      params = {
        :plugin => :some_plugin,
      }
      event = Nark::Plugin::Event.new params
      event.plugin.should eql :some_plugin
    end
  end

  describe "#to_hash" do
    it "returns the attributes as a Hash" do
      plugin_method_block = Proc.new {|p| p }
      params = {
        :plugin => :some_plugin,
        :type => 'before_call',
        :method_block => plugin_method_block
      }
      event = Nark::Plugin::Event.new params
      event.to_hash.should eql params
    end
  end

  describe "#exists?" do
    let(:plugin_method_block) { Proc.new {|p| p } }
    let(:params) {
      { :plugin => :some_plugin, :type => 'before_call', :method_block => plugin_method_block }
    }

    before :each do
      class EventsWrapper
        include Nark::Events
      end
    end

    after :each do
      Object.send :remove_const, :EventsWrapper
    end

    it "returns false if it does not exist" do
      event = Nark::Plugin::Event.new params
      Nark::Plugin.events.stub(:find).and_return false
      event.should_not exist
    end

    it "returns true if it does exist" do
      event = Nark::Plugin::Event.new params
      Nark::Plugin.events.stub(:find).and_return true
      event.should exist
    end
  end
end
{'fraction_non_alphanumeric': 0.1003610108303249, 'fraction_numerical': 0.0, 'mean_word_length': 2.4865771812080535, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, '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': '1531117', 'n_tokens_mistral': 1318, 'n_tokens_neox': 1288, 'n_words': 375}