spreadbase 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,25 +1,5 @@
1
- # encoding: UTF-8
2
-
3
- =begin
4
- Copyright 2012 Saverio Miroddi saverio.pub2 <a-hat!> gmail.com
5
-
6
- This file is part of SpreadBase.
7
-
8
- SpreadBase is free software: you can redistribute it and/or modify it under the
9
- terms of the GNU Lesser General Public License as published by the Free Software
10
- Foundation, either version 3 of the License, or (at your option) any later
11
- version.
12
-
13
- SpreadBase is distributed in the hope that it will be useful, but WITHOUT ANY
14
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
15
- PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16
-
17
- You should have received a copy of the GNU Lesser General Public License along
18
- with SpreadBase. If not, see <http://www.gnu.org/licenses/>.
19
- =end
20
-
21
- require File.expand_path( '../../../lib/spreadbase', __FILE__ )
22
- require File.expand_path( '../../spec_helpers', __FILE__ )
1
+ require_relative '../../lib/spreadbase'
2
+ require_relative '../spec_helpers'
23
3
 
24
4
  require 'date'
25
5
  require 'bigdecimal'
@@ -33,13 +13,13 @@ describe SpreadBase::Codecs::OpenDocument12 do
33
13
  before :each do
34
14
  table_1 = SpreadBase::Table.new(
35
15
  'abc', [
36
- [ 1, 1.1, T_BIGDECIMAL ],
37
- [ T_DATE, T_DATETIME, T_TIME ],
38
- [ nil, 'a', nil ]
16
+ [1, 1.1, T_BIGDECIMAL],
17
+ [T_DATE, T_DATETIME, T_TIME],
18
+ [nil, 'a', nil]
39
19
  ]
40
20
  )
41
21
 
42
- table_2 = SpreadBase::Table.new( 'cde' )
22
+ table_2 = SpreadBase::Table.new('cde')
43
23
 
44
24
  @sample_document = SpreadBase::Document.new
45
25
 
@@ -49,89 +29,87 @@ describe SpreadBase::Codecs::OpenDocument12 do
49
29
  # :encode/:decode
50
30
  #
51
31
  it "should encode and decode the sample document" do
52
- document_archive = SpreadBase::Codecs::OpenDocument12.new.encode_to_archive( @sample_document )
32
+ document_archive = SpreadBase::Codecs::OpenDocument12.new.encode_to_archive(@sample_document)
53
33
 
54
- document = SpreadBase::Codecs::OpenDocument12.new.decode_archive( document_archive, :floats_as_bigdecimal => true )
34
+ document = SpreadBase::Codecs::OpenDocument12.new.decode_archive(document_archive, floats_as_bigdecimal: true)
55
35
 
56
- assert_size( document.tables, 2 ) do | table_1, table_2 |
36
+ assert_size(document.tables, 2) do | table_1, table_2 |
57
37
 
58
- table_1.name.should == 'abc'
38
+ expect(table_1.name).to eq('abc')
59
39
 
60
- assert_size( table_1.data, 3 ) do | row_1, row_2, row_3 |
40
+ assert_size(table_1.data, 3) do | row_1, row_2, row_3 |
61
41
 
62
- assert_size( row_1, 3 ) do | value_1, value_2, value_3 |
63
- value_1.should == 1
64
- value_1.should be_a( Fixnum )
65
- value_2.should == 1.1
66
- value_2.should be_a( BigDecimal )
67
- value_3.should == T_BIGDECIMAL
68
- value_3.should be_a( BigDecimal )
42
+ assert_size(row_1, 3) do | value_1, value_2, value_3 |
43
+ expect(value_1).to eq(1)
44
+ expect(value_1).to be_a(Integer)
45
+ expect(value_2).to eq(1.1)
46
+ expect(value_2).to be_a(BigDecimal)
47
+ expect(value_3).to eq(T_BIGDECIMAL)
48
+ expect(value_3).to be_a(BigDecimal)
69
49
  end
70
50
 
