# Mocking global variables in rspec

**URL:** <https://www.ruby-forum.com/t/mocking-global-variables-in-rspec/141910>\
**Category:** Rails\
**Created:** [July 1, 2008, 6:10pm UTC](https://www.ruby-forum.com/t/mocking-global-variables-in-rspec/141910 "2008-07-01T18:10:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Reggie\_on\_rails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e56c9b/32.png) [@Reggie\_on\_rails](https://www.ruby-forum.com/u/Reggie_on_rails)\
**Post date:** [July 1, 2008, 6:10pm UTC](https://www.ruby-forum.com/t/mocking-global-variables-in-rspec/141910/1 "2008-07-01T18:10:06Z")

</div>

What’s the best way to mock global variables in rspec?

For the model group I would like database interaction.

For the controller group I would like to mock the behavior.

However it’s failing in the ExampleGroup and defining a before(:all)  
is overkill since I only require db transaction for the model test.

Any ideas?

Thanks in avance 🙂
