Sha256: 1cc6ad7344218a32c0fa1c6a95761905149d9529c23f886a6f381ee98d7ceca8

Contents?: true

Size: 1.33 KB

Versions: 10

Compression:

Stored size: 1.33 KB

Contents

require 'rdf/spec'

RSpec.shared_examples 'an RDF::Countable' do
  include RDF::Spec::Matchers

  let(:statements) {RDF::Spec.quads}
  before do
    raise 'countable must be set with `let(:countable)' unless
      defined? countable

    if countable.empty?
      if (countable.writable? rescue false)
        countable.send(:insert_statements, statements)
      elsif countable.respond_to?(:<<)
        statements.each { |statement| countable << statement }
      else
        raise "+countable+ must respond to #<< or be pre-populated with the" \
              "statements in #{RDF::Spec::TRIPLES_FILE} in a before block"
      end
    end
  end

  describe RDF::Countable do
    subject {countable}

    it {is_expected.to respond_to(:empty?)}
    it {is_expected.to_not be_empty}
    it {is_expected.to respond_to(:count)}
    its(:count) {is_expected.to eq statements.size}
    it {is_expected.to respond_to(:size)}
    its(:size) {is_expected.to eq statements.size}

    context "when empty" do
      subject {[].extend(RDF::Countable)}
      it {is_expected.to be_empty}
      its(:count) {is_expected.to eq 0}
      its(:size) {is_expected.to eq 0}
    end

    its(:to_enum) {is_expected.to be_countable}
    its(:enum_for) {is_expected.to be_countable}
    it "#enum_for(:each)" do
      expect(subject.enum_for(:each)).to be_countable
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
rdf-spec-3.3.0 lib/rdf/spec/countable.rb
rdf-spec-3.2.0 lib/rdf/spec/countable.rb
rdf-spec-3.1.2 lib/rdf/spec/countable.rb
rdf-spec-3.1.1 lib/rdf/spec/countable.rb
rdf-spec-3.1.0 lib/rdf/spec/countable.rb
rdf-spec-3.0.0 lib/rdf/spec/countable.rb
rdf-spec-2.2.0 lib/rdf/spec/countable.rb
rdf-spec-2.2.0.pre.rc1 lib/rdf/spec/countable.rb
rdf-spec-2.0.0 lib/rdf/spec/countable.rb
rdf-spec-2.0.0.beta1 lib/rdf/spec/countable.rb