csv_model 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,82 @@
1
+ require 'spec_helper'
2
+
3
+ describe CSVModel::Utilities::Options do
4
+ class ObjectWithOptions
5
+ include CSVModel::Utilities::Options
6
+
7
+ def initialize(options)
8
+ @options = options
9
+ end
10
+ end
11
+
12
+ let(:options) { double('options') }
13
+ let(:key) { :foo }
14
+ let(:value) { :bar }
15
+ let(:default) { :default }
16
+ subject { ObjectWithOptions.new(options) }
17
+
18
+ describe '#option' do
19
+ context 'when options responds to []' do
20
+ before do
21
+ allow(options).to receive(:[]).with(key).and_return(value)
22
+ end
23
+
24
+ it 'returns the value of [key]' do
25
+ expect(subject.option(key)).to eq(value)
26
+ end
27
+
28
+ context 'and the value of [key] is nil' do
29
+ let(:value) { nil }
30
+
31
+ it 'returns nil when no default is specified' do
32
+ expect(subject.option(key)).to eq(nil)
33
+ end
34
+
35
+ it 'returns the default value when a default is specified' do
36
+ expect(subject.option(key, default)).to eq(default)
37
+ end
38
+ end
39
+ end
40
+
41
+ context 'when options responds to :key' do
42
+ before do
43
+ allow(options).to receive(key).with(no_args).and_return(value)
44
+ end
45
+
46
+ it 'returns the value of :key' do
47
+ expect(subject.option(key)).to eq(value)
48
+ end
49
+
50
+ context 'and the value of :key is nil' do
51
+ let(:value) { nil }
52
+
53
+ it 'returns nil when no default is specified' do
54
+ expect(subject.option(key)).to eq(nil)
55
+ end
56
+
57
+ it 'returns the default value when a default is specified' do
58
+ expect(subject.option(key, default)).to eq(default)
59
+ end
60
+ end
61
+ end
62
+
63
+ context 'when options responds to both [] and :key' do
64
+ before do
65
+ allow(options).to receive(:[]).with(key).and_return(value)
66
+ allow(options).to receive(key).with(no_args).and_return(:alt)
67
+ end
68
+
69
+ it 'returns the value of [key]' do
70
+ expect(subject.option(key)).to eq(value)
71
+ end
72
+
73
+ context 'and the value of [key] is nil' do
74
+ let(:value) { nil }
75
+
76
+ it 'returns the value of :key' do
77
+ expect(subject.option(key)).to eq(:alt)
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,20 @@
1
+ $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
2
+ $LOAD_PATH << File.join(File.dirname(__FILE__))
3
+
4
+ require 'rubygems'
5
+ require 'rspec'
6
+
7
+ # require "simplecov"
8
+
9
+ require 'csv_model'
10
+ require 'ostruct'
11
+
12
+ Dir["spec/support/**/*.rb"].each { |f| require File.expand_path(f) }
13
+
14
+ RSpec.configure do |config|
15
+ config.order = "random"
16
+
17
+ config.before(:suite) do
18
+ srand(config.seed)
19
+ end
20
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: csv_model
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Matthew Chadwick
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 3.0.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 3.0.0
55
+ description: ''
56
+ email:
57
+ - matthew.chadwick@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - .travis.yml
64
+ - Gemfile
65
+ - Gemfile.lock
66
+ - LICENSE
67
+ - README.md
68
+ - Rakefile
69
+ - csv_model.gemspec
70
+ - lib/csv_model.rb
71
+ - lib/csv_model/column.rb
72
+ - lib/csv_model/errors.rb
73
+ - lib/csv_model/extensions.rb
74
+ - lib/csv_model/header_row.rb
75
+ - lib/csv_model/model.rb
76
+ - lib/csv_model/object_with_status_snapshot.rb
77
+ - lib/csv_model/record_status.rb
78
+ - lib/csv_model/row.rb
79
+ - lib/csv_model/utilities.rb
80
+ - lib/csv_model/version.rb
81
+ - spec/csv_model/column_spec.rb
82
+ - spec/csv_model/header_row_spec.rb
83
+ - spec/csv_model/model_spec.rb
84
+ - spec/csv_model/object_with_status_snapshot_spec.rb
85
+ - spec/csv_model/row_spec.rb
86
+ - spec/csv_model/utilities_spec.rb
87
+ - spec/spec_helper.rb
88
+ homepage: ''
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.2.1
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: Utility library for importing CSV data.
112
+ test_files:
113
+ - spec/csv_model/column_spec.rb
114
+ - spec/csv_model/header_row_spec.rb
115
+ - spec/csv_model/model_spec.rb
116
+ - spec/csv_model/object_with_status_snapshot_spec.rb
117
+ - spec/csv_model/row_spec.rb
118
+ - spec/csv_model/utilities_spec.rb
119
+ - spec/spec_helper.rb