<commit_before>require 'spec_helper'

module SteppingStone
  describe Hooks do
    describe "#invoke" do
      it "invokes hooks in the right order" do
        results = []
        subject.add(:before) { results.push(:before) }
        subject.add(:after) { results.push(:after) }
        subject.add(:around) do |run|
          results.push(:around_before)
          run.call
          results.push(:around_after)
        end
        subject.invoke { results.push(:run) }
        results.should eq([:around_before, :before, :run, :after, :around_after])
      end

      it "passes arguments to invoke to the hooks" do
        res = []
        subject.add(:around) do |run, arg|
          res.push(:"around_before_#{arg}")
          run.call
          res.push(:"around_after_#{arg}")
        end
        subject.add(:before) { |arg| res.push(:"before_#{arg}") }
        subject.add(:after)  { |arg| res.push(:"after_#{arg}") }
        subject.invoke([], :arg) {}
        res.should eq([:around_before_arg, :before_arg, :after_arg, :around_after_arg])
      end

      context "with a tagged hook" do
        it "invokes the hook when the tag matches" do
          res = []<commit_msg>Better spec example name<commit_after>require 'spec_helper'

module SteppingStone
  describe Hooks do
    describe "#invoke" do
      it "invokes hooks in the right order" do
        results = []
        subject.add(:before) { results.push(:before) }
        subject.add(:after) { results.push(:after) }
        subject.add(:around) do |run|
          results.push(:around_before)
          run.call
          results.push(:around_after)
        end
        subject.invoke { results.push(:run) }
        results.should eq([:around_before, :before, :run, :after, :around_after])
      end

      it "passes arguments to the hooks" do
        res = []
        subject.add(:around) do |run, arg|
          res.push(:"around_before_#{arg}")
          run.call
          res.push(:"around_after_#{arg}")
        end
        subject.add(:before) { |arg| res.push(:"before_#{arg}") }
        subject.add(:after)  { |arg| res.push(:"after_#{arg}") }
        subject.invoke([], :arg) {}
        res.should eq([:around_before_arg, :before_arg, :after_arg, :around_after_arg])
      end

      context "with a tagged hook" do
        it "invokes the hook when the tag matches" do
          res = []
{'fraction_non_alphanumeric': 0.13653603034134007, 'fraction_numerical': 0.0, 'mean_word_length': 2.343661971830986, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2249763', 'n_tokens_mistral': 721, 'n_tokens_neox': 727, 'n_words': 175}