RSpec match_result

Feed input to a block and match result against expected value

Overview

require "json"

require "rspec/match_result"

describe "JSON.parse" do
  it "generally works" do
    sets = [
      ["", [JSON::ParserError, /two octets/]],
      ["xyz", [JSON::ParserError, /unexpected token/]],
      ['{"x":"y"}', {"x" => "y"}],
      ['{"ar":[1.2,3.4]}', {"ar" => [1.2, 3.4]}],
    ]

    sets.each do |input, expected|
      match_result(input, expected) {JSON.parse(input)}
    end
  end
end

Full documentation is available at rubydoc.info.

Setup

This project is a sub. Sub setup example is available here.

For more info on subs, click here.

Cheers!

— Alex Fortuna, © 2015