File: hook_all.rb

package info (click to toggle)
ruby-maxitest 6.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 504 kB
  • sloc: ruby: 1,583; makefile: 7
file content (29 lines) | stat: -rw-r--r-- 797 bytes parent folder | download | duplicates (2)
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
26
27
28
29
module Maxitest
  class << self
    attr_accessor :hook_all_counter
  end
end
Maxitest.hook_all_counter = 0

module Maxitest
  module HookAll
    [:before, :after].each do |hook|
      # minitest discards the type argument, so we are not sending it along
      define_method(hook) do |type = :each, &block|
        case type
        when :each then super(&block)
        when :all
          raise ArgumentError, ":all is not supported in after" if hook == :after
          c = (Maxitest.hook_all_counter += 1)
          callback = :"maxitest_hook_all_#{c}"
          let_all(callback, &block)
          super() { send callback }
        else
          raise ArgumentError, "only :each and :all are supported"
        end
      end
    end
  end
end

Minitest::Spec::DSL.prepend(Maxitest::HookAll)