Skip to content

Commit

Permalink
load samples and convert each one to an "it" block in specs
Browse files Browse the repository at this point in the history
  • Loading branch information
mislav committed Apr 22, 2008
1 parent ccf8d08 commit 7667dea
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
35 changes: 14 additions & 21 deletions spec/markdown_spec.rb
Expand Up @@ -3,7 +3,7 @@

describe BlueCloth, 'Markdown processing' do

include SampleLoader
extend SampleLoader

it "should render HTML without trailing newline" do
BlueCloth.new('Foo').to_html.should == '<p>Foo</p>'
Expand All @@ -12,30 +12,23 @@
it "should not swallow trailing newline" do
BlueCloth.new("Foo\n").to_html.should == "<p>Foo</p>\n"
end

it "should render all the samples correctly" do
load_samples('all')
render_samples

describe 'sample:' do
load_samples('all') do |sample|
it(sample.comment) { sample.should render }
end

load_samples('failing') do |sample|
it(sample.comment) { sample.should render }
end if false
end

it "should render all the failing samples" do
load_samples('failing')
render_samples
end

protected

def render
SampleMatcher.new
end

def render_samples
@sections.values.each do |samples|
samples.each do |sample|
sample.should render
end
end
end

end

class SampleMatcher
Expand All @@ -58,8 +51,8 @@ def failure_message
]
end

def negative_failure_message
"expected #{@target.inspect} not to be in Zone #{@expected}"
end
# def negative_failure_message
# "expected #{@target.inspect} not to be in Zone #{@expected}"
# end
end

8 changes: 7 additions & 1 deletion spec/sample_loader.rb
@@ -1,6 +1,6 @@
module SampleLoader
protected
def load_samples(name)
def load_samples(name, &block)
samples_file = File.dirname(__FILE__) + '/samples/' + name
raise ArgumentError, %[no samples file for "#{name}"] unless File.exists? samples_file

Expand Down Expand Up @@ -66,6 +66,12 @@ def load_samples(name)
$stderr.puts "error while processing line #{linenum}"
raise $!
end

if block_given?
@sections.values.each do |samples|
samples.each &block
end
end
end

class Sample
Expand Down

0 comments on commit 7667dea

Please sign in to comment.