• Stars
    star
    169
  • Rank 216,601 (Top 5 %)
  • Language
    Ruby
  • License
    MIT License
  • Created about 11 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

RSpec matcher for testing JSON string

RSpec::JsonMatcher

test

This library provides RSpec matcher for testing JSON string.

  • parsing a given value as JSON string
  • handy pattern matching with #=== method like case-when statement
  • supporting nested pattern matching

Installation

Install the gem and add to the application's Gemfile by executing:

$ bundle add rspec-json_matcher

If bundler is not being used to manage dependencies, install the gem by executing:

$ gem install rspec-json_matcher

Usage

Configuration

# spec/spec_helper.rb
require "rspec/json_matcher"
RSpec.configuration.include RSpec::JsonMatcher

Matchers

  • be_json
  • be_json_including
  • be_json_as
{ "a" => "b", "c" => "d" }.to_json.should be_json
{ "a" => "b", "c" => "d" }.to_json.should be_json_including("a" => "b")
{ "a" => "b", "c" => "d" }.to_json.should be_json_as("a" => "b", "c" => "d")

Example

[
  {
    "url" => "https://api.github.com/gists/17a07d0a27fd3f708f5f",
    "id" => "1",
    "description" => "description of gist",
    "public" => true,
    "user" => {
      "login" => "octocat",
      "id" => 1,
      "avatar_url" => "https://github.com/images/error/octocat_happy.gif",
      "gravatar_id" => "somehexcode",
      "url" => "https://api.github.com/users/octocat"
    },
    "files" => {
      "ring.erl" => {
        "size" => 932,
        "filename" => "ring.erl",
        "raw_url" => "https://gist.github.com/raw/365370/8c4d2d43d178df44f4c03a7f2ac0ff512853564e/ring.erl"
      }
    },
    "comments" => 0,
    "comments_url" => "https://api.github.com/gists/6fb6af8cb6e26dbbc327/comments/",
    "html_url" => "https://gist.github.com/1",
    "git_pull_url" => "git://gist.github.com/1.git",
    "git_push_url" => "[email protected]:1.git",
    "created_at" => "2010-04-14T02:15:15Z"
  }
].to_json.should be_json_as([
  {
    "url"          => /^https:/,
    "id"           => /^\d+$/,
    "description"  => /gist/,
    "public"       => true,
    "user"         => Hash,
    "files"        => Hash,
    "comments"     => Fixnum,
    "comments_url" => /^https:/,
    "html_url"     => /^https:/,
    "git_pull_url" => /^git:/,
    "git_push_url" => /^git@/,
    "created_at"   => /^\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\dZ/,
  }
])

Failure message

More Repositories

1

ruboty

Ruby + Bot = Ruboty
Ruby
460
star
2

autodoc

Generate documentation from your rack application & request-spec.
Ruby
373
star
3

rspec-request_describer

An RSpec plugin to write self-documenting request-specs.
Ruby
172
star
4

altria

Casual CI server
Ruby
144
star
5

weak_parameters

Validates params in your controller.
Ruby
144
star
6

view_source_map

Rails plugin to embed template path as HTML comment.
Ruby
128
star
7

rack-json_schema

JSON Schema based Rack middlewares
Ruby
127
star
8

yattecast

Podcastサイトをつくるためのテンプレート
SCSS
102
star
9

webtail

Stdin to your browser by WebSocket
JavaScript
95
star
10

katatema

A handy static site generator using React.js
JavaScript
95
star
11

jdoc

Generate API documentation from JSON Schema.
Ruby
92
star
12

retro-twitter-client

A retro twitter client.
JavaScript
86
star
13

mastodon-terraform

Boilerplate for running Mastodon on AWS using Terraform and CircleCI.
HCL
84
star
14

replicat

master-slave replication helper for ActiveRecord.
Ruby
81
star
15

amazon_url_shortener

Chrome extension to automatically shorten Amazon product URL.
Shell
80
star
16

gospel

BDD-style testing library for Golang
Go
76
star
17

scheman

SQL schema parser.
Ruby
74
star
18

json_world

Provides DSL to define JSON Schema representation of your class.
Ruby
74
star
19

guideline

The guideline of your code
Ruby
71
star
20

markdiff

Rendered Markdown differ.
Ruby
71
star
21

danger-suggester

A Danger plug-in to suggest code changes through inline comments in pull requests.
Ruby
68
star
22

github-stream

Stream notifications on GitHub
JavaScript
67
star
23

sitespec

Generate static site from your rack application & test files
Ruby
60
star
24

response_code_matchers

Provide rspec matchers to match http response code
Ruby
58
star
25

awesome-fantasy

A collection of awesome FinalFantasy-ish libraries, tools, frameworks and software.
57
star
26

chrono

A chain of logics about chronology.
Ruby
52
star
27

gig

A blog application using GitHub as a data store.
JavaScript
52
star
28

dotfiles

A chain of configurations for my workstation.
Shell
51
star
29

gialog

Blog template to use GitHub Issues as article editor.
TypeScript
50
star
30

code_hunter

Hunt out weak spots in your rails application
Ruby
46
star
31

somemoji

A grand unified emoji mapper for some emoji providers.
Ruby
45
star
32

chatroid

Chatterbot builder
Ruby
45
star
33

rubocop-migration

RuboCop extension focused on ActiveRecord migration.
Ruby
41
star
34

docomoru

Client library for docomo API written in Ruby.
Ruby
37
star
35

syoboi_calendar

An API Client library for http://cal.syoboi.jp/ written in Ruby.
Ruby
36
star
36

slimcop

RuboCop runner for Slim template.
Ruby
36
star
37

mmd.js

A project to work MMD in a web browser with client-side JavaScript.
CoffeeScript
36
star
38

