Today I Learned

How to use post/response in an RSpec matcher

In request specs post/response helpers are available:

post '/graphql', params: { query: query }
json = JSON.parse(response.body)

If you want to use them in a custom matcher, you have to include ActionDispatch::Integration::Runner and define you app:

class TheBestMatcherEverCreated
  include ActionDispatch::Integration::Runner

  # typical matcher's methods omitted for brevity

  def my_best_method
    post '/graphql', params: { query: query }
    JSON.parse(response.body)
  end

  private

  def app
    Rails.application
  end
end