Created
November 23, 2011 21:07
-
-
Save AndrewVos/1389914 to your computer and use it in GitHub Desktop.
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
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