Skip to content

Instantly share code, notes, and snippets.

@sideshowcoder
Last active January 2, 2016 20:39
Show Gist options
  • Save sideshowcoder/8358021 to your computer and use it in GitHub Desktop.
Save sideshowcoder/8358021 to your computer and use it in GitHub Desktop.
README Driven Development task for Rake
def code_from_markdown file
content = File.read(file)
code_snippets = []
content.scan(/`{3,}ruby\n((.|\n)*?)^`{3,}/) { |m| code_snippets << $1 }
code_snippets
end
namespace :test do
# all code inside ```ruby ``` is executed to uncomment certain examples just
# use ```xruby ``` or alike
desc "Execute the codesamples in the README"
task :codesamples do
lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
examples = code_from_markdown("./README.md")
examples.each do |example|
fork { eval example }
Process.wait
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment