# Using a constant in both unit tests and in fixtures

**URL:** <https://www.ruby-forum.com/t/using-a-constant-in-both-unit-tests-and-in-fixtures/115639>\
**Category:** Rails\
**Created:** [September 27, 2007, 3:54am UTC](https://www.ruby-forum.com/t/using-a-constant-in-both-unit-tests-and-in-fixtures/115639 "2007-09-27T03:54:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![creativelogic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f17d59/32.png) [@creativelogic](https://www.ruby-forum.com/u/creativelogic)\
**Post date:** [September 27, 2007, 3:54am UTC](https://www.ruby-forum.com/t/using-a-constant-in-both-unit-tests-and-in-fixtures/115639/1 "2007-09-27T03:54:11Z")

</div>

I create a number of users in a database through a fixture. I then run  
a  
unit test to verify that the number of users in the database is correct.  
I  
want to make this number a constant that is only defined in one place.  
I  
currently have it defined in ./test/test\_helper.rb which works fine for  
the  
unit test, but the fixture cannot see it. I’ve tried to "require  
‘…/test\_helper.rb’ " from inside the fixture to no avail.

Any ideas?

---

<div class="post-metadata">

**Author:** ![creativelogic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f17d59/32.png) [@creativelogic](https://www.ruby-forum.com/u/creativelogic)\
**Post date:** [September 27, 2007, 7:00pm UTC](https://www.ruby-forum.com/t/using-a-constant-in-both-unit-tests-and-in-fixtures/115639/2 "2007-09-27T19:00:43Z")

</div>

On 9/26/07, Ryan A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I create a number of users in a database through a fixture. I then run a  
> unit test to verify that the number of users in the database is correct. I  
> want to make this number a constant that is only defined in one place. I  
> currently have it defined in ./test/test\_helper.rb which works fine for the  
> unit test, but the fixture cannot see it. I’ve tried to "require  
> ‘…/test\_helper.rb’ " from inside the fixture to no avail.

You can put it in a file in lib/ and then require that file from both  
your test and your fixture file.
