Skip to content

Instantly share code, notes, and snippets.

@wolframkriesing
Last active February 8, 2016 08:10
Show Gist options
  • Save wolframkriesing/48921fbd1d0b06db584b to your computer and use it in GitHub Desktop.
Save wolframkriesing/48921fbd1d0b06db584b to your computer and use it in GitHub Desktop.
rake DSL as it should be?
# Tasks are defined using the DSL like this `task :name ....`
# But for a task that execute tests I can only find this piece of code everywhere on the web
Rake::TestTask.new do |t|
t.libs << "test"
t.test_files = FileList['test/test*.rb']
t.verbose = true
end
# should it not be something like this
task :test => [Rake::TestTask] do |t|
t.libs << "test"
t.test_files = FileList['test/test*.rb']
t.verbose = true
end
# I would understand that. But the very different syntax used above doesn't stick in
# my head and somehow yells at me "I don't want to be part of the DSL, I want to be Ruby".
# extracted from https://github.com/wolframkriesing/wolfram.kriesing.de/blob/use-react/content/tech.md#understanding-rake-in-order-to-keep-on-reading-objects-on-rails
@sideshowcoder
Copy link

Mh the 2. seems more dsl like but implies a task is created that depends on the test task, which is not the case.
Rake is a very thin DSL and task is just a constructor method. It could look more DSL like this

test_task :thing do |t|
  ...
end

But not sure how much this improves things, for me the DSL is clearer then you pass an argument to the Rake::TestTask construction.
Overall I think the approach to only use DSL where it is most obvious is kind of clever.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment