waterlink / rspec-json_expectations

Set of matchers and helpers to allow you test your APIs responses like a pro.
https://www.relishapp.com/waterlink/rspec-json-expectations/docs
MIT License
140 stars 23 forks source link

Support all aliased RSpec expectations #18

Closed FranklinYu closed 7 years ago

FranklinYu commented 8 years ago

RSpec expectation is supported, but not all their aliases:

require 'rspec/json_expectations'

describe 'sample' do
  it 'passes with original matcher' do
    json = '{"foo":"bar"}'
    expect(json).to include_json(
      foo: be_a_kind_of(String)
    )
  end

  it 'should have succeeded' do
    expect('bar').to a_kind_of(String)
  end

  it 'fails' do
    json = '{"foo":"bar"}'
    expect(json).to include_json(
      foo: a_kind_of(String)
    )
  end
end

Here a_kind_of is an alias of be_a_kind_of. I find the noun-phrase aliases fit better here. Notably be_kind_of, another alias of be_a_kind_of, is supported. Any reason to reject the noun-phrase?

JanStevens commented 8 years ago

Also finding this a bit annoying, small hack around it

In json_traverser.rb

12: RSPECMATCHERS = defined?(RSpec::Matchers) ? [RSpec::Matchers::BuiltIn::BaseMatcher, RSpec::Matchers::AliasedMatcher] : []
99: return nil unless expected.is_a?(RSpec::Matchers::BuiltIn::BaseMatcher) ||
            expected.is_a?(RSpec::Matchers::AliasedMatcher)

Seems to work fine now