Sha256: 05251e123b11eedfcaab688bf196c2f522fa894ef6ece1710e3349725604e1a2

Contents?: true

Size: 804 Bytes

Versions: 11

Compression:

Stored size: 804 Bytes

Contents

require 'stringio'
require 'kramdown'

describe "README.md code snippet" do
  let(:code_blocks) do
    markdown = File.read(File.expand_path(File.dirname(__FILE__) + '/../README.md'))
    parse_ruby_from(markdown)
  end

  it "executes with the expected output" do
    code, output = *code_blocks
    expect(execute_ruby(code)).to eq output
  end

  def execute_ruby(code)
    capture_stdout do
      eval code, binding
    end
  end

  def parse_ruby_from(markdown)
    code_blocks = Kramdown::Parser::GFM.parse(markdown).first.children.select { |e| e.type == :codeblock }.map(&:value)
    expect(code_blocks).not_to be_empty
    code_blocks
  end

  def capture_stdout
    original = $stdout
    $stdout = StringIO.new
    yield
    result = $stdout.string
    $stdout = original
    result
  end

end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
cucumber-core-1.5.0 spec/readme_spec.rb
cucumber-core-1.4.0 spec/readme_spec.rb
cucumber-core-1.3.1 spec/readme_spec.rb
cucumber-core-1.3.0 spec/readme_spec.rb
cucumber-core-1.2.0 spec/readme_spec.rb
cucumber-core-1.1.3 spec/readme_spec.rb
cucumber-core-1.1.2 spec/readme_spec.rb
cucumber-core-1.1.1 spec/readme_spec.rb
cucumber-core-1.1.0 spec/readme_spec.rb
cucumber-core-1.0.0 spec/readme_spec.rb
cucumber-core-1.0.0.beta.4 spec/readme_spec.rb