aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/cask/test/support/shared_examples.rb
blob: 594ca81c17aab525140fa26720f9028d94c6eb31 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# Adapted from https://gist.github.com/jodosha/1560208
MiniTest::Spec.class_eval do
  def self.shared_examples
    @shared_examples ||= {}
  end
end

module MiniTest
  class Spec
    module SharedExamples
      def shared_examples_for(desc, &block)
        MiniTest::Spec.shared_examples[desc] = block
      end

      def it_behaves_like(desc, *args, &block)
        instance_exec(*args, &MiniTest::Spec.shared_examples[desc])
        instance_eval(&block) if block_given?
      end
    end
  end
end

Object.class_eval do
  include(MiniTest::Spec::SharedExamples)
end