71
- assert_size( row_2, 3 ) do | value_1, value_2, value_3 |
72
- value_1.should == T_DATE
73
- value_2.should == T_DATETIME
74
- value_3.should == T_DATETIME
51
+ assert_size(row_2, 3) do | value_1, value_2, value_3 |
52
+ expect(value_1).to eq(T_DATE)
53
+ expect(value_2).to eq(T_DATETIME)
54
+ expect(value_3).to eq(T_DATETIME)
75
55
  end
76
56
 
77
- assert_size( row_3, 3 ) do | value_1, value_2, value_3 |
78
- value_1.should == nil
79
- value_2.should == 'a'
80
- value_3.should == nil
57
+ assert_size(row_3, 3) do | value_1, value_2, value_3 |
58
+ expect(value_1).to eq(nil)
59
+ expect(value_2).to eq('a')
60
+ expect(value_3).to eq(nil)
81
61
  end
82
62
 
83
63
  end
84
64
 
85
- table_2.name.should == 'cde'
65
+ expect(table_2.name).to eq('cde')
86
66
 
87
- assert_size( table_2.data, 0 )
67
+ assert_size(table_2.data, 0)
88
68
  end
89
69
  end
90
70
 
91
71
  # Not worth testing in detail; just ensure that the pref
92
72
  #
93
73
  it "should encode the document with makeup (:prettify) - SMOKE" do
94
- formatter = stub_initializer( REXML::Formatters::Pretty )
74
+ formatter = stub_initializer(REXML::Formatters::Pretty)
95
75
 
96
- formatter.should_receive( :write )
76
+ expect(formatter).to receive(:write)
97
77
 
98
- SpreadBase::Codecs::OpenDocument12.new.encode_to_archive( @sample_document, :prettify => true )
78
+ SpreadBase::Codecs::OpenDocument12.new.encode_to_archive(@sample_document, prettify: true)
99
79
  end
100
80
 
101
81
  # Those methods are actually "utility" (read: testing) methods.
102
82
  #
103
83
  it "should encode/decode the content.xml - SMOKE" do
104
- content_xml = SpreadBase::Codecs::OpenDocument12.new.encode_to_content_xml( @sample_document )
84
+ content_xml = SpreadBase::Codecs::OpenDocument12.new.encode_to_content_xml(@sample_document)
105
85
 
106
- document = SpreadBase::Codecs::OpenDocument12.new.decode_content_xml( content_xml )
86
+ document = SpreadBase::Codecs::OpenDocument12.new.decode_content_xml(content_xml)
107
87
 
108
- assert_size( document.tables, 2 )
88
+ assert_size(document.tables, 2)
109
89
  end
110
90
 
111
91
  # If values are not converted to UTF-8, some encodings cause an error to be
112
92
  # raised when assigning a value to a cell.
113
93
  #
114
- # 1.8 tests can't be done, since the official platform is 1.9
115
- #
116
94
  it "should convert to utf-8 before saving" do
117
- string = "à".encode( 'UTF-16' )
95
+ string = "à".encode('utf-16')
118
96
 
119
- @sample_document.tables[ 0 ][ 0, 0 ] = string
97
+ @sample_document.tables[0][0, 0] = string
120
98
 
121
99
  # Doesn't encode correctly if the value is not converted
122
100
  #
123
- SpreadBase::Codecs::OpenDocument12.new.encode_to_content_xml( @sample_document )
101
+ SpreadBase::Codecs::OpenDocument12.new.encode_to_content_xml(@sample_document)
124
102
  end
125
103
 
126
104
  it "should decode as BigDecimal" do
127
- content_xml = SpreadBase::Codecs::OpenDocument12.new.encode_to_content_xml( @sample_document )
105
+ content_xml = SpreadBase::Codecs::OpenDocument12.new.encode_to_content_xml(@sample_document)
128
106
 
129
- document = SpreadBase::Codecs::OpenDocument12.new.decode_content_xml( content_xml, :floats_as_bigdecimal => true )
107
+ document = SpreadBase::Codecs::OpenDocument12.new.decode_content_xml(content_xml, floats_as_bigdecimal: true)
130
108
 
131
- value = document.tables[ 0 ][ 2, 0 ]
109
+ value = document.tables[0][2, 0]
132
110
 
133
- value.should be_a( BigDecimal )
134
- value.should == T_BIGDECIMAL
111
+ expect(value).to be_a(BigDecimal)
112
+ expect(value).to eq(T_BIGDECIMAL)
135
113
  end
136
114
 
137
115
  end
@@ -1,25 +1,5 @@
1
- # encoding: utf-8
2
-
3
- =begin
4
- Copyright 2012 Saverio Miroddi saverio.pub2 <a-hat!> gmail.com
5
-
6
- This file is part of SpreadBase.
7
-
8
- SpreadBase is free software: you can redistribute it and/or modify it under the
9
- terms of the GNU Lesser General Public License as published by the Free Software
10
- Foundation, either version 3 of the License, or (at your option) any later
11
- version.
12
-
13
- SpreadBase is distributed in the hope that it will be useful, but WITHOUT ANY
14
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
15
- PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16
-
17
- You should have received a copy of the GNU Lesser General Public License along
18
- with SpreadBase. If not, see <http://www.gnu.org/licenses/>.
19
- =end
20
-
21
- require File.expand_path( '../../../lib/spreadbase', __FILE__ )
22
- require File.expand_path( '../../spec_helpers', __FILE__ )
1
+ require_relative '../../lib/spreadbase'
2
+ require_relative '../spec_helpers'
23
3
 
24
4
  include SpecHelpers
25
5
 
@@ -30,9 +10,9 @@ describe SpreadBase::Document do
30
10
  @sample_document.tables = [
31
11
  SpreadBase::Table.new(
32
12
  'abc', [
33
- [ 1, 1.1, T_BIGDECIMAL ],
34
- [ T_DATE, T_DATETIME, T_TIME ],
35
- [ true, 'a', nil ]
13
+ [1, 1.1, T_BIGDECIMAL],
14
+ [T_DATE, T_DATETIME, T_TIME],
15
+ [true, 'a', nil]
36
16
  ]
37
17
  )
38
18
  ]
@@ -43,61 +23,59 @@ describe SpreadBase::Document do
43
23
  it "should initialize out of thin air" do
44
24
  document = SpreadBase::Document.new
45
25
 
46
- document.document_path.should == nil
26
+ expect(document.document_path).to be(nil)
47
27
 
48
- document.tables.should be_empty
28
+ expect(document.tables).to be_empty
49
29
  end
50
30
 
51
31
  # A lazy use of stubs
52
32
  #
53
33
  it "should initialize from a file" do
54
- codec = stub_initializer( SpreadBase::Codecs::OpenDocument12 )
34
+ codec = stub_initializer(SpreadBase::Codecs::OpenDocument12)
55
35
 
56
- File.should_receive( :'exists?' ).with( '/pizza/margerita.txt' ).and_return( true )
57
- IO.should_receive( :read ).with( '/pizza/margerita.txt' ).and_return( 'abc' )
58
- codec.should_receive( :decode_archive ).with( 'abc', {} ).and_return( @sample_document )
36
+ expect(File).to receive(:'exist?').with('/pizza/margerita.txt').and_return(true)
37
+ expect(IO).to receive(:read).with('/pizza/margerita.txt').and_return('abc')
38
+ expect(codec).to receive(:decode_archive).with('abc', {}).and_return(@sample_document)
59
39
 
60
- document = SpreadBase::Document.new( '/pizza/margerita.txt' )
40
+ document = SpreadBase::Document.new('/pizza/margerita.txt')
61
41
 
62
- assert_size( document.tables, 1 ) do | table |
63
- table.name.should == 'abc'
64
- table.data.size.should == 3
42
+ assert_size(document.tables, 1) do | table |
43
+ expect(table.name).to eq('abc')
44
+ expect(table.data.size).to eq(3)
65
45
  end
66
46
  end
67
47
 
68
48
  it "should initialize with a non-existing file" do
69
- codec = stub_initializer( SpreadBase::Codecs::OpenDocument12 )
70
-
71
- document = SpreadBase::Document.new( '/pizza/margerita.txt' )
49
+ document = SpreadBase::Document.new('/pizza/margerita.txt')
72
50
 
