[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Needing help using Rake from within a Ruby program

Bryan Richardson

1/18/2008 4:15:00 AM

[Note: parts of this message were removed to make it a legal post.]

Hello all,

I'm trying to invoke rake from within one of my Unit Test files to setup a
test database before running tests and I'm having some trouble doing so. I
try the following code in a file that is located in the same directory as my
Rakefile:

rake = Rake::Application.new
rake['foo:bar:load'].invoke

and I get the following:

RuntimeError: Don't know how to build task 'foo:bar:load'

However, if I run rake from the command line in this same directory passing
it the foo:bar:load task it works fine. Any suggestions?

Thanks! -- BTR

4 Answers

Gordon Thiesfeld

1/18/2008 4:29:00 AM

0

On Jan 17, 2008 10:14 PM, Bryan Richardson <btricha@gmail.com> wrote:
> Hello all,
>
> I'm trying to invoke rake from within one of my Unit Test files to setup a
> test database before running tests and I'm having some trouble doing so. I
> try the following code in a file that is located in the same directory as my
> Rakefile:
>
> rake = Rake::Application.new
> rake['foo:bar:load'].invoke
>
> and I get the following:
>
> RuntimeError: Don't know how to build task 'foo:bar:load'
>
> However, if I run rake from the command line in this same directory passing
> it the foo:bar:load task it works fine. Any suggestions?
>
> Thanks! -- BTR
>

Did you require the rakefile in you code? rake does so automatically.

Thanks,

Gordon

Gordon Thiesfeld

1/18/2008 4:37:00 AM

0

>
> Did you require the rakefile in you code? rake does so automatically.
>
> Thanks,
>
> Gordon
>

Wow, that was very terse. Even for me. What I mean is that the rake
command will require your rakefile automatically. But if you want to
use a rake task from ruby, you will have to explicitly require the
rakefile.

Thanks,

Gordon

Bryan Richardson

1/18/2008 4:54:00 AM

0

[Note: parts of this message were removed to make it a legal post.]

Gordon,

How do I specify the Rakefile to use?

Thanks! -- BTR

On Jan 17, 2008 9:36 PM, Gordon Thiesfeld <gthiesfeld@gmail.com> wrote:

> >
> > Did you require the rakefile in you code? rake does so automatically.
> >
> > Thanks,
> >
> > Gordon
> >
>
> Wow, that was very terse. Even for me. What I mean is that the rake
> command will require your rakefile automatically. But if you want to
> use a rake task from ruby, you will have to explicitly require the
> rakefile.
>
> Thanks,
>
> Gordon
>
>

Gordon Thiesfeld

1/18/2008 12:39:00 PM

0

On Jan 17, 2008 10:53 PM, Bryan Richardson <btricha@gmail.com> wrote:
> Gordon,
>
> How do I specify the Rakefile to use?
>
> Thanks! -- BTR
>

I was a little off. I don't think you can use require, but you can use load.

require 'rubygems'
require 'rake'
load 'path/to/Rakefile'

rake = Rake::Application.new
rake['spec'].invoke