Sha256: 96ca25b6c49a4f37bbba8aa14802afb64ac8c51d666e04adf4ef97c3c272a08d

Contents?: true

Size: 1.21 KB

Versions: 4

Compression:

Stored size: 1.21 KB

Contents

require 'rdf/spec'

module RDF_Countable
  extend RSpec::SharedContext
  include RDF::Spec::Matchers

  before :each do
    raise '+@countable+ must be defined in a before(:each) block' unless instance_variable_get('@countable')

    @statements = RDF::Spec.quads

    if @countable.empty?
      if @countable.respond_to?(:<<) && (@countable.writable? rescue true)
        @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(:each) block"
      end
    end
  end

  describe RDF::Countable do
    subject {@countable}

    it {should respond_to(:empty?)}
    it {should_not be_empty}
    it {should respond_to(:count)}
    its(:count) {should == @statements.size}
    it {should respond_to(:size)}
    its(:size) {should == @statements.size}

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

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rdf-spec-1.1.3 lib/rdf/spec/countable.rb
rdf-spec-1.1.0 lib/rdf/spec/countable.rb
rdf-spec-1.1.0p4 lib/rdf/spec/countable.rb
rdf-spec-1.0.9 lib/rdf/spec/countable.rb