sniff 0.1.13 → 0.1.14

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,51 +1,61 @@
1
1
  require 'date'
2
2
  require 'active_support'
3
+ require 'chronic'
3
4
 
4
- def coerce_value(value)
5
- # what is this, PHP?
6
- if value.nil?
7
- nil
8
- elsif value == 'true'
9
- true
10
- elsif value == 'false'
11
- false
12
- elsif value =~ /\d+\.\d+/
13
- value.to_f
14
- elsif value =~ /^\d+$/
15
- value.to_i
16
- else
17
- value
5
+ module CucumberValueParser
6
+ def coerce_value(value)
7
+ # what is this, PHP?
8
+ if value.nil?
9
+ nil
10
+ elsif value == 'true'
11
+ true
12
+ elsif value == 'false'
13
+ false
14
+ elsif value =~ /\d+\.\d+/
15
+ value.to_f
16
+ elsif value =~ /^\d+$/
17
+ value.to_i
18
+ elsif value.is_a?(String) and date = Chronic.parse(value)
19
+ date
20
+ else
21
+ value
22
+ end
18
23
  end
19
- end
20
24
 
21
- def compare_values(a, b)
22
- if b.blank?
23
- a.should be_blank
24
- elsif a.is_a? Date or a.is_a? Time
25
- b = Date.parse b
26
- a.should == b
27
- elsif b =~ /\d+\.\d+/
28
- b = b.to_f
29
- a.to_f.should be_close(b, 0.00001)
30
- elsif b =~ /^\d+$/
31
- b = b.to_i
32
- a.to_i.should == b
33
- else
34
- a.should == b
25
+ def compare_values(a, b)
26
+ if b.blank?
27
+ a.should be_blank
28
+ elsif a.is_a? Time
29
+ b = Chronic.parse b unless b.is_a?(Time)
30
+ a.should == b
31
+ elsif a.is_a? Date
32
+ b = Date.parse b unless b.is_a?(Date)
33
+ a.should == b
34
+ elsif b =~ /\d+\.\d+/
35
+ b = b.to_f
36
+ a.to_f.should be_close(b, 0.00001)
37
+ elsif b =~ /^\d+$/
38
+ b = b.to_i
39
+ a.to_i.should == b
40
+ else
41
+ a.should == b
42
+ end
35
43
  end
36
- end
37
44
 
38
- def equality?(a, b)
39
- if b.blank?
40
- a.blank?
41
- elsif a.is_a? Date or a.is_a? Time
42
- b = Date.parse b
43
- a == b
44
- elsif b =~ /\d+\.\d+/
45
- (a.to_f - b.to_f).abs <= 0.00001
46
- elsif b =~ /^\d+$/
47
- a.to_i == b.to_i
48
- else
49
- a == b
45
+ def equality?(a, b)
46
+ if b.blank?
47
+ a.blank?
48
+ elsif a.is_a? Date or a.is_a? Time
49
+ b = Date.parse b
50
+ a == b
51
+ elsif b =~ /\d+\.\d+/
52
+ (a.to_f - b.to_f).abs <= 0.00001
53
+ elsif b =~ /^\d+$/
54
+ a.to_i == b.to_i
55
+ else
56
+ a == b
57
+ end
50
58
  end
51
59
  end
60
+
61
+ include CucumberValueParser
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+ require 'test_support/cucumber/support/values'
3
+
4
+ include CucumberValueParser
5
+
6
+ describe CucumberValueParser do
7
+ describe '#coerce_value' do
8
+ it 'should leave a nil value alone' do
9
+ coerce_value(nil).should be_nil
10
+ end
11
+ it 'should parse "false" into a boolean' do
12
+ coerce_value('false').should be_false
13
+ end
14
+ it 'should parse "true" into a boolean' do
15
+ coerce_value('true').should be_true
16
+ end
17
+ it 'should parse a float' do
18
+ coerce_value('2.3').should == 2.3
19
+ end
20
+ it 'should parse a zero-prefixed float' do
21
+ coerce_value('2.0').should == 2.0
22
+ end
23
+ it 'should parse an integer' do
24
+ coerce_value('2').should == 2
25
+ end
26
+ it 'should parse a date' do
27
+ coerce_value('today').should be_an_instance_of(Time)
28
+ coerce_value('2010-01-20').should be_an_instance_of(Time)
29
+ coerce_value('2010-01-20 13:00:00').should be_an_instance_of(Time)
30
+ coerce_value('2 days from now').should be_an_instance_of(Time)
31
+ end
32
+ it 'should leave regular strings alone' do
33
+ coerce_value('sandwich').should == 'sandwich'
34
+ coerce_value('UA').should == 'UA'
35
+ end
36
+ end
37
+ end
38
+
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sniff
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1
4
+ hash: 7
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 13
10
- version: 0.1.13
9
+ - 14
10
+ version: 0.1.14
11
11
  platform: ruby
