# \[Rspec\] Using Mocha results in uninitialized constant, using a 'fix' breaks RSpec output

**URL:** <https://www.ruby-forum.com/t/rspec-using-mocha-results-in-uninitialized-constant-using-a-fix-breaks-rspec-output/175195>\
**Category:** Rails\
**Created:** [September 9, 2009, 2:28pm UTC](https://www.ruby-forum.com/t/rspec-using-mocha-results-in-uninitialized-constant-using-a-fix-breaks-rspec-output/175195 "2009-09-09T14:28:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lb2007](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/35a633/32.png) [@Lb2007](https://www.ruby-forum.com/u/Lb2007)\
**Post date:** [September 9, 2009, 2:28pm UTC](https://www.ruby-forum.com/t/rspec-using-mocha-results-in-uninitialized-constant-using-a-fix-breaks-rspec-output/175195/1 "2009-09-09T14:28:44Z")

</div>

After installation of Mocha (0.9.7), running “script/spec spec”  
results in a “`const\_missing’: uninitialized constant  
Test::Unit::TestResult::TestResultFailureSupport (NameError)” error.  
(As shown here; [Ruby code - 15 lines - codepad](http://codepad.org/mTqztjwt) )  
I’m running Ruby 1.8.6 with Rails 2.3.4 on Windows, rspec (-rails)  
1.2.8 (1.2.7.1), Test::Unit 2.0.3

As suggested roughly on

> <https://stackoverflow.com/questions/1145318/getting-uninitialized-constant-error-when-trying-to-run-tests>

, I’ve added config.gem ‘test-unit’, :lib =\> ‘test/unit’" to my  
environments/test.rb file at the very top. Doing so does resolve the  
trace being printed, however, no output is generated at all when  
running “script/spec spec” again. Removing the line brings back the  
trace, but logically does not resolve the issue. ( Relevant Test::Unit  
code is shown on [Ruby code - 89 lines - codepad](http://codepad.org/bg7BlS7F) )

What other workarounds could I give a shot? Googling doesnt seem to  
bring up alternative solutions sadly.

---

<div class="post-metadata">

**Author:** ![Lb2007](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/35a633/32.png) [@Lb2007](https://www.ruby-forum.com/u/Lb2007)\
**Post date:** [September 10, 2009, 10:57am UTC](https://www.ruby-forum.com/t/rspec-using-mocha-results-in-uninitialized-constant-using-a-fix-breaks-rspec-output/175195/2 "2009-09-10T10:57:31Z")

</div>

2009/9/9 Lb2007 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> trace being printed, however, no output is generated at all when  
> running “script/spec spec” again. Removing the line brings back the  
> trace, but logically does not resolve the issue. ( Relevant Test::Unit  
> code is shown on [http://codepad.org/bg7BlS7F](http://codepad.org/bg7BlS7F) )
> 
> What other workarounds could I give a shot? Googling doesnt seem to  
> bring up alternative solutions sadly.

I don’t know anything about the RSpec side of things, but the thing  
that changed in Mocha \>= 0.9.6 was that previously Mocha had itself  
loaded Test::Unit whereas now it expects you to load Test::Unit  
yourself before you then load Mocha.

How are you loading Mocha? If you are loading it with a config.gem  
statement after the ‘test-unit’ one, then this should be ok and I  
would guess the problem may lie in the integration with RSpec.

## Regards, James.

> **[James Mead](https://jamesmead.org/)**
>
> Ruby Developer, author of Mocha, and ex-Antarctic Hero.

---

<div class="post-metadata">

**Author:** ![Lb2007](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/35a633/32.png) [@Lb2007](https://www.ruby-forum.com/u/Lb2007)\
**Post date:** [October 1, 2009, 10:58pm UTC](https://www.ruby-forum.com/t/rspec-using-mocha-results-in-uninitialized-constant-using-a-fix-breaks-rspec-output/175195/3 "2009-10-01T22:58:09Z")

</div>

It seems that having the test-unit gem installed causes this problem.

On my Linux box, my rspec tests were all working fine for one project.  
I started testing another project that I had imported from a Windows  
development environment that referenced the test-unit gem.

Installing that gem on my Linux box gave me an error when trying to  
run my rspec tests. After adding config.gem “test-unit” to test.rb,  
the tests didn’t fail but didn’t run anymore. The newer application  
also had the same issues.

I uninstalled the test-unit gem from my Linux machine and removed the  
config.gem requirement from both the old and new applications and  
everything ran fine again.  
I also did this on my Windows machine and everything started running  
as expected.

Eric

---

<div class="post-metadata">

**Author:** ![Lb2007](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/35a633/32.png) [@Lb2007](https://www.ruby-forum.com/u/Lb2007)\
**Post date:** [October 2, 2009, 4:35pm UTC](https://www.ruby-forum.com/t/rspec-using-mocha-results-in-uninitialized-constant-using-a-fix-breaks-rspec-output/175195/4 "2009-10-02T16:35:23Z")

</div>

2009/10/1 E. Litwin [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> I uninstalled the test-unit gem from my Linux machine and removed the  
> config.gem requirement from both the old and new applications and  
> everything ran fine again.  
> I also did this on my Windows machine and everything started running  
> as expected.

I’m glad you’ve solved your problem.

However, it sounds like there might still be a problem with some  
combination of Mocha, Test::Unit and RSpec (& RSpec on rails?).

It’d be great if you could create a ticket on Lighthouse [1] with  
steps to reproduce the problem e.g. in a Rails app built from scratch.

Regards,

James M…
