# Mixing Rake and Turn

**URL:** <https://www.ruby-forum.com/t/mixing-rake-and-turn/84308>\
**Category:** Ruby\
**Created:** [February 2, 2007, 11:30pm UTC](https://www.ruby-forum.com/t/mixing-rake-and-turn/84308 "2007-02-02T23:30:34Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [February 2, 2007, 11:30pm UTC](https://www.ruby-forum.com/t/mixing-rake-and-turn/84308/1 "2007-02-02T23:30:34Z")

</div>

Hi all,

I’ve got some test tasks that I’ve got setup via a Rakefile. I’d like  
to see the output in the ‘turn’ format. However, simply sticking  
‘require “turn”’ at the top of the Rakefile doesn’t quite do the  
trick:

> rake test\_foo  
> Loaded suite /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake/  
> rake\_test\_loader  
> Started  
> …  
> Finished in 0.440434 seconds.

# 249 tests, 738 assertions, 0 failures, 0 errors Loaded suite /usr/local/bin/rake

# pass: 0, fail: 0, error: 0 total: 0 tests with 0 assertions in 0.001122 seconds

So, it’s giving me the nicer summary, but not the line by line result  
for each test.

How do I get Rake to behave the way I want?

Thanks,

Dan

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [February 2, 2007, 11:41pm UTC](https://www.ruby-forum.com/t/mixing-rake-and-turn/84308/2 "2007-02-02T23:41:36Z")

</div>

On 2/2/07, Daniel B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Started  
> So, it’s giving me the nicer summary, but not the line by line result  
> for each test.
> 
> How do I get Rake to behave the way I want?

When you run your unit tests from within rake, they are actually run  
in a separate ruby interpreter. Requiring turn into the Rakefile does  
not require turn into the ruby interpreter where the unit tests are  
run.

You’ll have to modify your test task to include turn …

ruby -Ilib -rturn your/test.rb

Or use the turn command

turn -Ilib your/test.rb

The fancy turn summary is coming out of the ruby interpreter running  
rake. When you require ‘turn’ the test::unit library is also  
included. test::unit sets up an empty test suite by default and  
registers a teardown hook. If no tests are run by the time the  
interpreter exits, the teardown hook is invoked and the empty test  
suite is run (hence the empty result set).

Hope this explanation helps.

Blessings,  
TwP

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [February 3, 2007, 12:10am UTC](https://www.ruby-forum.com/t/mixing-rake-and-turn/84308/3 "2007-02-03T00:10:38Z")

</div>

On Feb 2, 3:40 pm, “Tim P.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > pass: 0, fail: 0, error: 0  
> > not require turn into the ruby interpreter where the unit tests are  
> > The fancy turn summary is coming out of the ruby interpreter running  
> > rake. When you require ‘turn’ the test::unit library is also  
> > included. test::unit sets up an empty test suite by default and  
> > registers a teardown hook. If no tests are run by the time the  
> > interpreter exits, the teardown hook is invoked and the empty test  
> > suite is run (hence the empty result set).
> 
> Hope this explanation helps.

Thanks Tim, it does.

In theory, then, I ought to be able to push “-rturn” onto the  
TestTask#ruby\_opts accessor. Unfortunately, there appears to be a bug  
in Rake where the @ruby\_opts instance variable is getting reset to an  
empty array inside the “define” method in testtask.rb.

I’ll bring that up on the Rake mailing list.

Regards,

Dan

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [February 3, 2007, 1:45pm UTC](https://www.ruby-forum.com/t/mixing-rake-and-turn/84308/4 "2007-02-03T13:45:30Z")

</div>

Daniel B. wrote:

> end  
> But you have now a dependency to turn. If you share your program with  
> others they have to install turn if they want to use the test task. ☹

I prefer at the moment the following snipped on top of every test file:

require ‘test/unit’  
begin  
require ‘turn’  
rescue LoadError; end

So you can running tests with or without turn installed.

Other ideas?

Regards,  
Jan

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [February 3, 2007, 12:30am UTC](https://www.ruby-forum.com/t/mixing-rake-and-turn/84308/5 "2007-02-03T00:30:40Z")

</div>

On Feb 2, 4:09 pm, “Daniel B.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > ‘require “turn”’ at the top of the Rakefile doesn’t quite do the  
> > > Loaded suite /usr/local/bin/rake  
> > > When you run your unit tests from within rake, they are actually run  
> > > turn -Ilib your/test.rb  
> > > Thanks Tim, it does.  
> > > Dan  
> > > Upon further review, using TestTask#ruby\_opts _does_ work. The bug was  
> > > mine.

Anyhoo, for the sake of future Googlers, this is how you do it:

desc “Runs the test suite for the Foo class”  
Rake::TestTask.new(‘test\_foo’) do |t|  
t.test\_files = FileList[‘test/foo/\*.rb’] # Or whatever  
t.ruby\_opts \<\< ‘-rturn’  
t.warning = true  
end

Regards,

Dan

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [February 3, 2007, 4:51pm UTC](https://www.ruby-forum.com/t/mixing-rake-and-turn/84308/6 "2007-02-03T16:51:44Z")

</div>

On Feb 3, 5:40 am, Jan F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > t.warning = true  
> > rescue LoadError; end
> 
> So you can running tests with or without turn installed.
> 
> Other ideas?

In one project I have way too many files for that to be feasible. A  
simpler approach would be to do this at the top of the Rakefile:

$turn = true  
begin  
require ‘turn’  
rescue LoadError  
$turn = false  
end

t.ruby\_opts \<\< ‘-rturn’ if $turn

The only problem with that is that, as Tim mentioned earlier, you’ll  
get the bogus “zero” test results at the end (in addition to the real  
results). To avoid that, we could check to see if the turn.rb file  
merely exists instead of actually loading it:

require ‘rbconfig’  
include Config

$turn = false  
$turn = true if File.exists?(File.join(CONFIG[‘sitelibdir’],  
‘turn.rb’))

t.ruby\_opts \<\< ‘-rturn’ if $turn

This is what I plan on doing.

Regards,

Dan

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [February 5, 2007, 8:40am UTC](https://www.ruby-forum.com/t/mixing-rake-and-turn/84308/7 "2007-02-05T08:40:55Z")

</div>

Daniel B. wrote:

> t.ruby\_opts \<\< ‘-rturn’  
> This doesn’t work if you have installed turn via rubygems:

/usr/bin/ruby1.8: no such file to load – turn (LoadError)  
rake aborted!

You cannot load gems with the -r option of the ruby interpreter.

Regards,  
Jan

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [February 5, 2007, 5:23pm UTC](https://www.ruby-forum.com/t/mixing-rake-and-turn/84308/8 "2007-02-05T17:23:46Z")

</div>

On Feb 5, 2007, at 10:17 AM, Tim P. wrote:

> t.ruby\_opts \<\< ‘-rubygems’  
> t.ruby\_opts \<\< ‘-rturn’
> 
> That should work, correct?

No, I don’t think so.

Ruby’s -r switch is not implemented by calling Ruby’s require()  
method, so RubyGems cannot override it.

James Edward G. II

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [February 5, 2007, 5:17pm UTC](https://www.ruby-forum.com/t/mixing-rake-and-turn/84308/9 "2007-02-05T17:17:45Z")

</div>

On 2/5/07, Jan F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Daniel B. wrote:
> 
> > t.ruby\_opts \<\< ‘-rturn’  
> > This doesn’t work if you have installed turn via rubygems:
> 
> /usr/bin/ruby1.8: no such file to load – turn (LoadError)  
> rake aborted!
> 
> You cannot load gems with the -r option of the ruby interpreter.

t.ruby\_opts \<\< ‘-rubygems’  
t.ruby\_opts \<\< ‘-rturn’

That should work, correct?

TwP
