imw 0.2.16 → 0.2.17

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,38 +2,85 @@ require File.dirname(__FILE__) + "/../spec_helper"
2
2
 
3
3
  describe IMW::Metadata do
4
4
 
5
- describe "initalizing" do
5
+ before do
6
+ @metadata = IMW::Metadata.new({'foobar' => {'description' => 'buzz', 'fields' => ['a','b', 'c']}, 'http://www.google.com' => { 'description' => 'google', 'fields' => ['d', 'e', 'f'] }})
7
+ end
8
+
9
+ describe "matching URLs without a base" do
6
10
 
7
- it "should accept a hash" do
8
- IMW::Metadata.new('a' => ['a', 'b']).should == { 'a' => [{:name => 'a'}, {:name => 'b'}] }
11
+ it "should be able to look up a relative URI literally" do
12
+ @metadata.describes?('foobar').should be_true
9
13
  end
14
+
15
+ it "should be able to look up a relative URI when passed an IMW::Resource" do
16
+ @metadata.describes?(IMW.open('foobar')).should be_true
17
+ end
18
+
19
+ it "should be able to look up an absolute URI literally" do
20
+ @metadata.describes?('http://www.google.com').should be_true
21
+ end
22
+
23
+ it "should rightly fail to literally look up a URI it doesn't know about" do
24
+ @metadata.describes?('bungler').should be_false
25
+ end
26
+
10
27
  end
11
28
 
12
- describe 'loading' do
29
+ describe "setting URLs" do
30
+ describe "without a base URL" do
31
+ it "should set 'foobar' to 'foobar'" do
32
+ @metadata['foobar'] = {'description' => 'bhaarg', 'fields' => ['a','b','c']}
33
+ @metadata.keys.should include('foobar')
34
+ end
13
35
 
14
- it "should accept a Hash in a resource" do
15
- data = {'a' => ['a', 'b']}
16
- resource = IMW.open('some_resource')
17
- IMW.should_receive(:open).with(resource).and_return(resource)
18
- resource.should_receive(:load).and_return(data)
19
- IMW::Metadata.load(resource).should == { 'a' => [{:name => 'a'}, {:name => 'b'}] }
36
+ it "should set '/a/b/c/foobar' to '/a/b/c/foobar'" do
37
+ @metadata['/a/b/c/foobar'] = {'description' => 'bhaarg', 'fields' => ['a','b','c']}
38
+ @metadata.keys.should include('/a/b/c/foobar')
39
+ end
40
+
41
+ end
42
+
43
+ describe "with a base URL" do
44
+ before do
45
+ FileUtils.mkdir_p('chimpo')
46
+ @metadata.base = File.join(IMWTest::TMP_DIR, 'chimpo')
47
+ end
48
+
49
+ it "should set 'foobar' to '$base/foobar'" do
50
+ @metadata['foobar'] = {'description' => 'bhaarg', 'fields' => ['a','b','c']}
51
+ @metadata.keys.should include(File.join(IMWTest::TMP_DIR, 'chimpo', 'foobar'))
52
+ end
53
+
54
+ it "should set '/a/b/c/foobar' to '/a/b/c/foobar'" do
55
+ @metadata['/a/b/c/foobar'] = {'description' => 'bhaarg', 'fields' => ['a','b','c']}
56
+ @metadata.keys.should include('/a/b/c/foobar')
57
+ end
58
+
20
59
  end
21
60
  end
22
61
 
23
- describe "constructing absolute URIs" do
62
+ describe "matching URLs with a base" do
24
63
 
25
- before { @metadata = IMW::Metadata.new }
26
-
27
- it "should return the resource given without a base" do
28
- @metadata.send(:absolute_uri, 'path/to/something').should == 'path/to/something'
64
+ it "should raise an error when trying to use a base URI that doesn't exist" do
65
+ lambda { @metadata.base = 'chimpo' }.should raise_error(IMW::PathError)
29
66
  end
30
67
 
31
- it "should return the absolute URI with a base" do
32
- path = File.join(IMWTest::TMP_DIR, 'metadata.yaml')
33
- FileUtils.mkdir_p(path)
34
- @metadata.base = path
35
- @metadata.send(:absolute_uri, 'path/to/something').should == File.join(IMWTest::TMP_DIR, '/path/to/something')
68
+ it "should raise an error when trying to use a base URI that isn't a directory" do
69
+ IMW.open!('chimpo') { |f| f.write('a file') }
70
+ lambda { @metadata.base = 'chimpo' }.should raise_error(IMW::PathError)
36
71
  end
72
+
73
+ it "should be able to look up a URI relative to its base" do
74
+ FileUtils.mkdir_p('chimpo')
75
+ @metadata.base = File.join(IMWTest::TMP_DIR, 'chimpo')
76
+ @metadata['foobar'] = {'description' => 'buzz', 'fields' => ['a','b', 'c']}
77
+ @metadata.describe?('foobar').should be_true
78
+ @metadata.describe?(IMW.open('foobar')).should be_true
79
+ end
80
+
81
+ it "should continue to be able to look up an absolute URI literally" do
82
+ @metadata.describes?('http://www.google.com').should be_true
83
+ end
84
+
37
85
  end
38
-
39
86
  end
@@ -65,6 +65,11 @@ describe IMW::Schemes::Local::LocalFile do
65
65
  # FIXME only look at the first 100 bytes b/c of subsequent non-ascii chars...
