nfe_reader 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +23 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +38 -0
  6. data/Rakefile +13 -0
  7. data/lib/nfe_reader/authorization.rb +12 -0
  8. data/lib/nfe_reader/carrier.rb +16 -0
  9. data/lib/nfe_reader/collection/duplicate.rb +12 -0
  10. data/lib/nfe_reader/collection.rb +34 -0
  11. data/lib/nfe_reader/customer.rb +62 -0
  12. data/lib/nfe_reader/delivery.rb +20 -0
  13. data/lib/nfe_reader/document.rb +73 -0
  14. data/lib/nfe_reader/export.rb +12 -0
  15. data/lib/nfe_reader/fiscal.rb +33 -0
  16. data/lib/nfe_reader/header.rb +129 -0
  17. data/lib/nfe_reader/information.rb +38 -0
  18. data/lib/nfe_reader/product/armament.rb +22 -0
  19. data/lib/nfe_reader/product/cane.rb +42 -0
  20. data/lib/nfe_reader/product/exportation.rb +20 -0
  21. data/lib/nfe_reader/product/fuel.rb +18 -0
  22. data/lib/nfe_reader/product/importation.rb +49 -0
  23. data/lib/nfe_reader/product/medicament.rb +19 -0
  24. data/lib/nfe_reader/product/vehicle.rb +117 -0
  25. data/lib/nfe_reader/product.rb +90 -0
  26. data/lib/nfe_reader/provider.rb +43 -0
  27. data/lib/nfe_reader/purchase.rb +14 -0
  28. data/lib/nfe_reader/removal.rb +20 -0
  29. data/lib/nfe_reader/taxation/cofins.rb +43 -0
  30. data/lib/nfe_reader/taxation/cofins_st.rb +19 -0
  31. data/lib/nfe_reader/taxation/icms.rb +86 -0
  32. data/lib/nfe_reader/taxation/importation_tax.rb +17 -0
  33. data/lib/nfe_reader/taxation/ipi.rb +41 -0
  34. data/lib/nfe_reader/taxation/issqn.rb +22 -0
  35. data/lib/nfe_reader/taxation/pis.rb +42 -0
  36. data/lib/nfe_reader/taxation/pis_st.rb +19 -0
  37. data/lib/nfe_reader/total.rb +76 -0
  38. data/lib/nfe_reader/transport.rb +97 -0
  39. data/lib/nfe_reader/version.rb +5 -0
  40. data/lib/nfe_reader.rb +129 -0
  41. data/lib/nokogiri_hash.rb +60 -0
  42. data/nfe-reader.gemspec +24 -0
  43. data/test/files/sample-nfe.xml +234 -0
  44. data/test/files/sample2-nfe.xml +192 -0
  45. data/test/nfe_reader/authorization_test.rb +22 -0
  46. data/test/nfe_reader/cane_test.rb +71 -0
  47. data/test/nfe_reader/carrier_test.rb +46 -0
  48. data/test/nfe_reader/collection/duplicate_test.rb +27 -0
  49. data/test/nfe_reader/collection_test.rb +78 -0
  50. data/test/nfe_reader/customer_test.rb +133 -0
  51. data/test/nfe_reader/delivery_test.rb +57 -0
  52. data/test/nfe_reader/document_test.rb +113 -0
  53. data/test/nfe_reader/export_test.rb +22 -0
  54. data/test/nfe_reader/fiscal_test.rb +67 -0
  55. data/test/nfe_reader/header_test.rb +135 -0
  56. data/test/nfe_reader/information_test.rb +37 -0
  57. data/test/nfe_reader/product/armament_test.rb +32 -0
  58. data/test/nfe_reader/product/exportation_test.rb +34 -0
  59. data/test/nfe_reader/product/fuel_test.rb +44 -0
  60. data/test/nfe_reader/product/importation_test.rb +64 -0
  61. data/test/nfe_reader/product/medicament_test.rb +37 -0
  62. data/test/nfe_reader/product/vehicle_test.rb +133 -0
  63. data/test/nfe_reader/product_test.rb +125 -0
  64. data/test/nfe_reader/provider_test.rb +155 -0
  65. data/test/nfe_reader/purchase_test.rb +27 -0
  66. data/test/nfe_reader/removal_test.rb +57 -0
  67. data/test/nfe_reader/taxation/cofins_st_test.rb +37 -0
  68. data/test/nfe_reader/taxation/cofins_test.rb +42 -0
  69. data/test/nfe_reader/taxation/icms_test.rb +122 -0
  70. data/test/nfe_reader/taxation/importation_tax_test.rb +32 -0
  71. data/test/nfe_reader/taxation/ipi_test.rb +78 -0
  72. data/test/nfe_reader/taxation/issqn_test.rb +42 -0
  73. data/test/nfe_reader/taxation/pis_st_test.rb +37 -0
  74. data/test/nfe_reader/taxation/pis_test.rb +42 -0
  75. data/test/nfe_reader/total_test.rb +148 -0
  76. data/test/nfe_reader/transport_test.rb +172 -0
  77. data/test/nfe_reader_test.rb +125 -0
  78. data/test/nokogiri_test.rb +27 -0
  79. data/test/test_helper.rb +13 -0
  80. metadata +201 -0
