-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support before :all and block after :all + around :all
- Loading branch information
Showing
10 changed files
with
114 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ def let_all(name, &block) | |
cache.first | ||
end | ||
end | ||
|
||
def self.included(base) | ||
base.extend(self) | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
require "./spec/cases/helper" | ||
|
||
hook_method = (ENV["HOOK_METHOD"] || "before").to_sym | ||
hook_type = (ENV["HOOK_TYPE"] || "all").to_sym | ||
|
||
# need this globally or classes don't sort | ||
r = Minitest::Runnable.runnables | ||
def r.shuffle | ||
self | ||
end | ||
|
||
describe 2 do | ||
order_dependent! | ||
|
||
send hook_method, hook_type do | ||
puts "ALL" | ||
end | ||
|
||
it "works" do | ||
puts "T1" | ||
end | ||
|
||
describe "subclass" do | ||
order_dependent! | ||
|
||
send hook_method, hook_type do | ||
puts "ALL-SUB" | ||
end | ||
|
||
it "still works" do | ||
puts "TS1" | ||
end | ||
|
||
it "yes it does" do | ||
puts "TS2" | ||
end | ||
end | ||
|
||
it "works after subclass" do | ||
puts "T2" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters