# coding: utf-8 $:.unshift "." require 'spec_helper' require 'rdf/spec/reader' describe JSON::LD::Reader do before :each do @reader = JSON::LD::Reader.new(StringIO.new("")) end include RDF_Reader describe ".for" do formats = [ :jsonld, "etc/doap.jsonld", {:file_name => 'etc/doap.jsonld'}, {:file_extension => 'jsonld'}, {:content_type => 'application/ld+json'}, {:content_type => 'application/x-ld+json'}, ].each do |arg| it "discovers with #{arg.inspect}" do RDF::Reader.for(arg).should == JSON::LD::Reader end end end context :interface do subject { %q({ "@context": {"foaf": "http://xmlns.com/foaf/0.1/"}, "@id": "_:bnode1", "@type": "foaf:Person", "foaf:homepage": "http://example.com/bob/", "foaf:name": "Bob" }) } describe "#initialize" do it "yields reader given string" do inner = mock("inner") inner.should_receive(:called).with(JSON::LD::Reader) JSON::LD::Reader.new(subject) do |reader| inner.called(reader.class) end end it "yields reader given IO" do inner = mock("inner") inner.should_receive(:called).with(JSON::LD::Reader) JSON::LD::Reader.new(StringIO.new(subject)) do |reader| inner.called(reader.class) end end it "returns reader" do JSON::LD::Reader.new(subject).should be_a(JSON::LD::Reader) end end describe "#each_statement" do it "yields statements" do inner = mock("inner") inner.should_receive(:called).with(RDF::Statement).exactly(3) JSON::LD::Reader.new(subject).each_statement do |statement| inner.called(statement.class) end end end describe "#each_triple" do it "yields statements" do inner = mock("inner") inner.should_receive(:called).exactly(3) JSON::LD::Reader.new(subject).each_triple do |subject, predicate, object| inner.called(subject.class, predicate.class, object.class) end end end end end