<commit_before>require "spec_helper"

describe "Plugin DSL" do
  include Rack::Test::Methods

  before :each do
    def app
      @target_app = mock('The target application')
      @target_app.stub(:call).and_return([200, {'PATH_INFO' => '/'}, "Target application"])
      Rack::Tracker::Middleware.new @target_app
    end
  end

  describe "defining a plugin hook" do
    it "triggers the hook when the application is called" do
      Rack::Tracker::DSL.new :something_really_cool do |plugin|
        plugin.variables :total_requests => 0

        plugin.add_hook :before_call do |env|
          Rack::Tracker.total_requests += 1
        end
      end

      module Rack::Tracker
        include Rack::Tracker::Plugins::SomethingReallyCool
      end

      get '/'
      Rack::Tracker.total_requests.should eql 1
    end
  end

  describe "#method" do
    it "allows us to define a plugin method" do
      Rack::Tracker::DSL.new :something_really_cool do |plugin|
        plugin.method :revision do
          %x[cat .git/refs/heads/master| cut -f 1].chomp
        end
      end

      module Rack::Tracker
        include Rack::Tracker::Plugins::SomethingReallyCool
      end

      Rack::Tracker.revision.should eql %x[cat .git/refs/heads/master| cut -f 1].chomp
    end
  end
end
<commit_msg>Improve the description of the spec<commit_after>require "spec_helper"

describe "Plugin DSL" do
  include Rack::Test::Methods

  before :each do
    def app
      @target_app = mock('The target application')
      @target_app.stub(:call).and_return([200, {'PATH_INFO' => '/'}, "Target application"])
      Rack::Tracker::Middleware.new @target_app
    end
  end

  describe "defining a plugin hook" do
    it "triggers the hook when the application is called" do
      Rack::Tracker::DSL.new :something_really_cool do |plugin|
        plugin.variables :total_requests => 0

        plugin.add_hook :before_call do |env|
          Rack::Tracker.total_requests += 1
        end
      end

      module Rack::Tracker
        include Rack::Tracker::Plugins::SomethingReallyCool
      end

      get '/'
      Rack::Tracker.total_requests.should eql 1
    end
  end

  describe "defining a plugin class method" do
    it "allows us to define a plugin method" do
      Rack::Tracker::DSL.new :something_really_cool do |plugin|
        plugin.method :revision do
          %x[cat .git/refs/heads/master| cut -f 1].chomp
        end
      end

      module Rack::Tracker
        include Rack::Tracker::Plugins::SomethingReallyCool
      end

      Rack::Tracker.revision.should eql %x[cat .git/refs/heads/master| cut -f 1].chomp
    end
  end
end

{'fraction_non_alphanumeric': 0.10132827324478179, 'fraction_numerical': 0.0060721062618595825, 'mean_word_length': 2.73371104815864, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '4422420', 'n_tokens_mistral': 845, 'n_tokens_neox': 791, 'n_words': 225}