12
12
  authors:
13
13
  - Derek Kastner
@@ -19,9 +19,10 @@ date: 2010-09-13 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- name: activerecord
22
+ type: :runtime
23
23
  prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
24
+ name: activerecord
25
+ version_requirements: &id001 !ruby/object:Gem::Requirement
25
26
  none: false
26
27
  requirements:
27
28
  - - ~>
@@ -32,12 +33,12 @@ dependencies:
32
33
  - 0
33
34
  - 0
34
35
  version: 3.0.0
35
- type: :runtime
36
- version_requirements: *id001
36
+ requirement: *id001
37
37
  - !ruby/object:Gem::Dependency
38
- name: activesupport
38
+ type: :runtime
39
39
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
40
+ name: activesupport
41
+ version_requirements: &id002 !ruby/object:Gem::Requirement
41
42
  none: false
42
43
  requirements:
43
44
  - - ~>
@@ -48,28 +49,28 @@ dependencies:
48
49
  - 0
49
50
  - 0
50
51
  version: 3.0.0
51
- type: :runtime
52
- version_requirements: *id002
52
+ requirement: *id002
53
53
  - !ruby/object:Gem::Dependency
54
- name: sqlite3-ruby
54
+ type: :runtime
55
55
  prerelease: false
56
- requirement: &id003 !ruby/object:Gem::Requirement
56
+ name: chronic
57
+ version_requirements: &id003 !ruby/object:Gem::Requirement
57
58
  none: false
58
59
  requirements:
59
60
  - - ~>
60
61
  - !ruby/object:Gem::Version
61
- hash: 27
62
+ hash: 17
62
63
  segments:
63
- - 1
64
- - 3
65
64
  - 0
66
- version: 1.3.0
67
- type: :runtime
68
- version_requirements: *id003
65
+ - 2
66
+ - 3
67
+ version: 0.2.3
68
+ requirement: *id003
69
69
  - !ruby/object:Gem::Dependency
70
- name: common_name
70
+ type: :runtime
71
71
  prerelease: false
72
- requirement: &id004 !ruby/object:Gem::Requirement
72
+ name: common_name
73
+ version_requirements: &id004 !ruby/object:Gem::Requirement
73
74
  none: false
74
75
  requirements:
75
76
  - - ~>
@@ -80,12 +81,12 @@ dependencies:
80
81
  - 1
81
82
  - 5
82
83
  version: 0.1.5
83
- type: :runtime
84
- version_requirements: *id004
84
+ requirement: *id004
85
85
  - !ruby/object:Gem::Dependency
86
- name: earth
86
+ type: :runtime
87
87
  prerelease: false
88
- requirement: &id005 !ruby/object:Gem::Requirement
88
+ name: earth
89
+ version_requirements: &id005 !ruby/object:Gem::Requirement
89
90
  none: false
90
91
  requirements:
91
92
  - - ~>
@@ -96,12 +97,28 @@ dependencies:
96
97
  - 0
97
98
  - 32
98
99
  version: 0.0.32
100
+ requirement: *id005
101
+ - !ruby/object:Gem::Dependency
99
102
  type: :runtime
100
- version_requirements: *id005
103
+ prerelease: false
104
+ name: sqlite3-ruby
105
+ version_requirements: &id006 !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ hash: 27
111
+ segments:
112
+ - 1
113
+ - 3
114
+ - 0
115
+ version: 1.3.0
116
+ requirement: *id006
101
117
  - !ruby/object:Gem::Dependency
102
- name: timeframe
118
+ type: :runtime
103
119
  prerelease: false
104
- requirement: &id006 !ruby/object:Gem::Requirement
120
+ name: timeframe
121
+ version_requirements: &id007 !ruby/object:Gem::Requirement
105
122
  none: false
106
123
  requirements:
107
124
  - - ~>
@@ -112,12 +129,12 @@ dependencies:
112
129
  - 0
113
130
  - 8
114
131
  version: 0.0.8
115
- type: :runtime
116
- version_requirements: *id006
132
+ requirement: *id007
117
133
  - !ruby/object:Gem::Dependency
118
- name: bundler
134
+ type: :development
119
135
  prerelease: false
120
- requirement: &id007 !ruby/object:Gem::Requirement
136
+ name: bundler
137
+ version_requirements: &id008 !ruby/object:Gem::Requirement
121
138
  none: false
122
139
  requirements:
123
140
  - - ">="
@@ -126,26 +143,28 @@ dependencies:
126
143
  segments:
127
144
  - 0
128
145
  version: "0"
129
- type: :development
130
- version_requirements: *id007
146
+ requirement: *id008
131
147
  - !ruby/object:Gem::Dependency
132
- name: jeweler
148
+ type: :development
133
149
  prerelease: false
134
- requirement: &id008 !ruby/object:Gem::Requirement
150
+ name: fast_timestamp
151
+ version_requirements: &id009 !ruby/object:Gem::Requirement
135
152
  none: false
