Last active
January 2, 2016 20:39
-
-
Save sideshowcoder/8358021 to your computer and use it in GitHub Desktop.
README Driven Development task for Rake
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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