# MiniTest before and after all

**URL:** <https://www.ruby-forum.com/t/minitest-before-and-after-all/210488>\
**Category:** Ruby\
**Created:** [August 9, 2011, 6:39pm UTC](https://www.ruby-forum.com/t/minitest-before-and-after-all/210488 "2011-08-09T18:39:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [August 9, 2011, 6:39pm UTC](https://www.ruby-forum.com/t/minitest-before-and-after-all/210488/1 "2011-08-09T18:39:59Z")

</div>

What is the reasoning behind MiniTest’s lack of support for  
`before :all` / `after :all` ?

I can understand that one should keep setup procedures to a minimum,  
but are their not use cases where pre-testcase setup is really needed  
– logging into a database or service, for example?

What is the conventional thinking on this topic?

---

<div class="post-metadata">

**Author:** ![tcsnide](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@tcsnide](https://www.ruby-forum.com/u/tcsnide)\
**Post date:** [August 9, 2011, 11:16pm UTC](https://www.ruby-forum.com/t/minitest-before-and-after-all/210488/2 "2011-08-09T23:16:47Z")

</div>

> Thomas S. wrote in post #1015734:

> What is the conventional thinking on this topic?

Maybe I’m wrong but I was going through some Ruby standard libraries  
just the other day and I saw this:

## 

# Define a ‘before’ action. Inherits the way normal methods should.

# 

# NOTE: +type+ is ignored and is only there to make porting easier.

# 

# Equivalent to MiniTest::Unit::TestCase#setup.

def self.before type = :each, &block  
raise “unsupported before type: #{type}” unless type == :each  
define\_inheritable\_method :setup, &block  
end

## 

# Define an ‘after’ action. Inherits the way normal methods should.

# 

# NOTE: +type+ is ignored and is only there to make porting easier.

# 

# Equivalent to MiniTest::Unit::TestCase#teardown.

def self.after type = :each, &block  
raise “unsupported after type: #{type}” unless type == :each  
define\_inheritable\_method :teardown, &block  
end

Keep in mind I don’t use minitest so that might not be what you’re  
after.

-Luke

---

<div class="post-metadata">

**Author:** ![tcsnide](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@tcsnide](https://www.ruby-forum.com/u/tcsnide)\
**Post date:** [August 10, 2011, 8:28am UTC](https://www.ruby-forum.com/t/minitest-before-and-after-all/210488/3 "2011-08-10T08:28:39Z")

</div>

On Aug 9, 5:16pm, luke gruber [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> # 
> 
> # NOTE: +type+ is ignored and is only there to make porting easier.
> 
> # 
> 
> # Equivalent to MiniTest::Unit::TestCase#teardown.
> 
> def self.after type = :each, &block  
> raise “unsupported after type: #{type}” unless type == :each  
> define\_inheritable\_method :teardown, &block  
> end
> 
> Keep in mind I don’t use minitest so that might not be what you’re  
> after.

That’s just elucidating my question. Read the line:

```
raise "unsupported before type: #{type}" unless type == :each

```

I’m asking about `:all`,

---

<div class="post-metadata">

**Author:** ![tcsnide](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@tcsnide](https://www.ruby-forum.com/u/tcsnide)\
**Post date:** [August 11, 2011, 1:17am UTC](https://www.ruby-forum.com/t/minitest-before-and-after-all/210488/4 "2011-08-11T01:17:24Z")

</div>

> I’m asking about `:all`,

You probably found this already, but just in case:  
[http://bfts.rubyforge.org/minitest/MiniTest/Unit.html#method-c-after\_tests](http://bfts.rubyforge.org/minitest/MiniTest/Unit.html#method-c-after_tests)

I don’t think Minitest supports a before\_tests though

there’s a github repo for that functionality apparently:  
[http://techno-weenie.net/2010/5/4/escaping-your-test-suite-with-your-life/](http://techno-weenie.net/2010/5/4/escaping-your-test-suite-with-your-life/)

-Luke
