michael-ken 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/spec/spec.opts DELETED
@@ -1,3 +0,0 @@
1
- --colour
2
- --loadby random
3
- --backtrace
data/spec/spec_helper.rb DELETED
@@ -1,40 +0,0 @@
1
- require 'pathname'
2
- require 'rubygems'
3
- require 'spec'
4
- require 'json'
5
-
6
- SPEC_ROOT = Pathname(__FILE__).dirname.expand_path
7
- require SPEC_ROOT.parent + 'lib/ken'
8
-
9
- def load_fixture(fixture_name)
10
- fname = "#{File.dirname(__FILE__)}/fixtures/#{fixture_name}.json"
11
- unless File.exists?(fname)
12
- open(fname, "w") do |file|
13
- puts "WARNING: Fixtures could not be loaded."
14
- end
15
- end
16
- JSON.parse open(fname,"r").read
17
- end
18
-
19
- # this will append a <br /> to every logged message, which produces
20
- # nicely formatted DataMapper debug outputs in Textmate's RSpec Bundle's output
21
- module Ken
22
- class Logger
23
- def prep_msg(message, level)
24
- level << delimiter << message << "<br/>"
25
- end
26
- end
27
- end
28
-
29
- # debugging helper (textmate rspec bundle)
30
- # TODO remove before release
31
- ESCAPE_TABLE = { '&'=>'&amp;', '<'=>'&lt;', '>'=>'&gt;', '"'=>'&quot;', "'"=>'&#039;', }
32
- def h(value)
33
- value.to_s.gsub(/[&<>"]/) {|s| ESCAPE_TABLE[s] }
34
- end
35
-
36
- Spec::Runner.configure do |config|
37
- config.after(:all) do
38
-
39
- end
40
- end
@@ -1,50 +0,0 @@
1
- require 'pathname'
2
-
3
- require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
4
-
5
- describe Ken::Attribute do
6
- before :all do
7
- Ken::Logger.new(STDOUT, :info)
8
- Ken::Session.new('http://www.freebase.com', 'ma', 'xxxxx')
9
- data = load_fixture('the_police')
10
- @the_police = Ken::Resource.new(data)
11
-
12
- @attribute = @unique_value_attribute = @the_police.attributes[2] # /music/artist/active_start
13
- @unique_object_attribute = @the_police.attributes[11] # /music/artist/origin
14
- @non_unique_value_attribute = @the_police.attributes[8] # /common/topic/alias
15
- @non_unique_object_attribute = @the_police.attributes[4] # /music/artist/album
16
- end
17
-
18
- it "should have values" do
19
- @attribute.values.should_not be_nil
20
- end
21
-
22
- describe "with unique value type" do
23
- it "should be unique and no object_type" do
24
- @unique_value_attribute.unique?.should == true
25
- @unique_value_attribute.object_type?.should == false
26
- end
27
- end
28
-
29
- describe "with unique object type" do
30
- it "be unique and an object type" do
31
- @unique_object_attribute.unique?.should == true
32
- @unique_object_attribute.object_type?.should == true
33
- end
34
- end
35
-
36
- describe "with non-unique value type" do
37
- it "be unique and an object type" do
38
- @non_unique_value_attribute.unique?.should == false
39
- @non_unique_value_attribute.object_type?.should == false
40
- end
41
- end
42
-
43
- describe "with non-unique object type" do
44
- it "be unique and an object type" do
45
- @non_unique_object_attribute.unique?.should == false
46
- @non_unique_object_attribute.object_type?.should == true
47
- end
48
- end
49
- end
50
-
@@ -1,30 +0,0 @@
1
- require 'pathname'
2
-
3
- require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
4
-
5
- describe Ken::Property do
6
- before :all do
7
- Ken::Logger.new(STDOUT, :info)
8
- # Ken::Session.new('http://www.freebase.com', 'ma', 'xxxxx')
9
- data = load_fixture('music_artist')
10
- @type = Ken::Type.new(data)
11
- @value_property = @type.properties[1]
12
- @object_property = @type.properties[3]
13
- end
14
-
15
- it 'should be a valid property instance' do
16
- @value_property.should be_kind_of(Ken::Property)
17
- @object_property.should be_kind_of(Ken::Property)
18
- end
19
-
20
- it 'should have a type' do
21
- @value_property.type.should be_kind_of(Ken::Type)
22
- @object_property.type.should be_kind_of(Ken::Type)
23
- end
24
-
25
- it 'should distinguish wheter it is an object or value type' do
26
- @value_property.object_type?.should == false
27
- @object_property.object_type?.should == true
28
- end
29
- end
30
-
@@ -1,63 +0,0 @@
1
- require 'pathname'
2
-
3
- require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
4
-
5
- describe Ken::Resource do
6
-
7
- before :each do
8
- # Ken::Logger.new(STDOUT, :info)
9
- # Ken::Session.new('http://www.freebase.com', 'ma', 'xxxxx')
10
- data = load_fixture('the_police')
11
- @the_police = Ken::Resource.new(data)
12
- end
13
-
14
- it 'should have types' do
15
- @the_police.types.should have_at_least(1).items
16
- @the_police.types.first.should be_kind_of(Ken::Type)
17
- end
18
-
19
- it 'should have views' do
20
- @the_police.views.should have(6).items
21
- @the_police.views.first.should be_kind_of(Ken::View)
22
- @the_police.views.first.type.should be_kind_of(Ken::Type)
23
- end
24
-
25
- it 'should have an id and a name' do
26
- @the_police.id.should be_kind_of(::String)
27
- @the_police.name.should be_kind_of(::String)
28
- end
29
-
30
- it 'should have attributes' do
31
- @the_police.attributes.should_not be_nil
32
- end
33
-
34
- it 'should deal with non-unique value type attributes' do
35
- pending
36
- end
37
-
38
- it 'should deal with unique object type attributes' do
39
- pending
40
- end
41
-
42
- it 'should deal with non-unique object type attributes' do
43
- pending
44
- end
45
-
46
- it 'should load attributes only on demand' do
47
- @the_police.attributes_loaded?.should == false
48
- @the_police.attributes
49
- @the_police.attributes_loaded?.should == true
50
- end
51
-
52
- it 'should load schema only on demand when calling types' do
53
- @the_police.schema_loaded?.should == false
54
- @the_police.types
55
- @the_police.schema_loaded?.should == true
56
- end
57
-
58
- it 'should load schema only on demand when calling views' do
59
- @the_police.schema_loaded?.should == false
60
- @the_police.views
61
- @the_police.schema_loaded?.should == true
62
- end
63
- end
@@ -1,18 +0,0 @@
1
- require 'pathname'
2
- require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
3
-
4
- describe Ken::Session do
5
- before :all do
6
- Ken::Logger.new(STDOUT, :info)
7
- Ken::Session.new('http://www.freebase.com', 'ma', 'xxxxx')
8
- end
9
-
10
- it 'should return the types of the_police' do
11
- result = Ken.session.mqlread({:id => "/en/the_police", :type => []})
12
- result['type'].length.should == 6
13
- end
14
-
15
- it 'should raise an Ken::MqlReadError if node does not exist' do
16
- lambda { Ken.session.mqlread({:id => "/en/the_police", :evil_property => []}) }.should raise_error(Ken::ReadError)
17
- end
18
- end
@@ -1,21 +0,0 @@
1
- require 'pathname'
2
-
3
- require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
4
-
5
- describe Ken::Type do
6
- before :all do
7
- Ken::Logger.new(STDOUT, :info)
8
- Ken::Session.new('http://www.freebase.com', 'ma', 'xxxxx')
9
-
10
- # fetch a type
11
- @type = Ken.get("/en/the_police").types.first
12
- end
13
-
14
- it 'should have an id and a name' do
15
- puts @type.id
16
- end
17
-
18
- it 'should have properties' do
19
- @type.properties.should have_at_least(1).items
20
- end
21
- end
@@ -1,28 +0,0 @@
1
- require 'pathname'
2
-
3
- require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
4
-
5
- describe Ken::View do
6
- before :all do
7
- Ken::Logger.new(STDOUT, :info)
8
- data = load_fixture('the_police')
9
- @the_police = Ken::Resource.new(data)
10
- @view = @the_police.views.first
11
- end
12
-
13
- it "should have a type" do
14
- @view.type.should_not be_nil
15
- @view.type.should be_kind_of(Ken::Type)
16
- end
17
-
18
- it "should have properties" do
19
- @view.properties.should_not be_nil
20
- @view.properties.each { |p| p.should be_kind_of(Ken::Property)}
21
- end
22
-
23
- it "should have attributes" do
24
- @view.attributes.should_not be_nil
25
- @view.attributes.each { |p| p.should be_kind_of(Ken::Attribute)}
26
- end
27
- end
28
-