Skip to content

jsl/be_valid_json

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

be_valid_json

Makes available method be_valid_json to check to see if a string is valid JSON or not without clouding specs with exception handling code.

Installation

Just copy be_valid_json.rb under the ‘lib’ folder to your rspec matchers folder, and include it in your spec_helper. Some Rails programmers follow a convention where custom matchers are put in a folder under the project root called ‘spec/support/matchers’, and be_valid_json.rb could be put in that folder.

In order to make the methods provided available in your specs, include the matcher library with something like the following line (which pulls in all code under ‘support/matchers’):

Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f}

Basic Usage

it "should detect valid json" do
  "foo".should_not be_valid_json
end

it "should detect invalid json" do
  {:a => :b}.to_json.should be_valid_json
end

Authors

Justin Leitgeb

About

Rspec custom matcher for detecting if a string is valid json or not.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages