saxerator 0.9.5 → 0.9.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.travis.yml +9 -12
  4. data/Gemfile +4 -2
  5. data/README.md +23 -3
  6. data/Rakefile +12 -1
  7. data/benchmark/benchmark.rb +54 -12
  8. data/benchmark/generate_sample_file.rb +1 -1
  9. data/lib/saxerator.rb +2 -3
  10. data/lib/saxerator/adapters/nokogiri.rb +39 -0
  11. data/lib/saxerator/adapters/ox.rb +69 -0
  12. data/lib/saxerator/adapters/rexml.rb +42 -0
  13. data/lib/saxerator/builder.rb +2 -2
  14. data/lib/saxerator/builder/array_element.rb +8 -2
  15. data/lib/saxerator/builder/empty_element.rb +2 -3
  16. data/lib/saxerator/builder/hash_builder.rb +8 -7
  17. data/lib/saxerator/builder/hash_element.rb +7 -8
  18. data/lib/saxerator/builder/string_element.rb +5 -7
  19. data/lib/saxerator/builder/xml_builder.rb +11 -7
  20. data/lib/saxerator/configuration.rb +27 -7
  21. data/lib/saxerator/document_fragment.rb +3 -5
  22. data/lib/saxerator/dsl.rb +6 -5
  23. data/lib/saxerator/full_document.rb +1 -1
  24. data/lib/saxerator/latches/abstract_latch.rb +1 -1
  25. data/lib/saxerator/latches/at_depth.rb +2 -2
  26. data/lib/saxerator/latches/child_of.rb +9 -14
  27. data/lib/saxerator/latches/for_tags.rb +2 -2
  28. data/lib/saxerator/latches/with_attributes.rb +2 -2
  29. data/lib/saxerator/latches/within.rb +6 -10
  30. data/lib/saxerator/parser/accumulator.rb +6 -9
  31. data/lib/saxerator/parser/latched_accumulator.rb +4 -49
  32. data/lib/saxerator/sax_handler.rb +9 -0
  33. data/lib/saxerator/version.rb +1 -1
  34. data/saxerator.gemspec +5 -2
  35. data/spec/lib/builder/hash_builder_spec.rb +25 -19
  36. data/spec/lib/builder/xml_builder_spec.rb +7 -26
  37. data/spec/lib/dsl/all_spec.rb +11 -6
  38. data/spec/lib/dsl/at_depth_spec.rb +10 -8
  39. data/spec/lib/dsl/child_of_spec.rb +6 -6
  40. data/spec/lib/dsl/for_tag_spec.rb +3 -3
  41. data/spec/lib/dsl/for_tags_spec.rb +5 -5
  42. data/spec/lib/dsl/with_attribute_spec.rb +4 -4
  43. data/spec/lib/dsl/with_attributes_spec.rb +8 -7
  44. data/spec/lib/dsl/within_spec.rb +6 -5
  45. data/spec/lib/saxerator_spec.rb +70 -58
  46. data/spec/spec_helper.rb +24 -3
  47. data/spec/support/fixture_file.rb +1 -1
  48. metadata +39 -5
@@ -0,0 +1,9 @@
1
+ module Saxerator
2
+ class SaxHandler
3
+ def characters(_text); end
4
+
5
+ def start_element(_name, _attrs = []); end
6
+
7
+ def end_element(_name); end
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module Saxerator
2
- VERSION = "0.9.5"
2
+ VERSION = '0.9.8'.freeze
3
3
  end
@@ -17,6 +17,8 @@ Gem::Specification.new do |s|
17
17
 
18
18
  s.rubyforge_project = 'saxerator'
19
19
 
