File: spec_helper.rb

package info (click to toggle)
ruby-redcloth 4.3.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 708 kB
  • sloc: ruby: 1,233; ansic: 201; makefile: 25
file content (36 lines) | stat: -rw-r--r-- 1,022 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
$:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
require 'redcloth'
require 'yaml'
  
def 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)
        expect(output).to eq(doc[formatter])
      end
    else
      example("should not raise errors when rendering #{formatter} for #{name}") do
        expect { method("format_as_#{formatter}").call(doc) }.not_to raise_error
      end
    end
  end
end

def 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_stream(File.open(testfile)) do |doc|
      name = doc['name'] || num
      @fixtures["#{testgroup} #{name}"] = doc
      num += 1
    end
  end
  @fixtures
end