weneedfeed

Generate feeds from URL and selectors.
Ruby
35
star
39

activerecord-belongs_to_if

Allows you to manage preload condition by :if condition.
Ruby
35
star
40

xrc

XMPP Ruby Client.
Ruby
35
star
41

jsonism

Generate HTTP Client from JSON Schema.
Ruby
35
star
42

ruboty-template

A template to create and deploy your ruboty on slack.
Ruby
34
star
43

rucoa

Language server for Ruby.
Ruby
33
star
44

mio

MicroBlog for Laboratory.
JavaScript
33
star
45

conditional_counter_cache

Give condition when to increment/decrement counter cache.
Ruby
32
star
46

rapa

An API client library for Amazon Product Advertising API, written in Ruby.
Ruby
32
star
47

kamo.js

A library to control event streams on Functional Reactive Programming model.
JavaScript
30
star
48

restaurant

A rails plugin to auto-define RESTful API
Ruby
29
star
49

r7kamura.com

The source of r7kamura.com.
29
star
50

plz

JSON Schema based command line HTTP client.
Ruby
29
star
51

markless

Markless is a WYSIWYG editor library, which supports Markdown key-binding.
JavaScript
28
star
52

ruboty-slack

Slack adapter for Ruboty.
Ruby
27
star
53

editabro

エディタブ郎
TypeScript
27
star
54

nyanko

Nyanko is a Rails extension framework deeply inspired from Chanko
Ruby
26
star
55

ruboty-cron

Mount cron system to Ruboty to schedule messages on a specific time.
Ruby
25
star
56

ruboty-github

Manage GitHub via Ruboty.
Ruby
25
star
57

streamer

Stream twitter, 2ch, hatebu, and AnyStreams inTerminal
Ruby
25
star
58

key-string

Detect keyboard event type from KeyboardEvent.
JavaScript
25
star
59

split-tests-by-timings

GitHub Action to split test files based on JUnit XML reports.
24
star
60

vscode-ruby-light

Lightweight VSCode extension for Ruby.
TypeScript
24
star
61

mem

Memoize any method call.
Ruby
23
star
62

works

過去につくったもの
23
star
63

vagrant-multiplug

Vagrant plug-in to manage plug-in dependencies.
Ruby
22
star
64

iremocon

Iremocon is a gem for managing iRemocon through telnet
Ruby
21
star
65

activerecord-enum_translation

Provides integration between ActiveRecord::Enum and I18n.
Ruby
21
star
66

taglog

Taggable logger extension
Ruby
21
star
67

draft-js-markless-plugin

A plugin for draft-js that allows you to create an WYSIWYG editor that supports Markdown-like keybinding.
JavaScript
21
star
68

copy-rich-link

Browser extension to copy the page title and URL as rich text.
TypeScript
20
star
69

scheman-rails

Rails plugin for Scheman.
Ruby
19
star
70

stackable-fetcher

A middleware-based HTTP client library.
JavaScript
19
star
71

rubocop-todo-corrector

Custom action to create a pull request that autocorrects offenses in .rubocop_todo.yml per cop.
18
star
72

volatile_counter_cache

Provides volatile counter cache logic to ActiveRecord::Base.
Ruby
18
star
73

amazon-api-gateway-client

A client library for Amazon API Gateway.
JavaScript
18
star
74

google-docs-to-github

Custom action to export Google Docs to GitHub.
18
star
75

rails_kwargs_testing

Provides Rails 5 compatible testing methods for gradual migration from Rails 4 to 5.
Ruby
18
star
76

zircon

IRC client library written in Pure Ruby
Ruby
17
star
77

rack-multiplexer

Provides a simple router & dispatcher for Rack applications as a Rack application.
Ruby
17
star
78

aws-signer-v4

Create AWS Signature v4 from request information and credentials.
JavaScript
17
star
79

github-label-sync-action

Sync GitHub Labels with labels definition file.
17
star
80

nes8

A NES emulator written in TypeScript.
TypeScript
17
star
81

fluct-example

An example application using fluct.
JavaScript
15
star
82

entoverse

A library to implement host-based HTTP reverse-proxy in Golang.
Go
15
star
83

cssspec

Generates style guide from stylesheets.
Ruby
15
star
84

yardspec

Run YARD as RSpec.
Ruby
15
star
85

rubocop-problem-matchers-action

GitHub Action to setup Problem Matchers for RuboCop.
JavaScript
14
star
86

ruboty-talk

Talk with you if given message didn't match any other handlers.
Ruby
14
star
87

godolog

Blog template to use Google Docs as article editor.
JavaScript
14
star
88

cycle-fetcher-driver

A Cycle.js Driver for making HTTP requests using fetcher.
JavaScript
14
star
89

faraday-lazyable

A request is never sent till a response have need.
Ruby
14
star
90

kyubey

MinimalSlideTool made by HTML/CSS/JS
JavaScript
13
star
91

rust-problem-matchers

GitHub Action to setup Problem Matchers for Rust.
JavaScript
13
star
92

chiver

a simple archive system using sinatra and markdown
JavaScript
13
star
93

json-encodable

Make a class encodable into JSON format.
Ruby
12
star
94

obs-browser-sources

12
star
95

api-gateway-lambda-example

An example application to integrate Amazon API Gateway and Amazon Lambda.
JavaScript
12
star
96

bump-request

Custom action to create a pull request that bumps version.
12
star
97

bobot

Ruboty on somewhere
Ruby
12
star
98

swagger_parser

Swagger schema parser.
Ruby
12
star
99

rack-mongoid

Provides RESTful interface for MongoDB as a rack middleware.
Ruby
12
star
100

cssdoc

CSS styleguide generator
CSS
12
star