<commit_before>require File.join(File.dirname(__FILE__), 'spec_helper')

describe SPARQL::Client do
  describe "when querying" do
    before(:each) do
      @client = SPARQL::Client.new('http://data.linkedmdb.org/sparql')
      @query = 'DESCRIBE ?kb WHERE  { ?kb <http://data.linkedmdb.org/resource/movie/actor_name> "<NAME>" . }'
    end

    def response(header)
      response = Net::HTTPSuccess.new '1.1', 200, 'body'
      response.content_type = header
      response.stub!(:body).and_return('body')
      response
    end

    it "should handle successful response with plain header" do
      @client.should_receive(:get).and_yield response('text/plain')
      RDF::Reader.should_receive(:for).with(:content_type=>'text/plain')
      @client.query(@query)
    end

    it "should handle successful response with boolean header" do
      @client.should_receive(:get).and_yield response(SPARQL::Client::RESULT_BOOL)
      @client.query(@query).should == false
    end

    it "should handle successful response with json header" do
      @client.should_receive(:get).and_yield response(SPARQL::Client::RESULT_JSON)
      @client.should_receive(:parse_json_bindings)
      @client.query(@query)
    end

    it "should handle successful response with xml header" do
      @client.should_receive(:get).and_yield response(SPARQL::Client::RESULT_XML)
      @client.should_receive(:parse_xml_bindings)
      @client.query(@query)
    end

    it "should handle successful response with overridden xml header" do
      @client.should_receive(:get).and_yield response(SPARQL::Client::RESULT_XML)
      @client.should_receive(:parse_json_bindings)
      @client.query(@query, :content_type=>SPARQL::Client::RESULT_JSON)
    end

    it "should handle successful response with overridden plain header" do
      @client.should_receive(:get).and_yield response('text/plain')
      RDF::Reader.should_receive(:for).with(:content_type=>'text/turtle')
      @client.query(@query, :content_type=>'text/turtle')
    end
  end
end<commit_msg>Accept header should be overridden when content-type is set explicitly.<commit_after>require File.join(File.dirname(__FILE__), 'spec_helper')

describe SPARQL::Client do
  describe "when querying" do
    before(:each) do
      @client = SPARQL::Client.new('http://data.linkedmdb.org/sparql')
      @query = 'DESCRIBE ?kb WHERE  { ?kb <http://data.linkedmdb.org/resource/movie/actor_name> "<NAME>" . }'
    end

    def response(header)
      response = Net::HTTPSuccess.new '1.1', 200, 'body'
      response.content_type = header
      response.stub!(:body).and_return('body')
      response
    end

    it "should handle successful response with plain header" do
      @client.should_receive(:get).and_yield response('text/plain')
      RDF::Reader.should_receive(:for).with(:content_type=>'text/plain')
      @client.query(@query)
    end

    it "should handle successful response with boolean header" do
      @client.should_receive(:get).and_yield response(SPARQL::Client::RESULT_BOOL)
      @client.query(@query).should == false
    end

    it "should handle successful response with json header" do
      @client.should_receive(:get).and_yield response(SPARQL::Client::RESULT_JSON)
      @client.should_receive(:parse_json_bindings)
      @client.query(@query)
    end

    it "should handle successful response with xml header" do
      @client.should_receive(:get).and_yield response(SPARQL::Client::RESULT_XML)
      @client.should_receive(:parse_xml_bindings)
      @client.query(@query)
    end

    it "should handle successful response with overridden xml header" do
      @client.should_receive(:get).and_yield response(SPARQL::Client::RESULT_XML)
      @client.should_receive(:parse_json_bindings)
      @client.query(@query, :content_type=>SPARQL::Client::RESULT_JSON)
    end

    it "should handle successful response with overridden json header" do
      @client.should_receive(:get).and_yield response(SPARQL::Client::RESULT_JSON)
      @client.should_receive(:parse_xml_bindings)
      @client.query(@query, :content_type=>SPARQL::Client::RESULT_XML)
    end

    it "should handle successful response with overridden plain header" do
      @client.should_receive(:get).and_yield response('text/plain')
      RDF::Reader.should_receive(:for).with(:content_type=>'text/turtle')
      @client.query(@query, :content_type=>'text/turtle')
    end
  end
end
{'fraction_non_alphanumeric': 0.12434762877240753, 'fraction_numerical': 0.002269117313365101, 'mean_word_length': 4.155555555555556, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 7}, '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': '468313', 'n_tokens_mistral': 1385, 'n_tokens_neox': 1318, 'n_words': 272}