<commit_before># Copyright (c) 2015 The Regents of the University of Michigan.
# All Rights Reserved.
# Licensed according to the terms of the Revised BSD License
# See LICENSE.md for details.

require 'bundler/setup'
#Bundler.setup
Bundler.require

$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
require 'dpn/client'

require 'httpclient'
require 'webmock/rspec'
WebMock.disable_net_connect!(allow_localhost: false)
WebMock.disable!

def test_api_root
  "https://test.client.dpn.org"
end

def dpn_url(url)
  url, query = url.split("?")
  api_string = "api-v#{DPN::Client::api_version}"
  if query
    File.join test_api_root, api_string, url, "/?#{query}"
  else
    File.join test_api_root, api_string, url, "/"
  end

end<commit_msg>shared examples for standard operations of dpn-client methods now in spec helper<commit_after># Copyright (c) 2015 The Regents of the University of Michigan.
# All Rights Reserved.
# Licensed according to the terms of the Revised BSD License
# See LICENSE.md for details.

require 'bundler/setup'
#Bundler.setup
Bundler.require

$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
require 'dpn/client'

require 'httpclient'
require 'webmock/rspec'
WebMock.disable_net_connect!(allow_localhost: false)
WebMock.disable!

def test_api_root
  "https://test.client.dpn.org"
end

def dpn_url(url)
  url, query = url.split("?")
  api_string = "api-v#{DPN::Client::api_version}"
  if query
    File.join test_api_root, api_string, url, "/?#{query}"
  else
    File.join test_api_root, api_string, url, "/"
  end
end

shared_examples "a dpn-client method" do |method, *args|
  # expect stub to be defined with let!

  it "sends the right request" do
    agent.public_send(method, *args)
    expect(stub).to have_been_requested
  end

  it "returns a response" do
    response = agent.public_send(method, *args)
    expect(response).to be_a DPN::Client::Response
    expect(response.to_json).to eql(stub.response.body)
  end

  it "calls the block" do
    expect { |probe|
      agent.public_send(method, *args, &probe)
    }.to yield_with_args(be_a(DPN::Client::Response))
  end

  it "yields the response" do
    agent.public_send(method, *args) do |response|
      expect(response.status).to eql(stub.response.status[0])
      expect(response.to_json).to eql(stub.response.body)
    end
  end
end
{'fraction_non_alphanumeric': 0.12030716723549488, 'fraction_numerical': 0.0038395904436860067, 'mean_word_length': 4.329545454545454, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '2182360', 'n_tokens_mistral': 815, 'n_tokens_neox': 807, 'n_words': 216}