data-driver 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +16 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.txt +61 -0
- data/Rakefile +2 -0
- data/data-driver.gemspec +25 -0
- data/lib/data-driver.rb +24 -0
- data/lib/data-driver/version.rb +3 -0
- data/spec/data-driver_spec.rb +47 -0
- data/spec/data.csv +4 -0
- data/spec/data.xlsx +0 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 172990b4855509df7fc42e4f509575a2aed09c91
|
4
|
+
data.tar.gz: 63c0255db71785fb6d780d1323fb7c2825a90808
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0d969cda115cf53222e8eb99c49ea9b9cc67bcfcb339b9c9ecf24732483204cf8bc3e84d747691dcd28d8e6de97dfbfda83e286c70f576b449a66a896f63b752
|
7
|
+
data.tar.gz: baf558c8de28ba8bd5f7e3b558ca0557cb7695595e06ab7d61f5544a000605ccf84b99ad12a7ca8dd5b881becab891ebc380903b8b79c14ef6185a2daa135a06
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Dave Haeffner
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.txt
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
= data-driver
|
2
|
+
|
3
|
+
== DESCRIPTION:
|
4
|
+
|
5
|
+
Consume a comma-separated (CSV) or modern Excel (XLSX) file containing data and return an array containing a key/value collections of your data (e.g., a Hash).
|
6
|
+
|
7
|
+
== INSTALLATION:
|
8
|
+
|
9
|
+
gem install data-driver
|
10
|
+
|
11
|
+
== DATA SCHEMA:
|
12
|
+
|
13
|
+
=== CSV
|
14
|
+
|
15
|
+
descriptor,descriptor,descriptor,etc.,etc.
|
16
|
+
yourdata,yourdata,yourdata,etc.,etc.
|
17
|
+
moreofyourdata,moreofyourdata,moreofyourdata,etc.,etc.
|
18
|
+
|
19
|
+
=== XLSX
|
20
|
+
|
21
|
+
| descriptor | descriptor | descriptor | etc. | etc. |
|
22
|
+
| yourdata | yourdata | yourdata | etc. | etc. |
|
23
|
+
| moreofyourdata | moreofyourdata | moreofyourdata | etc. | etc. |
|
24
|
+
|
25
|
+
== USAGE:
|
26
|
+
|
27
|
+
=== Basic Usage
|
28
|
+
|
29
|
+
DataDriver.consume('path-to-file')
|
30
|
+
|
31
|
+
NOTE: Will auto-detect the file type. If there is more than one worksheet, the first one will be used by default.
|
32
|
+
|
33
|
+
=== Specifying a Worksheet
|
34
|
+
|
35
|
+
DataDriver.consume('path-to-file', 1)
|
36
|
+
|
37
|
+
NOTE: The second parameter accepts a number, and numbering starts at 0. So 1 is the second worksheet.
|
38
|
+
|
39
|
+
== LICENSE:
|
40
|
+
|
41
|
+
The MIT License (MIT)
|
42
|
+
|
43
|
+
Copyright (c) 2014 Dave Haeffner
|
44
|
+
|
45
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
46
|
+
of this software and associated documentation files (the "Software"), to deal
|
47
|
+
in the Software without restriction, including without limitation the rights
|
48
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
49
|
+
copies of the Software, and to permit persons to whom the Software is
|
50
|
+
furnished to do so, subject to the following conditions:
|
51
|
+
|
52
|
+
The above copyright notice and this permission notice shall be included in all
|
53
|
+
copies or substantial portions of the Software.
|
54
|
+
|
55
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
56
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
57
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
58
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
59
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
60
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
61
|
+
SOFTWARE.
|
data/Rakefile
ADDED
data/data-driver.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'data-driver/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'data-driver'
|
8
|
+
spec.version = DataDriver::VERSION
|
9
|
+
spec.authors = ['Dave Haeffner']
|
10
|
+
spec.email = ['dhaeffner@gmail.com']
|
11
|
+
spec.summary = %q{See README.txt for details.}
|
12
|
+
spec.description = %q{A simple way to consume CSV and XLSX test data for use in your tests.}
|
13
|
+
spec.homepage = ''
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_dependency 'rubyXL', '~> 3.2.3'
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
23
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
24
|
+
spec.add_development_dependency 'rspec', '~> 3.1.0'
|
25
|
+
end
|
data/lib/data-driver.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'rubyXL'
|
2
|
+
require 'csv'
|
3
|
+
|
4
|
+
module DataDriver
|
5
|
+
|
6
|
+
def self.consume(file, worksheet_number = 0)
|
7
|
+
case File.extname(file).downcase
|
8
|
+
when '.xlsx'
|
9
|
+
#parse(scrub(RubyXL::Parser.parse(file)[worksheet_number].extract_data))
|
10
|
+
parse RubyXL::Parser.parse(file)[worksheet_number].extract_data
|
11
|
+
when '.csv'
|
12
|
+
parse CSV.read file
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def self.parse(datas)
|
19
|
+
descriptor = datas.shift
|
20
|
+
descriptor = descriptor.map { |key| key.to_sym }
|
21
|
+
datas.map { |data| Hash[ descriptor.zip(data) ] }
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require_relative '../lib/data-driver'
|
2
|
+
|
3
|
+
describe 'data-driver' do
|
4
|
+
|
5
|
+
def file(name)
|
6
|
+
File.join Dir.pwd, 'spec', name
|
7
|
+
end
|
8
|
+
|
9
|
+
context 'returns a Hash' do
|
10
|
+
|
11
|
+
it 'for CSV' do
|
12
|
+
obj = DataDriver.consume file('data.csv')
|
13
|
+
expect(obj.class).to eql Array
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'for XLSX' do
|
17
|
+
obj = DataDriver.consume file('data.xlsx')
|
18
|
+
expect(obj.class).to eql Array
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'parses the data' do
|
24
|
+
|
25
|
+
it 'for CSV' do
|
26
|
+
obj = DataDriver.consume file 'data.csv'
|
27
|
+
expect(obj[0][:account_type]).to eql 'bad_password'
|
28
|
+
expect(obj[1][:account_type]).to eql 'bad_username'
|
29
|
+
expect(obj[2][:account_type]).to eql 'standard_user'
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'for XLSX' do
|
33
|
+
obj = DataDriver.consume file('data.xlsx')
|
34
|
+
expect(obj[0][:id]).to eql 12345
|
35
|
+
expect(obj[1][:id]).to eql 67890
|
36
|
+
expect(obj[2][:id]).to eql 11223344
|
37
|
+
end
|
38
|
+
|
39
|
+
it '-> converts blanks to nil' do
|
40
|
+
obj = DataDriver.consume file('data.xlsx'), 1
|
41
|
+
expect(obj[0][:user]).to eql nil
|
42
|
+
expect(obj[0][:pass]).to eql nil
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
data/spec/data.csv
ADDED
data/spec/data.xlsx
ADDED
Binary file
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: data-driver
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dave Haeffner
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rubyXL
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.2.3
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.2.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.7'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.1.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.1.0
|
69
|
+
description: A simple way to consume CSV and XLSX test data for use in your tests.
|
70
|
+
email:
|
71
|
+
- dhaeffner@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.txt
|
80
|
+
- Rakefile
|
81
|
+
- data-driver.gemspec
|
82
|
+
- lib/data-driver.rb
|
83
|
+
- lib/data-driver/version.rb
|
84
|
+
- spec/data-driver_spec.rb
|
85
|
+
- spec/data.csv
|
86
|
+
- spec/data.xlsx
|
87
|
+
homepage: ''
|
88
|
+
licenses:
|
89
|
+
- MIT
|
90
|
+
metadata: {}
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 2.2.2
|
108
|
+
signing_key:
|
109
|
+
specification_version: 4
|
110
|
+
summary: See README.txt for details.
|
111
|
+
test_files:
|
112
|
+
- spec/data-driver_spec.rb
|
113
|
+
- spec/data.csv
|
114
|
+
- spec/data.xlsx
|