File: let_all.rb

package info (click to toggle)
ruby-maxitest 7.1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 444 kB
  • sloc: ruby: 1,339; makefile: 7
file content (20 lines) | stat: -rw-r--r-- 371 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# frozen_string_literal: true
module Maxitest
  module LetAll
    def let_all(name, &block)
      cache = []
      define_method(name) do
        if cache.empty?
          cache << instance_eval(&block)
        end
        cache.first
      end
    end

    def self.included(base)
      base.extend(self)
    end
  end
end

Minitest::Spec::DSL.include(Maxitest::LetAll)