Sha256: 918db4a7d01843ab45b614505d7f5f19c1d055d2d9818c62a5782d372ab33d37

Contents?: true

Size: 1.83 KB

Versions: 10

Compression:

Stored size: 1.83 KB

Contents

# coding: utf-8
$:.unshift "."
require 'spec_helper'
require 'rdf/spec/format'

describe JSON::LD::Format do
  before :each do
    @format_class = JSON::LD::Format
  end

  it_should_behave_like RDF_Format

  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::Format.for(arg).should == @format_class
      end
    end

    {
      :jsonld   => '{"@context" => "foo"}',
      :context  => %({\n"@context": {),
      :id       => %({\n"@id": {),
      :type     => %({\n"@type": {),
    }.each do |sym, str|
      it "detects #{sym}" do
        @format_class.for {str}.should == @format_class
      end
    end

    it "should discover 'jsonld'" do
      RDF::Format.for(:jsonld).reader.should == JSON::LD::Reader
    end
  end

  describe "#to_sym" do
    specify {@format_class.to_sym.should == :jsonld}
  end

  describe ".detect" do
    {
      :jsonld => '{"@context" => "foo"}',
    }.each do |sym, str|
      it "detects #{sym}" do
        @format_class.detect(str).should be_true
      end
    end

    {
      :n3             => "@prefix foo: <bar> .\nfoo:bar = {<a> <b> <c>} .",
      :nquads => "<a> <b> <c> <d> . ",
      :rdfxml => '<rdf:RDF about="foo"></rdf:RDF>',
      :rdfa   => '<div about="foo"></div>',
      :microdata => '<div itemref="bar"></div>',
      :ntriples         => "<a> <b> <c> .",
      :multi_line       => '<a>\n  <b>\n  "literal"\n .',
      :turtle           => "@prefix foo: <bar> .\n foo:a foo:b <c> .",
    }.each do |sym, str|
      it "does not detect #{sym}" do
        @format_class.detect(str).should be_false
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
json-ld-0.3.1 spec/format_spec.rb
json-ld-0.3.0 spec/format_spec.rb
json-ld-0.1.6.1 spec/format_spec.rb
json-ld-0.1.6 spec/format_spec.rb
json-ld-0.1.5.2 spec/format_spec.rb
json-ld-0.1.5.1 spec/format_spec.rb
json-ld-0.1.5 spec/format_spec.rb
json-ld-0.1.4.2 spec/format_spec.rb
json-ld-0.1.4.1 spec/format_spec.rb
json-ld-0.1.4 spec/format_spec.rb