73
- assert_size( document.tables, 0 )
51
+ assert_size(document.tables, 0)
74
52
  end
75
53
 
76
54
  it "should save to a file" do
77
- codec = stub_initializer( SpreadBase::Codecs::OpenDocument12 )
55
+ codec = stub_initializer(SpreadBase::Codecs::OpenDocument12)
78
56
 
79
57
  document = SpreadBase::Document.new
80
- document.tables << SpreadBase::Table.new( 'Ya-ha!' )
58
+ document.tables << SpreadBase::Table.new('Ya-ha!')
81
59
  document.document_path = '/tmp/abc.ods'
82
60
 
83
- codec.should_receive( :encode_to_archive ).with( document, :prettify => 'abc' ).and_return( 'sob!' )
84
- File.should_receive( :open ).with( '/tmp/abc.ods', 'wb' )
61
+ expect(codec).to receive(:encode_to_archive).with(document, prettify: 'abc').and_return('sob!')
62
+ expect(File).to receive(:open).with('/tmp/abc.ods', 'wb')
85
63
 
86
- document.save( :prettify => 'abc' )
64
+ document.save(prettify: 'abc')
87
65
  end
88
66
 
89
67
  it "should raise an error when trying to save without a filename" do
90
68
  document = SpreadBase::Document.new
91
- document.tables << SpreadBase::Table.new( 'Ya-ha!' )
69
+ document.tables << SpreadBase::Table.new('Ya-ha!')
92
70
 
93
- lambda { document.save }.should raise_error( RuntimeError, "Document path not specified" )
71
+ expect { document.save }.to raise_error(RuntimeError, "Document path not specified")
94
72
  end
95
73
 
96
74
  it "should raise an error when trying to save without tables" do
97
75
  document = SpreadBase::Document.new
98
76
  document.document_path = 'abc.ods'
99
77
 
100
- lambda { document.save }.should raise_error( RuntimeError, "At least one table must be present" )
78
+ expect { document.save }.to raise_error(RuntimeError, "At least one table must be present")
101
79
  end
102
80
 
103
81
  it "should return the data as string (:to_s)" do
@@ -105,14 +83,14 @@ describe SpreadBase::Document do
105
83
  abc:
106
84
 
107
85
  +------------+---------------------------+---------------------------+
108
- | 1 | 1.1 | 0.133E1 |
109
- | 2012-04-10 | 2012-04-11T23:33:42+00:00 | 2012-04-11 23:33:42 +0200 |
110
- | true | a | |
86
+ | 1 | 1.1 | 1.33 |
87
+ | 2012-04-10 | 2012-04-11 23:33:42 +0000 | 2012-04-11 23:33:42 +0200 |
88
+ | true | a | NIL |
111
89
  +------------+---------------------------+---------------------------+
112
90
 
113
91
  "
114
92
 
115
- @sample_document.to_s.should == expected_string
93
+ expect(@sample_document.to_s).to eq(expected_string)
116
94
  end
117
95
 
118
96
  it "should return the data as string, with headers (:to_s)" do
@@ -120,15 +98,15 @@ abc:
120
98
  abc:
121
99
 
122
100
  +------------+---------------------------+---------------------------+
123
- | 1 | 1.1 | 0.133E1 |
101
+ | 1 | 1.1 | 1.33 |
124
102
  +------------+---------------------------+---------------------------+
125
- | 2012-04-10 | 2012-04-11T23:33:42+00:00 | 2012-04-11 23:33:42 +0200 |
126
- | true | a | |
103
+ | 2012-04-10 | 2012-04-11 23:33:42 +0000 | 2012-04-11 23:33:42 +0200 |
104
+ | true | a | NIL |
127
105
  +------------+---------------------------+---------------------------+
128
106
 
129
107
  "
130
108
 
131
- @sample_document.to_s( :with_headers => true ).should == expected_string
109
+ expect(@sample_document.to_s(with_headers: true)).to eq(expected_string)
132
110
  end
133
111
 
134
112
  end