136
153
  requirements:
137
- - - ">="
154
+ - - ~>
138
155
  - !ruby/object:Gem::Version
139
- hash: 3
156
+ hash: 23
140
157
  segments:
141
158
  - 0
142
- version: "0"
143
- type: :development
144
- version_requirements: *id008
159
+ - 0
160
+ - 4
161
+ version: 0.0.4
162
+ requirement: *id009
145
163
  - !ruby/object:Gem::Dependency
146
- name: rake
164
+ type: :development
147
165
  prerelease: false
148
- requirement: &id009 !ruby/object:Gem::Requirement
166
+ name: jeweler
167
+ version_requirements: &id010 !ruby/object:Gem::Requirement
149
168
  none: false
150
169
  requirements:
151
170
  - - ">="
@@ -154,30 +173,26 @@ dependencies:
154
173
  segments:
155
174
  - 0
156
175
  version: "0"
157
- type: :development
158
- version_requirements: *id009
176
+ requirement: *id010
159
177
  - !ruby/object:Gem::Dependency
160
- name: rspec
178
+ type: :development
161
179
  prerelease: false
162
- requirement: &id010 !ruby/object:Gem::Requirement
180
+ name: rake
181
+ version_requirements: &id011 !ruby/object:Gem::Requirement
163
182
  none: false
164
183
  requirements:
165
- - - ~>
184
+ - - ">="
166
185
  - !ruby/object:Gem::Version
167
- hash: 62196417
186
+ hash: 3
168
187
  segments:
169
- - 2
170
- - 0
171
188
  - 0
172
- - beta
173
- - 17
174
- version: 2.0.0.beta.17
175
- type: :development
176
- version_requirements: *id010
189
+ version: "0"
190
+ requirement: *id011
177
191
  - !ruby/object:Gem::Dependency
178
- name: rcov
192
+ type: :development
179
193
  prerelease: false
180
- requirement: &id011 !ruby/object:Gem::Requirement
194
+ name: rcov
195
+ version_requirements: &id012 !ruby/object:Gem::Requirement
181
196
  none: false
182
197
  requirements:
183
198
  - - ">="
@@ -186,12 +201,12 @@ dependencies:
186
201
  segments:
187
202
  - 0
188
203
  version: "0"
189
- type: :development
190
- version_requirements: *id011
204
+ requirement: *id012
191
205
  - !ruby/object:Gem::Dependency
192
- name: rdoc
206
+ type: :development
193
207
  prerelease: false
194
- requirement: &id012 !ruby/object:Gem::Requirement
208
+ name: rdoc
209
+ version_requirements: &id013 !ruby/object:Gem::Requirement
195
210
  none: false
196
211
  requirements:
197
212
  - - ">="
@@ -200,24 +215,25 @@ dependencies:
200
215
  segments:
201
216
  - 0
202
217
  version: "0"
203
- type: :development
204
- version_requirements: *id012
218
+ requirement: *id013
205
219
  - !ruby/object:Gem::Dependency
206
- name: fast_timestamp
220
+ type: :development
207
221
  prerelease: false
208
- requirement: &id013 !ruby/object:Gem::Requirement
222
+ name: rspec
223
+ version_requirements: &id014 !ruby/object:Gem::Requirement
209
224
  none: false
210
225
  requirements:
211
226
  - - ~>
212
227
  - !ruby/object:Gem::Version
213
- hash: 23
228
+ hash: 62196417
214
229
  segments:
230
+ - 2
215
231
  - 0
216
232
  - 0
217
- - 4
218
- version: 0.0.4
219
- type: :development
220
- version_requirements: *id013
233
+ - beta
234
+ - 17
235
+ version: 2.0.0.beta.17
236
+ requirement: *id014
221
237
  description: Provides data environment for emitter gems
222
238
  email: derek.kastner@brighterplanet.com
223
239
  executables: []
@@ -247,6 +263,7 @@ files:
247
263
  - lib/test_support/db/fixtures/zip_codes.csv
248
264
  - README.markdown
249
265
  - spec/lib/sniff/database_spec.rb
266
+ - spec/lib/test_support/cucumber/support/values_spec.rb
250
267
  - spec/spec_helper.rb
251
268
  has_rdoc: true
252
269
  homepage: http://github.com/brighterplanet/sniff
@@ -284,6 +301,7 @@ specification_version: 3
284
301
  summary: Test support for Brighter Planet carbon gems
285
302
  test_files:
286
303
  - spec/lib/sniff/database_spec.rb
304
+ - spec/lib/test_support/cucumber/support/values_spec.rb
287
305
  - spec/spec_helper.rb
288
306
  - lib/test_support/cucumber/step_definitions/carbon_steps.rb
289
307
  - lib/test_support/cucumber/step_definitions/committee_steps.rb