<commit_before>require File.join(File.dirname(__FILE__), 'spec_helper')
require 'rdf/spec/queryable'

describe RDF::Queryable do
  # @see lib/rdf/spec/queryable.rb in rdf-spec
  it_behaves_like 'an RDF::Queryable' do
    # The available reference implementations are `RDF::Repository` and
    # `RDF::Graph`, but a subclass of Ruby Array implementing
    # `query_pattern` and `query_execute` should do as well
    # FIXME
    let(:queryable) { RDF::Repository.new }
  end

  context "Examples" do
    subject { RDF::Repository.new.insert(*RDF::Spec.quads) }

    context "Querying for statements having a given predicate" do
      it "with array" do
        expect(subject.query([nil, RDF::Vocab::DOAP.developer, nil]).to_a).not_to be_empty
        subject.query([nil, RDF::Vocab::DOAP.developer, nil]) {|s| expect(s).to be_a_statement}
        expect{|b| subject.query([nil, RDF::Vocab::DOAP.developer, nil], &b)}.to yield_control.at_least(1).times
      end
      it "with hash" do
        expect(subject.query(predicate: RDF::Vocab::DOAP.developer).to_a).not_to be_empty
        subject.query(predicate: RDF::Vocab::DOAP.developer) {|s| expect(s).to be_a_statement}
        expect{|b| subject.query(predicate: RDF::Vocab::DOAP.developer, &b)}.to yield_control.at_least(1).times
      end
    end

    context "Querying for solutions from a BGP" do
      it "returns solutions" do
        query = RDF::Query.new {pattern [:s, :p, :o]}
        expect(subject.query(query).to_a).not_to be_empty
        subject.query(query) {|s| expect(s).to be_a RDF::Query::Solution}
        expect{|b| subject.query(query, &b)}.to yield_control.exactly(subject.count).times
      end
    end
  end
end<commit_msg>Checks default `Queryable#query` for dispatching<commit_after>require File.join(File.dirname(__FILE__), 'spec_helper')
require 'rdf/spec/queryable'

describe RDF::Queryable do
  # @see lib/rdf/spec/queryable.rb in rdf-spec
  it_behaves_like 'an RDF::Queryable' do
    # The available reference implementations are `RDF::Repository` and
    # `RDF::Graph`, but a subclass of Ruby Array implementing
    # `query_pattern` and `query_execute` should do as well
    # FIXME
    let(:queryable) { RDF::Repository.new }
  end

  context "Examples" do
    subject { RDF::Repository.new.insert(*RDF::Spec.quads) }

    context "Querying for statements having a given predicate" do
      it "calls #query_pattern" do
        is_expected.to receive(:query_pattern)
        is_expected.not_to receive(:query_execute)
        subject.query([:s, :p, :o]) {}
      end
      it "with array" do
        expect(subject.query([nil, RDF::Vocab::DOAP.developer, nil]).to_a).not_to be_empty
        subject.query([nil, RDF::Vocab::DOAP.developer, nil]) {|s| expect(s).to be_a_statement}
        expect{|b| subject.query([nil, RDF::Vocab::DOAP.developer, nil], &b)}.to yield_control.at_least(1).times
      end
      it "with hash" do
        expect(subject.query(predicate: RDF::Vocab::DOAP.developer).to_a).not_to be_empty
        subject.query(predicate: RDF::Vocab::DOAP.developer) {|s| expect(s).to be_a_statement}
        expect{|b| subject.query(predicate: RDF::Vocab::DOAP.developer, &b)}.to yield_control.at_least(1).times
      end
    end

    context "Querying for solutions from a BGP" do
      let(:query) { query = RDF::Query.new {pattern [:s, :p, :o]} }
      it "calls #query_execute" do
        is_expected.to receive(:query_execute)
        is_expected.not_to receive(:query_pattern)
        subject.query(query) {}
      end

      it "returns solutions" do
        expect(subject.query(query).to_a).not_to be_empty
        subject.query(query) {|s| expect(s).to be_a RDF::Query::Solution}
        expect{|b| subject.query(query, &b)}.to yield_control.exactly(subject.count).times
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.13527712109272394, 'fraction_numerical': 0.0010506960861570791, 'mean_word_length': 3.638246041412911, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7193612', 'n_tokens_mistral': 1322, 'n_tokens_neox': 1282, 'n_words': 284}