<commit_before>begin 
  require_relative 'spec_helper'
rescue NameError
  require File.expand_path('spec_helper', __FILE__)
end

require File.expand_path('../../lib/mock_server/playback', __FILE__)
require File.expand_path('../../lib/mock_server/spec/helpers', __FILE__)

describe "Playback" do
  include Rack::Test::Methods
  include MockServer::Spec::Helpers

  def app
    MockServer::Playback.new( nil, {
      :path => File.dirname(__FILE__) + '/fixtures',
      :record_filenames => ['records'],
      :routes => [ '/**' ] })
  end

  it "return the response" do
    mock_server_get('/hello.json')

    get '/hello.json'

    assert_equal 'world', last_response.body
  end

  it "match request with query params" do
    mock_server_get('/query.json') do |request, recorded_request|
      request.query == recorded_request.query and
      recorded_request.query == 'with=params'
    end

    get '/query.json?with=params'
    assert_equal 'with params', last_response.body
  end

  it "match request with body" do
    mock_server_post('/body.json') do |request, recorded_request|
      request.body == recorded_request.body and
      recorded_request.body == 'with=body'
    end

    post '/body.json', 'with=body'
    assert_equal 'success post with body', last_response.body
  end

  it "parse request with json body" do
    mock_server_post('/json.json') do |request, recorded_request|
      request.body == recorded_request.body and
      recorded_request.body.name == 'test'
    end

    post '/json.json', '{"name":"test"}'
    assert_equal 'success post with body', last_response.body
  end

end<commit_msg>Add spec for recoreded_response<commit_after>begin 
  require_relative 'spec_helper'
rescue NameError
  require File.expand_path('spec_helper', __FILE__)
end

require File.expand_path('../../lib/mock_server/playback', __FILE__)
require File.expand_path('../../lib/mock_server/spec/helpers', __FILE__)

describe "Playback" do
  include Rack::Test::Methods
  include MockServer::Spec::Helpers

  def app
    MockServer::Playback.new( nil, {
      :path => File.dirname(__FILE__) + '/fixtures',
      :record_filenames => ['records'],
      :routes => [ '/**' ] })
  end

  it "return the response" do
    mock_server_get('/hello.json')

    get '/hello.json'

    assert_equal 'world', last_response.body
  end

  it "match request with query params" do
    mock_server_get('/query.json') do |request, recorded_request|
      request.query == recorded_request.query and
      recorded_request.query == 'with=params'
    end

    get '/query.json?with=params'
    assert_equal 'with params', last_response.body
  end

  it "match request with body" do
    mock_server_post('/body.json') do |request, recorded_request|
      request.body == recorded_request.body and
      recorded_request.body == 'with=body'
    end

    post '/body.json', 'with=body'
    assert_equal 'success post with body', last_response.body
  end

  it "parse request with json body" do
    mock_server_post('/json.json') do |request, recorded_request|
      request.body == recorded_request.body and
      recorded_request.body.name == 'test'
    end

    post '/json.json', '{"name":"test"}'
    assert_equal 'success post with body', last_response.body
  end

  it "pass the parse recorded response and pass it to the matcher block" do
    mock_server_get('/json_response.json') do |request, recorded_request, recorded_response|
      recorded_response.body.json == 'content'
    end

    get '/json_response.json'
    assert_equal '{"json":"content"}', last_response.body
  end

end
{'fraction_non_alphanumeric': 0.12444071588366891, 'fraction_numerical': 0.0, 'mean_word_length': 3.6454545454545455, 'pattern_counts': {'":': 3, '<': 3, '<?xml version=': 0, '>': 9, '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': '2447404', 'n_tokens_mistral': 1105, 'n_tokens_neox': 1084, 'n_words': 276}