Sha256: e1e7a37cddef4c35c902538835adeb069a7ab228fc543e2029865f92f4f503f1

Contents?: true

Size: 1.21 KB

Versions: 12

Compression:

Stored size: 1.21 KB

Contents

$:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
require 'redcloth'
require 'yaml'

class FormatterExampleGroup < Spec::Example::ExampleGroup
  
  def self.examples_from_yaml(&block)
    formatter = description.downcase
    define_method("format_as_#{formatter}", &block)
    
    fixtures.each do |name, doc|
      if doc[formatter]
        example("should output #{formatter} for #{name}") do
          output = method("format_as_#{formatter}").call(doc)
          output.should == doc[formatter]
        end
      else
        example("should not raise errors when rendering #{formatter} for #{name}") do
          lambda { method("format_as_#{formatter}").call(doc) }.should_not raise_error
        end
      end
    end
  end
  
  def self.fixtures
    return @fixtures if @fixtures
    @fixtures = {}
    Dir[File.join(File.dirname(__FILE__), *%w[fixtures *.yml])].each do |testfile|
      testgroup = File.basename(testfile, '.yml')
      num = 0
      YAML::load_documents(File.open(testfile)) do |doc|
        name = doc['name'] || num
        @fixtures["#{testgroup} #{name}"] = doc
        num += 1
      end
    end
    @fixtures
  end
  
end

Spec::Example::ExampleGroupFactory.register(:formatter, FormatterExampleGroup)

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
RedCloth-4.2.3-x86-mswin32-60 spec/spec_helper.rb
RedCloth-4.2.3-universal-java spec/spec_helper.rb
RedCloth-4.2.3 spec/spec_helper.rb
RedCloth-4.2.2-x86-mswin32-60 spec/spec_helper.rb
RedCloth-4.2.2-universal-java spec/spec_helper.rb
RedCloth-4.2.1-x86-mswin32-60 spec/spec_helper.rb
RedCloth-4.2.1-universal-java spec/spec_helper.rb
RedCloth-4.2.1 spec/spec_helper.rb
RedCloth-4.2.2 spec/spec_helper.rb
RedCloth-4.2.0 spec/spec_helper.rb
RedCloth-4.2.0-x86-mswin32-60 spec/spec_helper.rb
RedCloth-4.2.0-universal-java spec/spec_helper.rb