# spec/support/request_helpers.rb
module Requests
module JsonHelpers
def json
JSON.parse(response.body)
end
end
end
# spec_helper.rb
RSpec.configure do |config|
# ... The rest of your RSpec config.
config.include Requests::JsonHelpers, type: :request
end
# spec file
describe "..." do
it '....' do
get "/api/v1/..."
# test for the 200 status-code
expect(response).to be_success
# check that the message attributes are the same.
expect(json['content']).to eq(message.content)
# ensure that private attributes aren't serialized
expect(json['private_attr']).to eq(nil)
end
end