66
66
  IMW.open(path).snippet[0..100].should == File.new(path).read(101)
67
67
  end
68
+
69
+ it "can produce a summary with size and line count" do
70
+ @file.summary[:num_lines].should > 0
71
+ @file.summary[:size].should > 0
72
+ end
68
73
  end
69
74
 
70
75
  describe IMW::Schemes::Local::LocalDirectory do
@@ -130,28 +135,6 @@ describe IMW::Schemes::Local::LocalDirectory do
130
135
 
131
136
  end
132
137
 
133
- describe "handling schemata" do
134
-
135
- it "should recognize a YAML schema file" do
136
- schemata_path = File.join(@dir.path, 'schema.yaml')
137
- IMWTest::Random.file(schemata_path)
138
- @dir.schemata_path.should == schemata_path
139
- end
140
-
141
- it "should recognize a JSON schema file" do
142
- schemata_path = File.join(@dir.path, 'schema.json')
143
- IMWTest::Random.file(schemata_path)
144
- @dir.schemata_path.should == schemata_path
145
- end
146
-
147
- it "should recognize a funny-named YAML schema file" do
148
- schemata_path = File.join(@dir.path, 'schema-1838293.yml')
149
- IMWTest::Random.file(schemata_path)
150
- @dir.schemata_path.should == schemata_path
151
- end
152
-
153
- end
154
-
155
138
  it "can join with a path" do
156
139
  @dir.join("a", "b/c").to_s.should == File.join(@dir.path, 'a/b/c')
157
140
  end
@@ -170,6 +153,13 @@ describe IMW::Schemes::Local::LocalDirectory do
170
153
  end
171
154
  end
172
155
  end
156
+
157
+ it "can produce a summary with size and number of files" do
158
+ @dir.create
159
+ @dir.summary[:num_files].should == @dir.contents.size
160
+ @dir.summary[:size].should > 0
161
+ end
162
+
173
163
  end
174
164
 
175
165
 
@@ -28,5 +28,4 @@ describe IMW::Schemes::S3 do
28
28
  end
29
29
  end
30
30
  end
31
-
32
31
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imw
3
3
  version: !ruby/object:Gem::Version
4
- hash: 55
4
+ hash: 53
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 16
10
- version: 0.2.16
9
+ - 17
10
+ version: 0.2.17
11
11
  platform: ruby
12
12
  authors:
13
13
  - Dhruv Bansal
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-12-21 00:00:00 -06:00
19
+ date: 2011-01-17 00:00:00 -06:00
20
20
  default_executable:
21
21
  dependencies: []
22
22
 
@@ -69,8 +69,9 @@ files:
69
69
  - lib/imw/metadata/contains_metadata.rb
70
70
  - lib/imw/metadata/dsl.rb
71
71
  - lib/imw/metadata/field.rb
72
+ - lib/imw/metadata/has_metadata.rb
73
+ - lib/imw/metadata/has_summary.rb
72
74
  - lib/imw/metadata/schema.rb
73
- - lib/imw/metadata/schematized.rb
74
75
  - lib/imw/parsers.rb
75
76
  - lib/imw/parsers/flat.rb
76
77
  - lib/imw/parsers/html_parser.rb
@@ -157,7 +158,10 @@ files:
157
158
  - spec/imw/formats/json_spec.rb
158
159
  - spec/imw/formats/sgml_spec.rb
159
160
  - spec/imw/formats/yaml_spec.rb
161
+ - spec/imw/metadata/contains_metadata_spec.rb
160
162
  - spec/imw/metadata/field_spec.rb
163
+ - spec/imw/metadata/has_metadata_spec.rb
164
+ - spec/imw/metadata/has_summary_spec.rb
161
165
  - spec/imw/metadata/schema_spec.rb
162
166
  - spec/imw/metadata_spec.rb
163
167
  - spec/imw/parsers/line_parser_spec.rb
@@ -248,6 +252,9 @@ test_files:
248
252
  - spec/imw/formats/sgml_spec.rb
249
253
  - spec/imw/archives_spec.rb
250
254
  - spec/imw/metadata/schema_spec.rb
255
+ - spec/imw/metadata/contains_metadata_spec.rb
256
+ - spec/imw/metadata/has_metadata_spec.rb
257
+ - spec/imw/metadata/has_summary_spec.rb
251
258
  - spec/imw/metadata/field_spec.rb
252
259
  - spec/imw/schemes/http_spec.rb
253
260
  - spec/imw/schemes/local_spec.rb
@@ -1,27 +0,0 @@
1
- module IMW
2
- class Metadata
3
- module Schematized
4
-
5
- # The schema for this object.
6
- #
7
- # @return [IMW::Metadata::Schema, nil]
8
- def schema
9
- @schema
10
- end
11
-
12
- # Set a new schema for this object.
13
- #
14
- # Will call the object's +validate_schema!+ hook which should
15
- # check the record and take the appropriate action if it's
16
- # invalid.
17
- #
18
- # @param [Array, IMW::Metadata::Schema] new_schema
19
- # @return [IMW::Metadata::Schema]
20
- def schema= new_schema
21
- @schema = IMW::Metadata::Schema.new(new_schema)
22
- validate_schema! if respond_to?(:validate_schema!)
23
- @schema
24
- end
25
- end
26
- end
27
- end