Skip to content

Instantly share code, notes, and snippets.

@AndrewVos
Created November 23, 2011 21:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndrewVos/1389914 to your computer and use it in GitHub Desktop.
Save AndrewVos/1389914 to your computer and use it in GitHub Desktop.
task :default => :build
task :build do
contents = File.read("README.md.docu")
reading_assertion = false
reading_example = false
current_example = nil
current_assertion = nil
contents.lines.each do |line|
current_example ||= []
current_assertion ||= []
if line.strip == ":example:"
reading_example = true
reading_assertion = false
elsif line.strip == ":assertion:"
reading_example = false
reading_assertion = true
elsif line.strip == ":end:"
reading_example = false
reading_assertion = false
example = current_example.join("\n")
assertion = current_assertion.join("\n").gsub("#=>", "").strip
result = eval(example).to_s.strip
if result != assertion
raise "Assertion does not match example. Expected \"#{result}\" to equal \"#{assertion}\"."
end
current_example = []
current_assertion = []
else
current_example << line if reading_example
current_assertion << line if reading_assertion
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment