mida 0.3.9 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d1d5a6aea8cdf0891e2e766c740e806539a8947c
4
- data.tar.gz: 0f748e487ad3e4347cfde3ced305bc71288bf6df
3
+ metadata.gz: ce860318419bb6c7035970ea76944a6b163760c1
4
+ data.tar.gz: e7dd59518fe23b26b56e6da0bf5c7fb75f6b242b
5
5
  SHA512:
6
- metadata.gz: 490a74f5db41dd292883bbfd5d738431516c2ef6089936af1f7593f4ae53460724860a433eb545ac4f51a40d6ef69363275af907ab44c3738fbac7b60e5d7d29
7
- data.tar.gz: a333750b5de42b1f2b99cf1d0a15827251d02d3870f75a4862265b8ad8fff4b1c98a84ca623bcd9cd3ff7f08d7a4330f78779b6c1ffbab5d47f201548acdef48
6
+ metadata.gz: fb8a525521ad35f8fc5bcde98361d163d891b95535403b150bb251c5635f297d554f10192b8e2de38d8e5ee2cc2ff0c68bb48bcc3b47a5b61668c306574855a7
7
+ data.tar.gz: 7077836f38c96eeedc201ad945d8e2eff1a6495f1547fe301f19061122f6f958633d55cf2494def351c87ef7d0bf7222f1cfab3a906da1472b5714c194d2e70b
data/.gitignore CHANGED
@@ -2,6 +2,7 @@
2
2
  *.swp
3
3
 
4
4
  # Gem pkg directory
5
+ Gemfile.lock
5
6
  pkg/
6
7
  *.gem
7
8
  *.rbc
@@ -1,8 +1,13 @@
1
1
  language: ruby
2
+ sudo: false
3
+ cache:
4
+ bundler: true
2
5
  rvm:
3
- - 1.9.2
4
- - 1.9.3
5
- - 2.0.0
6
+ - 2.2.4
7
+ - 2.3.0
6
8
  branches:
7
9
  only:
8
10
  - master
11
+ env:
12
+ global:
13
+ - NOKOGIRI_USE_SYSTEM_LIBRARIES=true
@@ -11,15 +11,13 @@ module Mida
11
11
  # [[DataType, Regexp], [DataType, Regexp]]
12
12
  class Enumeration < Generic
13
13
 
14
- Enumeration.reveal(:class)
15
-
16
14
  # Raises +ArgumentError+ if value not valid value
17
15
  def initialize(value)
18
- value_is_valid = self.class::VALID_VALUES.any? do |valid_value|
16
+ value_is_valid = (class << self; self end).superclass::VALID_VALUES.any? do |valid_value|
19
17
  @parsedValue = valid_value[0].parse(value)
20
18
  @parsedValue.to_s =~ valid_value[1]
21
19
  end
22
- raise ArgumentError unless value_is_valid
20
+ raise ::ArgumentError unless value_is_valid
23
21
  end
24
22
 
25
23
  end
@@ -1,10 +1,8 @@
1
- require 'blankslate'
2
-
3
1
  module Mida
4
2
  module DataType
5
3
 
6
4
  # The base DataType Parser
7
- class Generic < BlankSlate
5
+ class Generic < BasicObject
8
6
 
9
7
  # Convenience method, same as +new+
10
8
  def self.parse(value)
@@ -12,7 +12,7 @@ module Mida
12
12
  def initialize(value)
13
13
  @parsedValue = ::DateTime.iso8601(value)
14
14
  rescue => e
15
- raise ArgumentError, e
15
+ raise ::ArgumentError, e
16
16
  end
17
17
 
18
18
  def to_s
@@ -16,7 +16,7 @@ module Mida
16
16
  # [page_url] The url of target used for form absolute urls. This must
17
17
  # include the filename, e.g. index.html.
18
18
  def initialize(target, page_url=nil)
19
- @doc = Nokogiri(target)
19
+ @doc = target.kind_of?(Nokogiri::XML::Document) ? target : Nokogiri(target)
20
20
  @page_url = page_url
21
21
  @items = extract_items
22
22
  end
@@ -1,3 +1,3 @@
1
1
  module Mida
2
- VERSION = "0.3.9"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -18,10 +18,9 @@ Gem::Specification.new do |spec|
18
18
  spec.require_paths = ["lib"]
19
19
  spec.extra_rdoc_files = ['README.rdoc', 'LICENCE.rdoc', 'CHANGELOG.rdoc']
20
20
  spec.rdoc_options << '--main' << 'README.rdoc'
21
- spec.add_dependency('blankslate', '3.1.3')
22
21
  spec.add_dependency('nokogiri', '>= 1.6')
23
- spec.add_dependency('addressable', '~> 2.3.8')
22
+ spec.add_dependency('addressable', '~> 2.4')
24
23
  spec.add_development_dependency "bundler", "~> 1.6"
25
24
  spec.add_development_dependency "rake"
26
- spec.add_development_dependency "rspec", "~> 2.10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.1"
27
26
  end
@@ -4,37 +4,37 @@ describe Mida::DataType::Boolean do
4
4
 
5
5
  it '#parse should raise an exception if a invalid text passed' do
6
6
  test = lambda {Mida::DataType::Boolean.parse('example')}
7
- test.should raise_error(ArgumentError)
7
+ expect(test).to raise_error(ArgumentError)
8
8
  end
9
9
 
10
10
  it '#parse should raise an exception if value is empty' do
11
11
  test = lambda {Mida::DataType::Boolean.parse('')}
12
- test.should raise_error(ArgumentError)
12
+ expect(test).to raise_error(ArgumentError)
13
13
  end
14
14
 
15
15
  it '#parse should return true for "True" whatever the case' do
16
16
  ['true', 'True', 'TRUE', 'tRUE'].each do |true_text|
17
- Mida::DataType::Boolean.parse(true_text).should be_true
17
+ expect(Mida::DataType::Boolean.parse(true_text)).to be_truthy
18
18
  end
19
19
  end
20
20
 
21
21
  it '#parse should return false for "False" whatever the case' do
22
22
  ['false', 'False', 'FALSE', 'fALSE'].each do |false_text|
23
- Mida::DataType::Boolean.parse(false_text).should be_false
23
+ expect(Mida::DataType::Boolean.parse(false_text)).to be_falsey
24
24
  end
25
25
  end
26
26
 
27
27
  it '#to_s should return proper string representation of boolean' do
28
- Mida::DataType::Boolean.parse('fALSE').to_s.should == 'False'
29
- Mida::DataType::Boolean.parse('tRUE').to_s.should == 'True'
28
+ expect(Mida::DataType::Boolean.parse('fALSE').to_s).to eq('False')
29
+ expect(Mida::DataType::Boolean.parse('tRUE').to_s).to eq('True')
30
30
  end
31
31
 
32
32
  it '! should negate as if a TrueClass/FalseClass' do
33
33
  true_boolean = Mida::DataType::Boolean.parse('true')
34
34
  false_boolean = Mida::DataType::Boolean.parse('false')
35
35
 
36
- (!true_boolean).should be_false
37
- (!false_boolean).should be_true
36
+ expect(!true_boolean).to be_falsey
37
+ expect(!false_boolean).to be_truthy
38
38
  end
39
39
 
40
40
  end
@@ -13,18 +13,18 @@ describe Mida::DataType::Enumeration do
13
13
 
14
14
  it '#parse should raise an exception if an invalid url passed' do
15
15
  test = lambda {BookType.parse('http://example.com/hardback')}
16
- test.should raise_error(ArgumentError)
16
+ expect(test).to raise_error(ArgumentError)
17
17
  end
18
18
 
19
19
  it '#parse should raise an exception if value is empty' do
20
20
  test = lambda {BookType.parse('')}
21
- test.should raise_error(ArgumentError)
21
+ expect(test).to raise_error(ArgumentError)
22
22
  end
23
23
 
24
24
  it '#parse should accept a valid value' do
25
25
  url_text = 'http://example.com/ebook'
26
26
  url = BookType.parse(url_text)
27
- url.to_s.should == url_text
27
+ expect(url.to_s).to eq(url_text)
28
28
  end
29
29
 
30
30
  end
@@ -4,18 +4,18 @@ describe Mida::DataType::Float do
4
4
 
5
5
  it '#parse should raise an exception if not a number' do
6
6
  test = lambda {Mida::DataType::Float.parse('hello')}
7
- test.should raise_error(ArgumentError)
7
+ expect(test).to raise_error(ArgumentError)
8
8
  end
9
9
 
10
10
  it '#parse should raise an exception if value is empty' do
11
11
  test = lambda {Mida::DataType::Float.parse('')}
12
- test.should raise_error(ArgumentError)
12
+ expect(test).to raise_error(ArgumentError)
13
13
  end
14
14
 
15
15
  it '#parse should accept a valid number' do
16
16
  float_text = '3.14'
17
17
  float = Mida::DataType::Float.parse(float_text)
18
- float.to_s.should == float_text
18
+ expect(float.to_s).to eq(float_text)
19
19
  end
20
20
 
21
21
  end
@@ -17,28 +17,28 @@ describe Mida::DataType::Generic do
17
17
 
18
18
  it "should provide access to the underlying type's methods" do
19
19
  number = Number.new('2.34')
20
- number.floor.should == 2
20
+ expect(number.floor).to eq(2)
21
21
  end
22
22
 
23
23
  it '#to_s should use the underlying types #to_s method' do
24
24
  number = Number.parse('2.34')
25
- number.to_s.should == '2.34'
25
+ expect(number.to_s).to eq('2.34')
26
26
  end
27
27
 
28
28
  it '#to_yaml should provide a yaml representation of the items #to_s method' do
29
29
  number = Number.parse('2.34')
30
- number.to_yaml.should =~ /---\s+['"]2.34['"]\n/
30
+ expect(number.to_yaml).to match(/---\s+['"]2.34['"]\n/)
31
31
  end
32
32
 
33
33
  it '#== should match against underlying type, string representation and self' do
34
34
  number = Number.new('2.34')
35
- (number == 2.34).should be_true
36
- (number == '2.34').should be_true
37
- (number == number).should be_true
35
+ expect(number == 2.34).to be_truthy
36
+ expect(number == '2.34').to be_truthy
37
+ expect(number == number).to be_truthy
38
38
 
39
- (number == 2.44).should be_false
40
- (number == '2.44').should be_false
41
- (number == Number.new('2.44')).should be_false
39
+ expect(number == 2.44).to be_falsey
40
+ expect(number == '2.44').to be_falsey
41
+ expect(number == Number.new('2.44')).to be_falsey
42
42
  end
43
43
 
44
44
  end
@@ -4,23 +4,23 @@ describe Mida::DataType::Integer do
4
4
 
5
5
  it '#parse should raise an exception if not a number' do
6
6
  test = lambda {Mida::DataType::Integer.parse('hello')}
7
- test.should raise_error(ArgumentError)
7
+ expect(test).to raise_error(ArgumentError)
8
8
  end
9
9
 
10
10
  it '#parse should raise an exception if not an integer' do
11
11
  test = lambda {Mida::DataType::Integer.parse('3.14')}
12
- test.should raise_error(ArgumentError)
12
+ expect(test).to raise_error(ArgumentError)
13
13
  end
14
14
 
15
15
  it '#parse should raise an exception if value is empty' do
16
16
  test = lambda {Mida::DataType::Integer.parse('')}
17
- test.should raise_error(ArgumentError)
17
+ expect(test).to raise_error(ArgumentError)
18
18
  end
19
19
 
20
20
  it '#parse should accept a valid number' do
21
21
  integer_text = '3'
22
22
  integer = Mida::DataType::Integer.parse(integer_text)
23
- integer.to_s.should == integer_text
23
+ expect(integer.to_s).to eq(integer_text)
24
24
  end
25
25
 
26
26
  end
@@ -4,12 +4,12 @@ describe Mida::DataType::ISO8601Date do
4
4
 
5
5
  it '#parse should raise an exception if invalid date format' do
6
6
  test = lambda {Mida::DataType::ISO8601Date.parse('27th August 2009')}
7
- test.should raise_error(ArgumentError)
7
+ expect(test).to raise_error(ArgumentError)
8
8
  end
9
9
 
10
10
  it '#parse should raise an exception if value is empty' do
11
11
  test = lambda {Mida::DataType::ISO8601Date.parse('')}
12
- test.should raise_error(ArgumentError)
12
+ expect(test).to raise_error(ArgumentError)
13
13
  end
14
14
 
15
15
  context 'when passed a valid date' do
@@ -19,7 +19,7 @@ describe Mida::DataType::ISO8601Date do
19
19
  end
20
20
 
21
21
  it '#to_s should return the date as an rfc822 text string' do
22
- @date.to_s.should == "Thu, 27 Aug 2009 01:13:04 +0510"
22
+ expect(@date.to_s).to eq("Thu, 27 Aug 2009 01:13:04 +0510")
23
23
  end
24
24
 
25
25
  end
@@ -4,18 +4,18 @@ describe Mida::DataType::Number do
4
4
 
5
5
  it '#parse should raise an exception if not a number' do
6
6
  test = lambda {Mida::DataType::Number.parse('hello')}
7
- test.should raise_error(ArgumentError)
7
+ expect(test).to raise_error(ArgumentError)
8
8
  end
9
9
 
10
10
  it '#parse should raise an exception if value is empty' do
11
11
  test = lambda {Mida::DataType::Number.parse('')}
12
- test.should raise_error(ArgumentError)
12
+ expect(test).to raise_error(ArgumentError)
13
13
  end
14
14
 
15
15
  it '#parse should accept a valid number' do
16
16
  num_text = '3.14'
17
17
  num = Mida::DataType::Number.parse(num_text)
18
- num.to_s.should == num_text
18
+ expect(num.to_s).to eq(num_text)
19
19
  end
20
20
 
21
21
  end
@@ -4,13 +4,13 @@ describe Mida::DataType::Text do
4
4
 
5
5
  it '#parse should accept an empty string' do
6
6
  text = Mida::DataType::Text.parse('')
7
- text.should == ''
7
+ expect(text).to eq('')
8
8
  end
9
9
 
10
10
  it '#parse should return the input value' do
11
11
  test_text = 'Some text'
12
12
  text = Mida::DataType::Text.parse(test_text)
13
- text.should == test_text
13
+ expect(text).to eq(test_text)
14
14
  end
15
15
 
16
16
  end
@@ -7,23 +7,23 @@ describe Mida::DataType::URL do
7
7
 
8
8
  it '#parse should raise an exception if a bad url passed' do
9
9
  test = lambda {Mida::DataType::URL.parse('example.com')}
10
- test.should raise_error(ArgumentError)
10
+ expect(test).to raise_error(ArgumentError)
11
11
  end
12
12
 
13
13
  it '#parse should raise an exception if value is empty' do
14
14
  test = lambda {Mida::DataType::URL.parse('')}
15
- test.should raise_error(ArgumentError)
15
+ expect(test).to raise_error(ArgumentError)
16
16
  end
17
17
 
18
18
  it '#parse should accept a valid url' do
19
19
  url_text = 'http://example.com/test/'
20
20
  url = Mida::DataType::URL.parse(url_text)
21
- url.to_s.should == url_text
21
+ expect(url.to_s).to eq(url_text)
22
22
  end
23
23
 
24
24
  it '#parse should accept a valid url with special characters' do
25
25
  url_text = 'http://example.com/übergangslösung'
26
26
  url = Mida::DataType::URL.parse(url_text)
27
- url.to_s.should == ::Addressable::URI.encode(url_text)
27
+ expect(url.to_s).to eq(::Addressable::URI.encode(url_text))
28
28
  end
29
29
  end
@@ -11,21 +11,21 @@ def test_parsing(md, vocabulary, expected_results)
11
11
  end
12
12
 
13
13
  def test_to_h(item, expected_result)
14
- item.to_h.should == expected_result
14
+ expect(item.to_h).to eq(expected_result)
15
15
  end
16
16
 
17
17
  def test_properties(item, expected_result)
18
18
  item.properties.each do |name, value|
19
- match_array(value, expected_result[:properties][name])
19
+ match_array_legacy(value, expected_result[:properties][name])
20
20
  end
21
21
  end
22
22
 
23
- def match_array(value_array, expected_results)
23
+ def match_array_legacy(value_array, expected_results)
24
24
  value_array.each_with_index do |element, i|
25
25
  if element.is_a?(Mida::Item)
26
26
  test_properties(element, expected_results[i])
27
27
  else
28
- element.should == expected_results[i]
28
+ expect(element).to eq(expected_results[i])
29
29
  end
30
30
  end
31
31
  end
@@ -49,22 +49,29 @@ describe Mida::Document do
49
49
  </body></html>
50
50
  '
51
51
 
52
+ @nokogiri_document = Nokogiri(html)
53
+
52
54
  @md = Mida::Document.new(html)
53
55
  end
54
56
 
55
57
  it '#each should pass each item to the block' do
56
58
  item_num = 0
57
- @md.each {|item| item.should == @md.items[item_num]; item_num += 1}
59
+ @md.each {|item| expect(item).to eq(@md.items[item_num]); item_num += 1}
58
60
  end
59
61
 
60
62
  it 'should have access to the Enumerable mixin methods such as #find' do
61
63
  review = @md.find {|item| item.type == 'http://data-vocabulary.org/Review'}
62
- review.type.should == 'http://data-vocabulary.org/Review'
63
- review.properties['itemreviewed'].should == ["Romeo Pizza"]
64
+ expect(review.type).to eq('http://data-vocabulary.org/Review')
65
+ expect(review.properties['itemreviewed']).to eq(["Romeo Pizza"])
64
66
 
65
67
  organization = @md.find {|item| item.type == 'http://data-vocabulary.org/Organization'}
66
- organization.type.should == 'http://data-vocabulary.org/Organization'
67
- organization.properties['name'].should == ["An org name"]
68
+ expect(organization.type).to eq('http://data-vocabulary.org/Organization')
69
+ expect(organization.properties['name']).to eq(["An org name"])
70
+ end
71
+
72
+ it 'should not re-parse a nokogiri document' do
73
+ md = Mida::Document.new(@nokogiri_document)
74
+ expect(md.instance_variable_get(:@doc).object_id).to eq(@nokogiri_document.object_id)
68
75
  end
69
76
  end
70
77
 
@@ -116,14 +123,14 @@ describe Mida::Document, 'when run against a full html document containing items
116
123
 
117
124
  it '#search should be able to match against items without an itemtype' do
118
125
  items = @md.search(%r{^$})
119
- items.size.should == 1
120
- items[0].properties['name'].should == ['An org name']
126
+ expect(items.size).to eq(1)
127
+ expect(items[0].properties['name']).to eq(['An org name'])
121
128
  end
122
129
 
123
130
  it '#search should be able to match against items with an itemtype' do
124
131
  items = @md.search(%r{^.+$})
125
- items.size.should == 1
126
- items[0].type.should == 'http://data-vocabulary.org/Review'
132
+ expect(items.size).to eq(1)
133
+ expect(items[0].type).to eq('http://data-vocabulary.org/Review')
127
134
  end
128
135
  end
129
136
 
@@ -152,7 +159,7 @@ describe Mida::Document, 'when run against a full html document containing two n
152
159
  end
153
160
 
154
161
  it 'should return all the itemscopes' do
155
- @md.items.size.should == 2
162
+ expect(@md.items.size).to eq(2)
156
163
  end
157
164
 
158
165
  it 'should give the type of each itemscope if none specified' do
@@ -165,8 +172,8 @@ describe Mida::Document, 'when run against a full html document containing two n
165
172
  itemscope_names[item.type] += 1
166
173
  end
167
174
 
168
- itemscope_names.size.should eq 2
169
- itemscope_names.each { |name, num| num.should == 1 }
175
+ expect(itemscope_names.size).to eq 2
176
+ itemscope_names.each { |name, num| expect(num).to eq(1) }
170
177
  end
171
178
 
172
179
 
@@ -220,11 +227,11 @@ describe Mida::Document, 'when run against a full html document containing one
220
227
  end
221
228
 
222
229
  it 'should not match itemscopes with different names' do
223
- @md.search(%r{nothing}).size.should == 0
230
+ expect(@md.search(%r{nothing}).size).to eq(0)
224
231
  end
225
232
 
226
233
  it 'should find the correct number of itemscopes' do
227
- @md.items.size.should == 1
234
+ expect(@md.items.size).to eq(1)
228
235
  end
229
236
 
230
237
  it 'should return the correct number of itemscopes' do
@@ -232,7 +239,7 @@ describe Mida::Document, 'when run against a full html document containing one
232
239
  %r{http://data-vocabulary.org/Product},
233
240
  %r{http://data-vocabulary.org/Review-aggregate}
234
241
  ]
235
- vocabularies.each {|vocabulary| @md.search(vocabulary).size.should == 1}
242
+ vocabularies.each {|vocabulary| expect(@md.search(vocabulary).size).to eq(1)}
236
243
 
237
244
  end
238
245
 
@@ -289,16 +296,16 @@ describe Mida::Document, 'when run against a document containing an itemscope
289
296
  %r{http://data-vocabulary.org/Product} => 1,
290
297
  %r{http://data-vocabulary.org/Review-aggregate} => 1
291
298
  }
292
- vocabularies.each {|vocabulary, num| @md.search(vocabulary).size.should == num}
299
+ vocabularies.each {|vocabulary, num| expect(@md.search(vocabulary).size).to eq(num)}
293
300
  end
294
301
 
295
302
  it 'should return the correct number of items' do
296
- @md.items.size.should == 2
303
+ expect(@md.items.size).to eq(2)
297
304
  end
298
305
 
299
306
  context "when no vocabulary specified or looking at the outer vocabulary" do
300
307
  it 'should return all the properties from the text with the correct values' do
301
- pending("get the contains: feature working")
308
+ skip("get the contains: feature working")
302
309
  expected_result = {
303
310
  type: 'http://data-vocabulary.org/Product',
304
311
  properties: {
@@ -314,7 +321,7 @@ describe Mida::Document, 'when run against a document containing an itemscope
314
321
  }
315
322
  }
316
323
 
317
- @md.search('http://data-vocabulary.org/Product').first.should == expected_result
324
+ expect(@md.search('http://data-vocabulary.org/Product').first).to eq(expected_result)
318
325
  end
319
326
  end
320
327
  end