@@ -0,0 +1,32 @@
1
+ require File.expand_path("../../../test_helper", __FILE__)
2
+
3
+ describe Nfe::ImportationTax do
4
+ def nfe_hash
5
+ {
6
+ II: {
7
+ vBC: '100.00',
8
+ vDespAdu: '17.00',
9
+ vII: '17.00',
10
+ vIOF: '5.00'
11
+ }
12
+ }
13
+ end
14
+
15
+ let(:cofins) { Nfe::ImportationTax.new(nfe_hash[:II]) }
16
+
17
+ it '#base' do
18
+ cofins.base.must_equal '100.00'
19
+ end
20
+
21
+ it '#expenditure' do
22
+ cofins.expenditure.must_equal '17.00'
23
+ end
24
+
25
+ it '#taxes' do
26
+ cofins.taxes.must_equal '17.00'
27
+ end
28
+
29
+ it '#iof' do
30
+ cofins.iof.must_equal '5.00'
31
+ end
32
+ end
@@ -0,0 +1,78 @@
1
+ require File.expand_path("../../../test_helper", __FILE__)
2
+
3
+ describe Nfe::Ipi do
4
+ def nfe_hash
5
+ {
6
+ ipi: {
7
+ clEnq: '0',
8
+ cEnq: '0',
9
+ CNPJProd: '99819146000120',
10
+ cSelo: '0',
11
+ qSelo: '0',
12
+
13
+ IPITrib: {
14
+ CST: '20',
15
+ vBC: '100.00',
16
+ qUnid: '0.00',
17
+ vUnid: '0.00',
18
+ pIPI: '15.00',
19
+ vIPI: '15.00',
20
+ },
21
+
22
+ IPINT:{
23
+ CST: '10'
24
+ }
25
+ }
26
+ }
27
+ end
28
+
29
+ let(:ipi) { Nfe::Ipi.new(nfe_hash[:ipi]) }
30
+
31
+ it '#frame_class' do
32
+ ipi.frame_class.must_equal '0'
33
+ end
34
+
35
+ it '#frame_code' do
36
+ ipi.frame_code.must_equal '0'
37
+ end
38
+
39
+ it '#cnpj' do
40
+ ipi.cnpj.must_equal '99819146000120'
41
+ end
42
+
43
+ it '#seal' do
44
+ ipi.seal.must_equal '0'
45
+ end
46
+
47
+ it '#seal_amount' do
48
+ ipi.seal_amount.must_equal '0'
49
+ end
50
+
51
+ it '#cst' do
52
+ ipi.cst.must_equal '20'
53
+ end
54
+
55
+ it '#ipi_base' do
56
+ ipi.ipi_base.must_equal '100.00'
57
+ end
58
+
59
+ it '#amount' do
60
+ ipi.amount.must_equal '0.00'
61
+ end
62
+
63
+ it '#value_unit' do
64
+ ipi.value_unit.must_equal '0.00'
65
+ end
66
+
67
+ it '#percentage' do
68
+ ipi.percentage.must_equal '15.00'
69
+ end
70
+
71
+ it '#value' do
72
+ ipi.value.must_equal '15.00'
73
+ end
74
+
75
+ it '#cst_group' do
76
+ ipi.cst_group.must_equal '10'
77
+ end
78
+ end
@@ -0,0 +1,42 @@
1
+ require File.expand_path("../../../test_helper", __FILE__)
2
+
3
+ describe Nfe::Issqn do
4
+ def nfe_hash
5
+ {
6
+ issqn: {
7
+ vBC: '100.00',
8
+ vISSQN: '17.00',
9
+ cMunFG: '1467',
10
+ cListServ: '0',
11
+ vAliq: '17.00',
12
+ cSitTrib: '10',
13
+ }
14
+ }
15
+ end
16
+
17
+ let(:issqn) { Nfe::Issqn.new(nfe_hash[:issqn]) }
18
+
19
+ it '#cst' do
20
+ issqn.cst.must_equal '10'
21
+ end
22
+
23
+ it '#base' do
24
+ issqn.base.must_equal '100.00'
25
+ end
26
+
27
+ it '#aliquot' do
28
+ issqn.aliquot.must_equal '17.00'
29
+ end
30
+
31
+ it '#value' do
32
+ issqn.value.must_equal '17.00'
33
+ end
34
+
35
+ it '#city' do
36
+ issqn.city.must_equal '1467'
37
+ end
38
+
39
+ it '#services' do
40
+ issqn.services.must_equal '0'
41
+ end
42
+ end
@@ -0,0 +1,37 @@
1
+ require File.expand_path("../../../test_helper", __FILE__)
2
+
3
+ describe Nfe::PisSt do
4
+ def nfe_hash
5
+ {
6
+ pisst: {
7
+ vBC: '100.00',
8
+ pPIS: '17.00',
9
+ vPIS: '17.00',
10
+ qBCProd: '0',
11
+ vAliqProd: '0'
12
+ }
13
+ }
14
+ end
15
+
16
+ let(:pis) { Nfe::PisSt.new(nfe_hash[:pisst]) }
17
+
18
+ it '#base' do
19
+ pis.base.must_equal '100.00'
20
+ end
21
+
22
+ it '#percentage' do
23
+ pis.percentage.must_equal '17.00'
24
+ end
25
+
26
+ it '#value' do
27
+ pis.value.must_equal '17.00'
28
+ end
29
+
30
+ it '#amount' do
31
+ pis.amount.must_equal '0'
32
+ end
33
+
34
+ it '#aliquot' do
35
+ pis.aliquot.must_equal '0'
36
+ end
37
+ end
@@ -0,0 +1,42 @@
1
+ require File.expand_path("../../../test_helper", __FILE__)
2
+
3
+ describe Nfe::Pis do
4
+ def nfe_hash
5
+ {
6
+ pis: {
7
+ CST: '10',
8
+ vBC: '100.00',
9
+ pPIS: '17.00',
10
+ vPIS: '17.00',
11
+ qBCProd: '0',
12
+ vAliqProd: '0'
13
+ }
14
+ }
15
+ end
16
+
17
+ let(:pis) { Nfe::Pis.new(nfe_hash[:pis]) }
18
+
19
+ it '#cst' do
20
+ pis.cst.must_equal '10'
21
+ end
22
+
23
+ it '#base' do
24
+ pis.base.must_equal '100.00'
25
+ end
26
+
27
+ it '#percentage' do
28
+ pis.percentage.must_equal '17.00'
29
+ end
30
+
31
+ it '#value' do
32
+ pis.value.must_equal '17.00'
33
+ end
34
+
35
+ it '#amount' do
36
+ pis.amount.must_equal '0'
37
+ end
38
+
39
+ it '#aliquot' do
40
+ pis.aliquot.must_equal '0'
41
+ end
42
+ end
@@ -0,0 +1,148 @@
1
+ require File.expand_path("../../test_helper", __FILE__)
2
+
3
+ describe Nfe::Total do
4
+ def nfe_hash
5
+ {
6
+ total: {
7
+ ICMSTot: {
8
+ vBC: '1000.00',
9
+ vICMS: '500.00',
10
+ vBCST: '200.00',
11
+ vST: '50.00',
12
+ vProd: '750.00',
13
+ vFrete: '10.00',
14
+ vSeg: '45.00',
15
+ vDesc: '12.00',
16
+ vII: '0.00',
17
+ vIPI: '12.00',
18
+ vPIS: '4.00',
19
+ vCOFINS: '16.00',
20
+ vOutro: '15.99',
21
+ vNF: '1250.00'
22
+ },
23
+ ISSQNtot: {
24
+ vServ: '125.00',
25
+ vBC: '100.00',
26
+ vISS: '10.00',
27
+ vPIS: '2.00',
28
+ vCOFINS: '4.00'
29
+ },
30
+ retTrib:{
31
+ vRetPIS: '1.00',
32
+ vRetCOFINS: '2.00',
33
+ vRetCSLL: '5.00',
34
+ vBCIRRF: '10.00',
35
+ vIRRF: '1.50',
36
+ vBCRetPrev: '100.00',
37
+ vRetPrev: '25.00'
38
+ }
39
+ }
40
+ }
41
+ end
42
+
43
+ let(:total) { Nfe::Total.new(nfe_hash[:total]) }
44
+
45
+ it '#icms_base' do
46
+ total.icms_base.must_equal '1000.00'
47
+ end
48
+
49
+ it '#icms' do
50
+ total.icms.must_equal '500.00'
51
+ end
52
+
53
+ it '#st_base' do
54
+ total.st_base.must_equal '200.00'
55
+ end
56
+
57
+ it '#st' do
58
+ total.st.must_equal '50.00'
59
+ end
60
+
61
+ it '#product' do
62
+ total.product.must_equal '750.00'
63
+ end
64
+
65
+ it '#freight' do
66
+ total.freight.must_equal '10.00'
67
+ end
68
+
69
+ it '#insurance' do
70
+ total.insurance.must_equal '45.00'
71
+ end
72
+
73
+ it '#descount' do
74
+ total.descount.must_equal '12.00'
75
+ end
76
+
77
+ it '#ii' do
78
+ total.ii.must_equal '0.00'
79
+ end
80
+
81
+ it '#ipi' do
82
+ total.ipi.must_equal '12.00'
83
+ end
84
+
85
+ it '#pis' do
86
+ total.pis.must_equal '4.00'
87
+ end
88
+
89
+ it '#cofins' do
90
+ total.cofins.must_equal '16.00'
91
+ end
92
+
93
+ it '#another' do
94
+ total.another.must_equal '15.99'
95
+ end
96
+
97
+ it '#total' do
98
+ total.total.must_equal '1250.00'
99
+ end
100
+
101
+ it '#service_value' do
102
+ total.service_value.must_equal '125.00'
103
+ end
104
+
105
+ it '#service_base' do
106
+ total.service_base.must_equal '100.00'
107
+ end
108
+
109
+ it '#service_iss' do
110
+ total.service_iss.must_equal '10.00'
111
+ end
112
+
113
+ it '#service_pis' do
114
+ total.service_pis.must_equal '2.00'
115
+ end
116
+
117
+ it '#service_cofins' do
118
+ total.service_cofins.must_equal '4.00'
119
+ end
120
+
121
+ it '#retention_pis' do
122
+ total.retention_pis.must_equal '1.00'
123
+ end
124
+
125
+ it '#retention_cofins' do
126
+ total.retention_cofins.must_equal '2.00'
127
+ end
128
+
129
+ it '#retention_csll' do
130
+ total.retention_csll.must_equal '5.00'
131
+ end
132
+
133
+ it '#retention_irrf_base' do
134
+ total.retention_irrf_base.must_equal '10.00'
135
+ end
136
+
137
+ it '#retention_irrf' do
138
+ total.retention_irrf.must_equal '1.50'
139
+ end
140
+
141
+ it '#retention_foresight_base' do
142
+ total.retention_foresight_base.must_equal '100.00'
143
+ end
144
+
145
+ it '#retention_foresight' do
146
+ total.retention_foresight.must_equal '25.00'
147
+ end
148
+ end
@@ -0,0 +1,172 @@
1
+ require File.expand_path("../../test_helper", __FILE__)
2
+
3
+ describe Nfe::Transport do
4
+ def transport_hash
5
+ {
6
+ transport: {
7
+ modFrete: '1',
8
+
9
+ retTransp: {
10
+ vServ: '1000.00',
11
+ vBCRet: '1000.00',
12
+ pICMSRet: '12.00',
13
+ vICMSRet: '120.00',
14
+ CFOP: '1111',
15
+ cMunFG: '1356'
16
+ },
17
+
18
+ veicTransp:{
19
+ placa: 'BBB-1210',
20
+ UF: 'UF',
21
+ RNTC: '1129853'
22
+ },
23
+
24
+ reboque: {
25
+ placa: 'AAA-1210',
26
+ UF: 'ST',
27
+ RNTC: '139754'
28
+ },
29
+
30
+ vagao: '0010',
31
+ balsa: '1000',
32
+
33
+ vol: {
34
+ qVol: '1',
35
+ esp: '1',
36
+ marca: '1',
37
+ nVol: '1',
38
+ pesoL: '100',
39
+ pesoB: '130',
40
+ lacres: {
41
+ nLacre: '1234567890'
42
+ }
43
+ },
44
+
45
+ transporta: {
46
+ CNPJ: '99819146000120',
47
+ xNome: 'Carrier',
48
+ IE: '15786913',
49
+ xEnder: 'Address',
50
+ xMun: 'City',
51
+ UF: 'ST'
52
+ }
53
+ }
54
+ }
55
+ end
56
+
57
+ def seals_hash
58
+ {
59
+ transport: {
60
+ vol: {
61
+ lacres: [
62
+ { nLacre: '1234567890' },
63
+ { nLacre: '1239126304' },
64
+ { nLacre: '1231313123' }
65
+ ]
66
+ },
67
+ }
68
+ }
69
+ end
70
+
71
+ let(:transport) { Nfe::Transport.new(transport_hash[:transport]) }
72
+
73
+ it '#kind' do
74
+ transport.kind.must_equal '1'
75
+ end
76
+
77
+ it '#service_value' do
78
+ transport.service_value.must_equal '1000.00'
79
+ end
80
+
81
+ it '#base' do
82
+ transport.base.must_equal '1000.00'
83
+ end
84
+
85
+ it '#icms_aliquot' do
86
+ transport.icms_aliquot.must_equal '12.00'
87
+ end
88
+
89
+ it '#icms_value' do
90
+ transport.icms_value.must_equal '120.00'
91
+ end
92
+
93
+ it '#cfop' do
94
+ transport.cfop.must_equal '1111'
95
+ end
96
+
97
+ it '#city' do
98
+ transport.city.must_equal '1356'
99
+ end
100
+
101
+ it '#vehicle_plaque' do
102
+ transport.vehicle_plaque.must_equal 'BBB-1210'
103
+ end
104
+
105
+ it '#vehicle_state' do
106
+ transport.vehicle_state.must_equal 'UF'
107
+ end
108
+
109
+ it '#vehicle_rntc' do
110
+ transport.vehicle_rntc.must_equal '1129853'
111
+ end
112
+
113
+ it '#hauling_palque' do
114
+ transport.hauling_palque.must_equal 'AAA-1210'
115
+ end
116
+
117
+ it '#hauling_state' do
118
+ transport.hauling_state.must_equal 'ST'
119
+ end
120
+
121
+ it '#hauling_rntc' do
122
+ transport.hauling_rntc.must_equal '139754'
123
+ end
124
+
125
+ it '#wagon' do
126
+ transport.wagon.must_equal '0010'
127
+ end
128
+
129
+ it '#ferry' do
130
+ transport.ferry.must_equal '1000'
131
+ end
132
+
133
+ it '#volume_amount' do
134
+ transport.volume_amount.must_equal '1'
135
+ end
136
+
137
+ it '#volume_kind' do
138
+ transport.volume_kind.must_equal '1'
139
+ end
140
+
141
+ it '#volume_brand' do
142
+ transport.volume_brand.must_equal '1'
143
+ end
144
+
145
+ it '#volume_number' do
146
+ transport.volume_number.must_equal '1'
147
+ end
148
+
149
+ it '#weight_net' do
150
+ transport.weight_net.must_equal '100'
151
+ end
152
+
153
+ it '#weight_gross' do
154
+ transport.weight_gross.must_equal '130'
155
+ end
156
+
157
+ it '#seals' do
158
+ transport.seals.must_equal '1234567890'
159
+ end
160
+
161
+ it '#carrier' do
162
+ transport.carrier.wont_be_nil
163
+ end
164
+
165
+ describe 'seals' do
166
+ let(:transport) { Nfe::Transport.new(seals_hash[:transport]) }
167
+
168
+ it 'have a string with all seal' do
169
+ transport.seals.must_equal '1234567890, 1239126304, 1231313123'
170
+ end
171
+ end
172
+ end
@@ -0,0 +1,125 @@
1
+ require File.expand_path("../test_helper", __FILE__)
2
+
3
+ describe Nfe::Reader do
4
+ let (:nfe) { Nfe::Reader::Base.new(File.open(file)) }
5
+
6
+ describe 'many products' do
7
+ let(:file) { File.open(File.expand_path("../files/sample-nfe.xml", __FILE__))}
8
+
9
+ it '#version' do
10
+ nfe.version.must_equal '2.00'
11
+ end
12
+
13
+ it '#number' do
14
+ nfe.number.must_equal 'NFe12300384950081649000148500001000001310002342'
15
+ end
16
+
17
+ it '#signature' do
18
+ nfe.signature.must_be_instance_of Hash
19
+ end
20
+
21
+ it '#customer' do
22
+ nfe.customer.must_be_instance_of Nfe::Customer
23
+ end
24
+
25
+ it '#information' do
26
+ nfe.information.must_be_instance_of Nfe::Information
27
+ end
28
+
29
+ it '#header' do
30
+ nfe.header.must_be_instance_of Nfe::Header
31
+ end
32
+
33
+ it '#provider' do
34
+ nfe.provider.must_be_instance_of Nfe::Provider
35
+ end
36
+
37
+ it '#customer' do
38
+ nfe.customer.must_be_instance_of Nfe::Customer
39
+ end
40
+
41
+ it '#products' do
42
+ nfe.products.must_be_instance_of Array
43
+ end
44
+
45
+ it '#products' do
46
+ nfe.products.first.must_be_instance_of Nfe::Product
47
+ end
48
+
49
+ it '#collection' do
50
+ nfe.collection.must_be_instance_of Nfe::Collection
51
+ end
52
+
53
+ it '#transport' do
54
+ nfe.transport.must_be_instance_of Nfe::Transport
55
+ end
56
+
57
+ it '#purchase' do
58
+ nfe.purchase.must_be_nil
59
+ end
60
+
61
+ it '#cane' do
62
+ nfe.cane.must_be_nil
63
+ end
64
+
65
+ it '#export' do
66
+ nfe.export.must_be_nil
67
+ end
68
+
69
+ it '#delivery' do
70
+ nfe.delivery.must_be_nil
71
+ end
72
+
73
+ it '#removal' do
74
+ nfe.removal.must_be_nil
75
+ end
76
+
77
+ it '#enviroment' do
78
+ nfe.enviroment.must_equal '1'
79
+ end
80
+
81
+ it '#version_app' do
82
+ nfe.version_app.must_equal 'SVRS2000101120000'
83
+ end
84
+
85
+ it '#key' do
86
+ nfe.key.must_equal '12300384950081649000148500001000001310002342'
87
+ end
88
+
89
+ it '#date' do
90
+ nfe.date.must_equal '2000-01-01T12:00:00'
91
+ end
92
+
93
+ it '#protocol' do
94
+ nfe.protocol.must_equal '100000481241129'
95
+ end
96
+
97
+ it '#digest' do
98
+ nfe.digest.must_equal 'aklOQ0184NjoeaqCIRT01927Crf='
99
+ end
100
+
101
+ it '#status' do
102
+ nfe.status.must_equal '100'
103
+ end
104
+
105
+ it '#description' do
106
+ nfe.description.must_equal 'Autorizado o uso da NF-e'
107
+ end
108
+
109
+ it '#total' do
110
+ nfe.total.must_be_instance_of Nfe::Total
111
+ end
112
+ end
113
+
114
+ describe 'single product' do
115
+ let(:file) { File.open(File.expand_path("../files/sample2-nfe.xml", __FILE__))}
116
+
117
+ it '#products' do
118
+ nfe.products.must_be_instance_of Array
119
+ end
120
+
121
+ it '#products' do
122
+ nfe.products.first.must_be_instance_of Nfe::Product
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,27 @@
1
+ require File.expand_path("../test_helper", __FILE__)
2
+
3
+ describe Nokogiri::XML::Node do
4
+ def xml
5
+ %q{
6
+ <xml>
7
+ <tag_one version='1.0'>
8
+ <subtag_one>Subtag One</subtag_one>
9
+ </tag_one>
10
+ <tag_two>Tag Two</tag_two>
11
+ <empty_tag/>
12
+ </xml>
13
+ }
14
+ end
15
+
16
+ def xml_in_hash
17
+ {:xml=>{:tag_one=>{:version=>"1.0", :subtag_one=>"Subtag One"}, :tag_two=>"Tag Two", :empty_tag=> nil}}
18
+ end
19
+
20
+ let(:nokogiri_xml) { Nokogiri::XML(xml) }
21
+
22
+ it { assert_equal nokogiri_xml.to_hash, xml_in_hash }
23
+ it { assert_equal nokogiri_xml.to_hash[:xml][:tag_one][:version], "1.0" }
24
+ it { assert_equal nokogiri_xml.to_hash[:xml][:tag_one][:subtag_one], "Subtag One" }
25
+ it { assert_equal nokogiri_xml.to_hash[:xml][:tag_two], "Tag Two" }
26
+ it { assert_equal nokogiri_xml.to_hash[:xml][:empty_tag], nil }
27
+ end