How to implement a new TaskLib in Rake

  • Thread starter Giulio Piancastelli
  • Start date
G

Giulio Piancastelli

Hi all,

so my last attempt [1] at building a task for running RubyFIT tests
from within Rake has been successful, and simpler than I thought. In
fact, thanks to the online examples in the Rake wiki, I've been able to
come up with something nice enough to be a good first step for my aim.

But now I'd like to turn those tasks in a proper TaskLib, and things
seems to be really a bit thougher here. Has anyone had experience
doing that, and would like to share some insights? I've tried mimicking
the structure of testtask.rb, the TaskLib for running Unit Tests, but
Rake aborts every time I run my script because "don't know how to build
task". I've seen the error comes from rake.rb, but I didn't manage to
understand what the code is trying to do right there.

Thanks in advance to anyone willing to help.

Best Regards,
Giulio Piancastelli.
 
J

Jim Weirich

Hi all,

so my last attempt [1] at building a task for running RubyFIT tests
from within Rake has been successful, and simpler than I thought. In
fact, thanks to the online examples in the Rake wiki, I've been able to
come up with something nice enough to be a good first step for my aim.

But now I'd like to turn those tasks in a proper TaskLib, and things
seems to be really a bit thougher here. Has anyone had experience
doing that, and would like to share some insights? I've tried mimicking
the structure of testtask.rb, the TaskLib for running Unit Tests, but
Rake aborts every time I run my script because "don't know how to build
task". I've seen the error comes from rake.rb, but I didn't manage to
understand what the code is trying to do right there.

Thanks in advance to anyone willing to help.

One of the things I've been thinking about for the next major version of Rake
is a better way to specify and use libraries of related tasks. Its still at
the "thinking about" stage yet, so don't hold your breath.

If you can post the details of what you are doing, I'd be glad to give a hand.
 
G

Giulio Piancastelli

Jim said:
If you can post the details of what you are doing, I'd be glad to
give a hand.

Well, I took another shot at a TaskLib implementation, and perhaps
found what was wrong with my code. Initially I wrote:

module Rake
class FitTestTask < TaskLib
attr_accessor :name, :libs, :pattern
def test_files=(list)
@test_files = list
end
def initialize(name=:fittest)
@name = name
@libs = ["lib"]
@pattern = nil
@test_files = nil
yield self if block_given?
define
end
def define
puts "Running FitTest tasklib with #@libs and tests #@test_files"
self
end
end
end

And rake aborted with the error message I reported. Then,
reimplementing, I noticed that you were actually *defining* a task in
TestTask#define, so I came up with:

def define
task @name do
puts "Running FitTest tasklib with #@libs and tests #@test_files"
end
self
end

This way, Rake runs fine, even if I don't understand the internal
mechanics. So, must every task in the lib be defined at once in a
method called by the constructor? The pattern usage of tasks seems to
suggest that (it's always Rake::SomeTask.new {...}) but I'd like to
hear more about this.

And... is it just *that* easy? Or are there other details I should be
aware of?

I'll try to define my tasks in a lib now; I'll get back to the
newsgroup if I happen to face some problems, perhaps harder to think
about than the latest. Sorry to bother.

Best Regards,
Giulio Piancastelli.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,261
Messages
2,571,040
Members
48,769
Latest member
Clifft

Latest Threads

Top