20
+ s.required_ruby_version = '>= 2.1.0'
21
+
20
22
  s.files = [
21
23
  'LICENSE',
22
24
  'README.md',
@@ -33,7 +35,8 @@ Gem::Specification.new do |s|
33
35
  s.executables = []
34
36
  s.require_paths = ['lib']
35
37
 
36
- s.add_runtime_dependency 'nokogiri', '>= 1.4.0'
37
-
38
+ s.add_development_dependency 'nokogiri', '>= 1.4.0'
39
+ s.add_development_dependency 'ox'
40
+ s.add_development_dependency 'rake'
38
41
  s.add_development_dependency 'rspec', '~> 3.1'
39
42
  end
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require 'spec_helper'
3
3
 
4
- describe "Saxerator (default) hash format" do
4
+ describe 'Saxerator (default) hash format' do
5
5
  let(:xml) { fixture_file('nested_elements.xml') }
6
6
  subject(:entry) { Saxerator.parser(xml).for_tag(:entry).first }
7
7
 
@@ -9,10 +9,13 @@ describe "Saxerator (default) hash format" do
9
9
  specify { expect(entry['title']).to eq('How to eat an airplane') }
10
10
 
11
11
  # hash and cdata inside name
12
- specify { expect(entry['author']).to eq({'name' => 'Soul<utter'}) }
12
+ specify { expect(entry['author']).to eq('name' => 'Soul<utter') }
13
13
 
14
14
  # array of hashes
15
- specify { expect(entry['contributor']).to eq([{'name' => 'Jane Doe'}, {'name' => 'Leviticus Alabaster'}]) }
15
+ specify do
16
+ expect(entry['contributor'])
17
+ .to eq([{ 'name' => 'Jane Doe' }, { 'name' => 'Leviticus Alabaster' }])
18
+ end
16
19
 
17
20
  # attributes on a hash
18
21
  specify { expect(entry['contributor'][0].attributes['type']).to eq('primary') }
@@ -26,32 +29,32 @@ describe "Saxerator (default) hash format" do
26
29
  # name on a string
27
30
  specify { expect(entry['title'].name).to eq('title') }
28
31
 
29
- describe "#to_s" do
30
- it "preserves the element name" do
32
+ describe '#to_s' do
33
+ it 'preserves the element name' do
31
34
  expect(entry['title'].to_a.name).to eq('title')
32
35
  end
33
36
  end
34
37
 
35
- describe "#to_h" do
36
- it "preserves the element name" do
38
+ describe '#to_h' do
39
+ it 'preserves the element name' do
37
40
  expect(entry.to_h.name).to eq('entry')
38
41
  end
39
42
  end
40
43
 
41
- describe "#to_a" do
42
- it "preserves the element name on a parsed hash" do
44
+ describe '#to_a' do
45
+ it 'preserves the element name on a parsed hash' do
43
46
  expect(entry.to_a.name).to eq('entry')
44
47
  end
45
48
 
46
- it "converts parsed hashes to nested key/value pairs (just like regular hashes)" do
49
+ it 'converts parsed hashes to nested key/value pairs (just like regular hashes)' do
47
50
  expect(entry.to_a.first).to eq(['id', '1'])
48
51
  end
49
52
 
50
- it "preserves the element name on a parsed string" do
53
+ it 'preserves the element name on a parsed string' do
51
54
  expect(entry['title'].to_a.name).to eq('title')
52
55
  end
53
56
 
54
- it "preserves the element name on an array" do
57
+ it 'preserves the element name on an array' do
55
58
  expect(entry['contributor'].to_a.name).to eq 'contributor'
56
59
  end
57
60
  end
@@ -60,21 +63,24 @@ describe "Saxerator (default) hash format" do
60
63
  specify { expect(entry['contributor'].name).to eq('contributor') }
61
64
 
62
65
  # character entity decoding
63
- specify { expect(entry['content']).to eq("<p>Airplanes are very large — this can present difficulty in digestion.</p>") }
66
+ specify do
67
+ expect(entry['content'])
68
+ .to eq('<p>Airplanes are very large — this can present difficulty in digestion.</p>')
69
+ end
64
70
 
65
- context "parsing an empty element" do
71
+ context 'parsing an empty element' do
66
72
  subject(:element) { entry['media:thumbnail'] }
67
73
 
68
- it "behaves somewhat like nil" do
74
+ it 'behaves somewhat like nil' do
69
75
  expect(element).to be_nil
70
- expect(!element).to eq true
71
- expect(element.to_s).to eq ''
72
- expect(element.to_h).to eq Hash.new
76
+ expect(!element).to be true
77
+ expect(element.to_s).to eq('')
78
+ expect(element.to_h).to eq({})
73
79
  end
74
80
 
75
81
  it { is_expected.to be_empty }
76
82
 
77
- it "has attributes" do
83
+ it 'has attributes' do
78
84
  expect(element.attributes.keys).to eq ['url']
79
85
  end
80
86
 
@@ -1,37 +1,18 @@
1
1
  # encoding: utf-8
2
2
  require 'spec_helper'
3
3
 
4
- describe "Saxerator xml format" do
4
+ describe 'Saxerator xml format' do
5
5
  let(:xml) { fixture_file('nested_elements.xml') }
6
+
6
7
  subject(:entry) do
7
8
  Saxerator.parser(xml) do |config|
8
9
  config.output_type = :xml
9
10
  end.for_tag(:entry).first
10
11
  end
11
12
 
12
- it { is_expected.to be_a(Nokogiri::XML::Node) }
13
- it "looks like the original document" do
14
- expected_xml = <<-eos
15
- <?xml version="1.0"?>
16
- <entry>
17
- <id>1</id>
18
- <published>2012-01-01T16:17:00-06:00</published>
19
- <updated>2012-01-01T16:17:00-06:00</updated>
20
- <link href="https://example.com/blog/how-to-eat-an-airplane"/>
21
- <title>How to eat an airplane</title>
22
- <content type="html">&lt;p&gt;Airplanes are very large &#x2014; this can present difficulty in digestion.&lt;/p&gt;</content>
23
- <media:thumbnail url="http://www.gravatar.com/avatar/a9eb6ba22e482b71b266daadf9c9a080?s=80"/>
24
- <author>
25
- <name>Soul&lt;utter</name>
26
- </author>
27
- <contributor type="primary">
28
- <name>Jane Doe</name>
29
- </contributor>
30
- <contributor>
31
- <name>Leviticus Alabaster</name>
32
- </contributor>
33
- </entry>
34
- eos
35
- expect(entry.to_xml).to eq(expected_xml)
13
+ it { is_expected.to be_a(REXML::Document) }
14
+ it 'looks like the original document' do
15
+ expected_xml = '<?xml version=\'1.0\' encoding=\'UTF-8\'?><entry><id>1</id><published>2012-01-01T16:17:00-06:00</published><updated>2012-01-01T16:17:00-06:00</updated><link href="https://example.com/blog/how-to-eat-an-airplane"/><title>How to eat an airplane</title><content type="html">&lt;p&gt;Airplanes are very large — this can present difficulty in digestion.&lt;/p&gt;</content><media:thumbnail url="http://www.gravatar.com/avatar/a9eb6ba22e482b71b266daadf9c9a080?s=80"/><author><name>Soul&lt;utter</name></author><contributor type="primary"><name>Jane Doe</name></contributor><contributor><name>Leviticus Alabaster</name></contributor></entry>'
16
+ expect(entry.to_s).to eq(expected_xml)
36
17
  end
37
- end
18
+ end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Saxerator::FullDocument#all" do
3
+ describe 'Saxerator::FullDocument#all' do
4
4
  subject(:parser) { Saxerator.parser(xml) }
5
5
 
6
6
  let(:xml) do
@@ -15,17 +15,22 @@ describe "Saxerator::FullDocument#all" do
15
15
  eos
16
16
  end
17
17
 
18
- it "should allow you to parse an entire document" do
19
- expect(parser.all).to eq 'blurb' => ['one', 'two', 'three'], 'notablurb' => 'four', 'empty' => {}
18
+ it 'allows you to parse an entire document' do
19
+ expect(parser.all)
20
+ .to eq 'blurb' => ['one', 'two', 'three'], 'notablurb' => 'four', 'empty' => {}
20
21
  end
21
22
 
22
- context "with_put_attributes_in_hash" do
23
+ context 'with_put_attributes_in_hash' do
23
24
  subject(:parser) do
24
25
  Saxerator.parser(xml) { |config| config.put_attributes_in_hash! }
25
26
  end
26
27
 
27
- it "should allow you to parse an entire document" do
28
- expect(parser.all).to eq 'blurb' => ['one', 'two', 'three'], 'notablurb' => 'four', 'empty' => { "with" => "attribute" }
28
+ it 'allows you to parse an entire document' do
29
+ expect(parser.all).to eq(
30
+ 'blurb' => ['one', 'two', 'three'],
31
+ 'notablurb' => 'four',
32
+ 'empty' => { 'with' => 'attribute' }
33
+ )
29
34
  end
30
35
  end
31
36
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Saxerator::DSL#at_depth" do
3
+ describe 'Saxerator::DSL#at_depth' do
4
4
  subject(:parser) { Saxerator.parser(xml) }
5
5
 
6
6
  let(:xml) do
@@ -18,17 +18,19 @@ describe "Saxerator::DSL#at_depth" do
18
18
  eos
19
19
  end
20
20
 
21
- it "should parse elements at the requested tag depth" do
21
+ it 'parses elements at the requested tag depth' do
22
22
  expect(parser.at_depth(2).inject([], :<<)).to eq([
23
- 'How to eat an airplane', 'Leviticus Alabaster',
24
- 'To wallop a horse in the face', 'Jeanne Clarewood'
23
+ 'How to eat an airplane',
24
+ 'Leviticus Alabaster',
25
+ 'To wallop a horse in the face',
26
+ 'Jeanne Clarewood'
25
27
  ])
26
28
  end
27
29
 
28
- it "should work in combination with #for_tag" do
30
+ it 'works in combination with #for_tag' do
29
31
  expect(parser.at_depth(2).for_tag(:name).inject([], :<<)).to eq([
30
- 'How to eat an airplane',
31
- 'To wallop a horse in the face'
32
+ 'How to eat an airplane',
33
+ 'To wallop a horse in the face'
32
34
  ])
33
35
  end
34
- end
36
+ end
@@ -1,11 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Saxerator::DSL#child_of" do
3
+ describe 'Saxerator::DSL#child_of' do
4
4
  subject(:parser) { Saxerator.parser(xml) }
5
5
 
6
6
  let(:xml) do
7
- <<-eos
8
- <root>
7
+ <<-eos
8
+ <root>
9
9
  <children>
10
10
  <name>Rudy McMannis</name>
11
11
  <children>
@@ -20,17 +20,17 @@ describe "Saxerator::DSL#child_of" do
20
20
  eos
21
21
  end
22
22
 
23
- it "should only parse children of the specified tag" do
23
+ it 'only parses children of the specified tag' do
24
24
  expect(parser.child_of(:grandchildren).inject([], :<<)).to eq([
25
25
  'Mildred Marston'
26
26
  ])
27
27
  end
28
28
 
29
- it "should work in combination with #for_tag" do
29
+ it 'works in combination with #for_tag' do
30
30
  expect(parser.for_tag(:name).child_of(:children).inject([], :<<)).to eq([
31
31
  'Rudy McMannis',
32
32
  'Tom McMannis',
33
33
  'Anne Welsh'
34
34
  ])
35
35
  end
36
- end
36
+ end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Saxerator::DSL#for_tag" do
3
+ describe 'Saxerator::DSL#for_tag' do
4
4
  subject(:parser) { Saxerator.parser(xml) }
5
5
 
6
6
  let(:xml) do
@@ -14,7 +14,7 @@ describe "Saxerator::DSL#for_tag" do
14
14
  eos
15
15
  end
16
16
 
17
- it "should only select the specified tag" do
17
+ it 'only selects the specified tag' do
18
18
  expect(parser.for_tag(:blurb).inject([], :<<)).to eq(['one', 'two', 'three'])
19
19
  end
20
- end
20
+ end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Saxerator::DSL#for_tags" do
3
+ describe 'Saxerator::DSL#for_tags' do
4
4
  subject(:parser) { Saxerator.parser(xml) }
5
5
 
6
6
  let(:xml) do
@@ -13,11 +13,11 @@ describe "Saxerator::DSL#for_tags" do
13
13
  eos
14
14
  end
15
15
 
16
- it "should only select the specified tags" do
16
+ it 'only selects the specified tags' do
17
17
  expect(parser.for_tags(%w(blurb1 blurb3)).inject([], :<<)).to eq(['one', 'three'])
18
18
  end
19
19
 
20
- it "raises an ArgumentError for a non-Array argument" do
21
- expect { parser.for_tags("asdf") }.to raise_error ArgumentError
20
+ it 'raises an ArgumentError for a non-Array argument' do
21
+ expect { parser.for_tags('asdf') }.to raise_error ArgumentError
22
22
  end
23
- end
23
+ end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Saxerator::DSL#with_attribute" do
3
+ describe 'Saxerator::DSL#with_attribute' do
4
4
  subject(:parser) { Saxerator.parser(xml) }
5
5
 
6
6
  let(:xml) do
@@ -15,14 +15,14 @@ describe "Saxerator::DSL#with_attribute" do
15
15
  eos
16
16
  end
17
17
 
18
- it "should match tags with the specified attributes" do
18
+ it 'matches tags with the specified attributes' do
19
19
  expect(subject.with_attribute(:type).inject([], :<<)).to eq([
20
20
  'Leviticus Alabaster',
21
21
  'Eunice Diesel'
22
22
  ])
23
23
  end
24
24
 
25
- it "should match tags with the specified attributes" do
25
+ it 'matches tags with the specified attributes' do
26
26
  expect(subject.with_attribute(:type, :primary).inject([], :<<)).to eq(['Leviticus Alabaster'])
27
27
  end
28
- end
28
+ end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Saxerator::DSL#with_attributes" do
3
+ describe 'Saxerator::DSL#with_attributes' do
4
4
  subject(:parser) { Saxerator.parser(xml) }
5
5
 
6
6
  let(:xml) do
@@ -16,17 +16,18 @@ describe "Saxerator::DSL#with_attributes" do
16
16
  eos
17
17
  end
18
18
 
19
- it "matches tags with the exact specified attributes" do
20
- expect(parser.with_attributes(:type => :primary, :ridiculous => 'true').inject([], :<<)).to eq([
19
+ it 'matches tags with the exact specified attributes' do
20
+ expect(parser.with_attributes(type: :primary, ridiculous: 'true').inject([], :<<)).to eq([
21
21
  'Leviticus Alabaster'
22
22
  ])
23
23
  end
24
24
 
25
- it "matches tags which have the specified attributes" do
26
- expect(parser.with_attributes(%w(type ridiculous)).inject([], :<<)).to eq(['Leviticus Alabaster', 'Eunice Diesel'])
25
+ it 'matches tags which have the specified attributes' do
26
+ expect(parser.with_attributes(%w(type ridiculous)).inject([], :<<))
27
+ .to eq(['Leviticus Alabaster', 'Eunice Diesel'])
27
28
  end
28
29
 
29
- it "raises ArgumentError if you pass something other than a Hash or Array" do
30
+ it 'raises ArgumentError if you pass something other than a Hash or Array' do
30
31
  expect { parser.with_attributes('asdf') }.to raise_error ArgumentError
31
32
  end
32
- end
33
+ end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Saxerator::DSL#within" do
3
+ describe 'Saxerator::DSL#within' do
4
4
  subject(:parser) { Saxerator.parser(xml) }
5
5
 
6
6
  let(:xml) do
@@ -15,14 +15,15 @@ describe "Saxerator::DSL#within" do
15
15
  eos
16
16
  end
17
17
 
18
- it "should only parse elements nested within the specified tag" do
18
+ it 'only parses elements nested within the specified tag' do
19
19
  expect(parser.within(:article).inject([], :<<)).to eq([
20
20
  'Is our children learning?',
21
21
  'Hazel Nutt'
22
22
  ])
23
23
  end
24
24
 
25
- it "should work in combination with #for_tag" do
26
- expect(parser.for_tag(:name).within(:article).inject([], :<<)).to eq(['Is our children learning?'])
25
+ it 'works in combination with #for_tag' do
26
+ expect(parser.for_tag(:name).within(:article).inject([], :<<))
27
+ .to eq(['Is our children learning?'])
27
28
  end
28
- end
29
+ end
@@ -1,19 +1,19 @@
1
- # encoding: utf-8
2
-
3
1
  require 'spec_helper'
4
2
 
5
- describe Saxerator do
6
- context "#parser" do
7
- subject(:parser) { Saxerator.parser(xml) }
3
+ RSpec.describe Saxerator do
4
+ context '#parser' do
5
+ subject(:parser) do
6
+ Saxerator.parser(xml)
7
+ end
8
8
 
9
- context "with a File argument" do
9
+ context 'with a File argument' do
10
10
  let(:xml) { fixture_file('flat_blurbs.xml') }
11
11
 
12
- it "should be able to parse it" do
13
- expect(parser.all).to eq({'blurb' => ['one', 'two', 'three']})
12
+ it 'can parse it' do
13
+ expect(parser.all).to eq('blurb' => %w(one two three))
14
14
  end
15
15
 
16
- it "should allow multiple operations on the same parser" do
16
+ it 'allows multiple operations on the same parser' do
17
17
  # This exposes a bug where if a File is not reset only the first
18
18
  # Enumerable method works as expected
19
19
  expect(parser.for_tag(:blurb).first).to eq('one')
@@ -21,48 +21,50 @@ describe Saxerator do
21
21
  end
22
22
  end
23
23
 
24
- context "with a String argument" do
24
+ context 'with a String argument' do
25
25
  let(:xml) do
26
26
  <<-eos
27
- <book>
28
- <name>Illiterates that can read</name>
29
- <author>Eunice Diesel</author>
30
- </book>
27
+ <book>
28
+ <name>Illiterates that can read</name>
29
+ <author>Eunice Diesel</author>
30
+ </book>
31
31
  eos
32
32
  end
33
33
 
34
- it "should be able to parse it" do
35
- expect(parser.all).to eq({ 'name' => 'Illiterates that can read', 'author' => 'Eunice Diesel' })
34
+ it 'can parse it' do
35
+ expect(parser.all).to eq('name' => 'Illiterates that can read', 'author' => 'Eunice Diesel')
36
36
  end
37
37
  end
38
38
  end
39
39
 
40
- context "configuration" do
40
+ context 'configuration' do
41
41
  let(:xml) { '<foo><bar foo="bar">baz</bar></foo>' }
42
42
 
43
- context "output type" do
43
+ context 'output type' do
44
44
  subject(:parser) do
45
- Saxerator.parser(xml) { |config| config.output_type = output_type }
45
+ Saxerator.parser(xml) do |config|
46
+ config.output_type = output_type
47
+ end
46
48
  end
47
49
 
48
- context "with config.output_type = :hash" do
50
+ context 'with config.output_type = :hash' do
49
51
  let(:output_type) { :hash }
50
52
  specify { expect(parser.all).to eq('bar' => 'baz') }
51
53
  end
52
54
 
53
- context "with config.output_type = :xml" do
55
+ context 'with config.output_type = :xml' do
54
56
  let(:output_type) { :xml }
55
- specify { expect(parser.all).to be_a Nokogiri::XML::Document }
57
+ specify { expect(parser.all).to be_a REXML::Document }
56
58
  specify { expect(parser.all.to_s).to include '<bar foo="bar">' }
57
59
  end
58
60
 
59
- context "with an invalid config.output_type" do
61
+ context 'with an invalid config.output_type' do
60
62
  let(:output_type) { 'lmao' }
61
63
  specify { expect { parser }.to raise_error(ArgumentError) }
62
64
  end
63
65
  end
64
66
 
65
- context "symbolize keys" do
67
+ context 'symbolize keys' do
66
68
  subject(:parser) do
67
69
  Saxerator.parser(xml) do |config|
68
70
  config.symbolize_keys!
@@ -70,50 +72,59 @@ describe Saxerator do
70
72
  end
71
73
  end
72
74
 
73
- specify { expect(parser.all).to eq(:bar => 'baz') }
75
+ specify { expect(parser.all).to eq(bar: 'baz') }
74
76
  specify { expect(parser.all.name).to eq(:foo) }
75
77
 
76
78
  it 'will symbolize attributes' do
77
79
  parser.for_tag('bar').each do |tag|
78
- expect(tag.attributes).to include(:foo => 'bar')
80
+ expect(tag.attributes).to include(foo: 'bar')
79
81
  end
80
82
  end
81
83
  end
82
84
 
83
- context "with ignore namespaces" do
84
- let(:xml) { <<-eos
85
- <ns1:foo xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ns1="http://foo.com" xmlns:ns3="http://bar.com">
86
- <ns3:bar>baz</ns3:bar>
87
- <ns3:bar bar="bar" ns1:foo="foo" class="class">bax</ns3:bar>
88
- </ns1:foo>
89
- eos
90
- }
85
+ context 'with ignore namespaces' do
86
+ let(:xml) do
87
+ <<-eos
88
+ <ns1:foo xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ns1="http://foo.com" xmlns:ns3="http://bar.com">
89
+ <ns3:bar>baz</ns3:bar>
90
+ <ns3:bar bar="bar" ns1:foo="foo" class="class">bax</ns3:bar>
91
+ </ns1:foo>
92
+ eos
93
+ end
91
94
 
92
95
  subject(:parser) do
93
- Saxerator.parser(xml) { |config|
96
+ Saxerator.parser(xml) do |config|
94
97
  config.ignore_namespaces!
95
- }
98
+ end
96
99
  end
97
100
 
98
- specify {
101
+ specify do
99
102
  bar_count = 0
100
- parser.for_tag("bar").each do |tag|
103
+ parser.for_tag('bar').each do |_|
101
104
  bar_count += 1
102
105
  end
103
106
  expect(bar_count).to eq(2)
104
- }
107
+ end
105
108
  end
106
109
 
107
- context "with strip namespaces" do
108
- let(:xml) { "<ns1:foo><ns3:bar>baz</ns3:bar></ns1:foo>" }
110
+ context 'with strip namespaces' do
111
+ let(:xml) do
112
+ <<-XML
113
+ <ns1:foo xmlns:ns1="http://foo.com" xmlns:ns3="http://baz.com">
114
+ <ns3:bar>baz</ns3:bar>
115
+ </ns1:foo>
116
+ XML
117
+ end
109
118
  subject(:parser) do
110
- Saxerator.parser(xml) { |config| config.strip_namespaces! }
119
+ Saxerator.parser(xml) do |config|
120
+ config.strip_namespaces!
121
+ end
111
122
  end
112
123
 
113
- specify { expect(parser.all).to eq({'bar' => 'baz'}) }
124
+ specify { expect(parser.all).to eq('bar' => 'baz') }
114
125
  specify { expect(parser.all.name).to eq('foo') }
115
126
 
116
- context "combined with symbolize keys" do
127
+ context 'combined with symbolize keys' do
117
128
  subject(:parser) do
118
129
  Saxerator.parser(xml) do |config|
119
130
  config.strip_namespaces!
@@ -121,30 +132,31 @@ describe Saxerator do
121
132
  end
122
133
  end
123
134
 
124
- specify { expect(parser.all).to eq({:bar => 'baz'}) }
135
+ specify { expect(parser.all).to eq(bar: 'baz') }
125
136
  end
126
137
 
127
- context "for specific namespaces" do
138
+ context 'for specific namespaces' do
128
139
  let(:xml) do
129
- <<-XML.gsub /^ {10}/, ''
130
- <ns1:foo>
131
- <ns2:bar>baz</ns2:bar>
132
- <ns3:bar>biz</ns3:bar>
140
+ <<-XML
141
+ <ns1:foo xmlns:ns1="http://foo.com" xmlns:ns2="http://bar.com" xmlns:ns3="http://baz.com">
142
+ <ns2:bar>baz</ns2:bar>
143
+ <ns3:bar>biz</ns3:bar>
133
144
  </ns1:foo>
134
145
  XML
135
146
  end
136
147
  subject(:parser) do
137
- Saxerator.parser(xml) { |config| config.strip_namespaces! :ns1, :ns3 }
148
+ Saxerator.parser(xml) do |config|
149
+ config.strip_namespaces! :ns1, :ns3
150
+ end
138
151
  end
139
152
 
140
- specify { expect(parser.all).to eq({'ns2:bar' => 'baz', 'bar' => 'biz'}) }
153
+ specify { expect(parser.all).to eq('ns2:bar' => 'baz', 'bar' => 'biz') }
141
154
  specify { expect(parser.all.name).to eq('foo') }
142
155
  end
143
156
  end
144
-
145
157
  end
146
158
 
147
- context "configuration with put_attributes_in_hash!" do
159
+ context 'configuration with put_attributes_in_hash!' do
148
160
  let(:xml) { '<foo foo="bar"><bar>baz</bar></foo>' }
149
161
 
150
162
  subject(:parser) do
@@ -153,8 +165,8 @@ describe Saxerator do
153
165
  end
154
166
  end
155
167
 
156
- it "should be able to parse it" do
157
- expect(parser.all).to eq({ 'bar' => 'baz', 'foo' => 'bar' })
168
+ it 'can parse it' do
169
+ expect(parser.all).to eq('bar' => 'baz', 'foo' => 'bar')
158
170
  end
159
171
 
160
172
  context 'with configured output_type :xml' do
@@ -165,7 +177,7 @@ describe Saxerator do
165
177
  end
166
178
  end
167
179
 
168
- context "should raise error with " do
180
+ context 'raises error with' do
169
181
  specify { expect { parser }.to raise_error(ArgumentError) }
170
182
  end
171
183
  end
@@ -179,7 +191,7 @@ describe Saxerator do
179
191
  end
180
192
 
181
193
  it 'will symbolize attribute hash keys' do
182
- expect(parser.all).to include(:bar => 'baz', :foo => 'bar')
194
+ expect(parser.all.to_hash).to include(bar: 'baz', foo: 'bar')
183
195
  end
184
196
  end
185
197
  end