# Setup not invoked during unit testing

**URL:** <https://www.ruby-forum.com/t/setup-not-invoked-during-unit-testing/191914>\
**Category:** Rails\
**Created:** [July 20, 2010, 4:57pm UTC](https://www.ruby-forum.com/t/setup-not-invoked-during-unit-testing/191914 "2010-07-20T16:57:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![f2andy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/7feea3/32.png) [@f2andy](https://www.ruby-forum.com/u/f2andy)\
**Post date:** [July 20, 2010, 4:57pm UTC](https://www.ruby-forum.com/t/setup-not-invoked-during-unit-testing/191914/1 "2010-07-20T16:57:12Z")

</div>

I have a bunch of unit test files in a Rails project. One of them has  
stopped using the setup method before each test, or even if I invoke it  
in the test itself.

After commenting out most of it, here is what is left:

require ‘test/test\_helper’

class GlcTest \< ActiveSupport::TestCase  
def setup  
p ‘###########################’  
end

def test\_setup  
p ‘[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[’  
setup  
end  
end

The file I am testing is glc.rb, and that does get loaded. If I run the  
test file, it does work normally; this is a problem when running the  
test through rake (either via my IDE or at the command line).

test\_setup does get invoked, so the file is being processed. I am  
guessing that somewhere there is another setup method that takes  
priority, but where would it be, and why does it take priority over this  
one? My IDE recognises that this setup overrides the one in  
ActiveSupport::TestCase.

There is no setup method defined in glc.rb, and as the problem is  
isolated to this one class, I am mystified as to where this other setup  
might be.

Any advice appreciated.

Using JRuby 1.5 on Windows, by the way.

---

<div class="post-metadata">

**Author:** ![f2andy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/7feea3/32.png) [@f2andy](https://www.ruby-forum.com/u/f2andy)\
**Post date:** [July 20, 2010, 5:51pm UTC](https://www.ruby-forum.com/t/setup-not-invoked-during-unit-testing/191914/2 "2010-07-20T17:51:31Z")

</div>

On 20 July 2010 15:57, Andy J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> p ‘###########################’  
> end
> 
> def test\_setup  
> p ‘[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[’

You could put a debugger statement here then step in to see where it  
goes

Colin

---

<div class="post-metadata">

**Author:** ![f2andy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/7feea3/32.png) [@f2andy](https://www.ruby-forum.com/u/f2andy)\
**Post date:** [July 20, 2010, 6:07pm UTC](https://www.ruby-forum.com/t/setup-not-invoked-during-unit-testing/191914/3 "2010-07-20T18:07:56Z")

</div>

On Jul 20, 3:57 pm, Andy J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> test\_setup does get invoked, so the file is being processed. I am  
> guessing that somewhere there is another setup method that takes  
> priority, but where would it be, and why does it take priority over this  
> one? My IDE recognises that this setup overrides the one in  
> ActiveSupport::TestCase.

is it possible that another of your test cases is also called  
GlcTest ?

Fred

---

<div class="post-metadata">

**Author:** ![f2andy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/7feea3/32.png) [@f2andy](https://www.ruby-forum.com/u/f2andy)\
**Post date:** [July 21, 2010, 10:33am UTC](https://www.ruby-forum.com/t/setup-not-invoked-during-unit-testing/191914/4 "2010-07-21T10:33:41Z")

</div>

Frederick C. wrote:

> On Jul 20, 3:57ï¿½pm, Andy J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > test\_setup does get invoked, so the file is being processed. I am  
> > guessing that somewhere there is another setup method that takes  
> > priority, but where would it be, and why does it take priority over this  
> > one? My IDE recognises that this setup overrides the one in  
> > ActiveSupport::TestCase.
> 
> is it possible that another of your test cases is also called  
> GlcTest ?
> 
> Fred

That was it. I had copy-and-pasted from GlcTest to create a new test  
class, and had forgotten to change the class name. Thanks for the help.
