Sha256: 12f3c7862d9730b24773bec0703986a995bdbc8e4b98967b5939390d79589557
Contents?: true
Size: 668 Bytes
Versions: 2
Compression:
Stored size: 668 Bytes
Contents
def describe_readme(readme, example_regex=default_example_regex) open(readme) do |f| f.read.scan(example_regex).each do |example_name, example_code| describe "#{example_name} (from README)" do subject { eval_code(example_code) } # This is safe isn't it!?!? :) it { should == expected_output(example_code) } end end end end def default_example_regex @default_example_regex ||= /(Example:[ ].*?)\n``` ruby\n(.*?)```/m end def expected_output(example_code) example_code.scan(/^# => (.*)/).flatten.join("\n") end def eval_code code IO.popen("ruby", "w+") { |f| f.write code f.close_write f.read.strip } end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rdd-0.0.2 | lib/rdd/rspec.rb |
rdd-0.0.1 | lib/rdd/rspec.rb |