<commit_before>require 'spec_helper'
require 'rack/test'
require 'sinatra/base'

class StubApp < Sinatra::Base
  before do
    content_type :json
  end

  get "/" do
    { :hello => "world" }.to_json
  end

  post "/greet" do
    request.body.rewind
    data = JSON.parse request.body.read
    { :hello => data["target"] }.to_json
  end
end

describe RspecApiDocumentation::TestClient do
  include Rack::Test::Methods

  let(:app) { StubApp }
  let(:test_client) { RspecApiDocumentation::TestClient.new(self) }

  subject { test_client }

  it { should be_a(RspecApiDocumentation::TestClient) }

  its(:session) { should equal(self) }
  its(:example) { should equal(example) }
  its(:metadata) { should equal(example.metadata) }

  describe "#last_response" do
    before do
      test_client.get "/"
    end

    it "should expose the last request" do<commit_msg>Update test client app for JSON failures<commit_after>require 'spec_helper'
require 'rack/test'
require 'sinatra/base'

class StubApp < Sinatra::Base
  before do
    content_type :json
  end

  get "/" do
    { :hello => "world" }.to_json
  end

  post "/greet" do
    request.body.rewind
    begin
      data = JSON.parse request.body.read
    rescue JSON::ParserError
      request.body.rewind
      data = request.body.read
    end
    { :hello => data["target"] }.to_json
  end
end

describe RspecApiDocumentation::TestClient do
  include Rack::Test::Methods

  let(:app) { StubApp }
  let(:test_client) { RspecApiDocumentation::TestClient.new(self) }

  subject { test_client }

  it { should be_a(RspecApiDocumentation::TestClient) }

  its(:session) { should equal(self) }
  its(:example) { should equal(example) }
  its(:metadata) { should equal(example.metadata) }

  describe "#last_response" do
    before do
      test_client.get "/"
    end

    it "should expose the last request" do
{'fraction_non_alphanumeric': 0.11660397635679742, 'fraction_numerical': 0.0, 'mean_word_length': 3.5304136253041363, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2326400', 'n_tokens_mistral': 625, 'n_tokens_neox': 605, 'n_words': 150}