sniff 0.0.19 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/sniff.rb CHANGED
@@ -22,8 +22,8 @@ module Sniff
22
22
  Sniff::Database.init local_root, options
23
23
 
24
24
  if defined?(Cucumber)
25
- step_definitions = Dir.glob File.join(File.dirname(__FILE__), 'test_support', 'step_definitions', '**', '*.rb')
26
- step_definitions.each { |definition| require definition }
25
+ cukes = Dir.glob File.join(File.dirname(__FILE__), 'test_support', 'cucumber', '**', '*.rb')
26
+ cukes.each { |support_file| require support_file }
27
27
  end
28
28
  end
29
29
  end
@@ -0,0 +1,71 @@
1
+ Given /^a purchase emitter$/ do
2
+ @activity = PurchaseRecord
3
+ end
4
+
5
+ Given /^(a )?characteristic "(.*)" of "(.*)"$/ do |_, name, value|
6
+ @characteristics ||= {}
7
+
8
+ if name =~ /\./
9
+ model_name, attribute = name.split /\./
10
+ model = model_name.singularize.camelize.constantize
11
+ value = model.send "find_by_#{attribute}", value
12
+ @characteristics[model_name.to_sym] = value
13
+ else
14
+ value = coerce_value(value)
15
+ @characteristics[name.to_sym] = value
16
+ end
17
+ end
18
+
19
+ When /^the "(.*)" committee is calculated$/ do |committee_name|
20
+ @decision ||= @activity.decisions[:emission]
21
+ @committee = @decision.committees.find { |c| c.name.to_s == committee_name }
22
+ @report = @committee.report(@characteristics, [])
23
+ @characteristics[committee_name.to_sym] = @report.conclusion
24
+ end
25
+
26
+ Then /^the committee should have used quorum "(.*)"$/ do |quorum|
27
+ @report.quorum.name.should == quorum
28
+ end
29
+
30
+ Then /^the conclusion of the committee should be "(.+)"$/ do |conclusion|
31
+ compare_values(@report.conclusion, conclusion)
32
+ end
33
+
34
+ Then /^the conclusion of the committee should include a key of (.*) and value (.*)$/ do |key, value|
35
+ if key.present?
36
+ @report.conclusion.keys.map(&:to_s).should include(key)
37
+ else
38
+ @report.conclusion.keys.map(&:to_s).should be_empty
39
+ end
40
+
41
+ if value.present?
42
+ @report.conclusion.each do |k, v|
43
+ @report.conclusion[k.to_s] == v
44
+ end
45
+ compare_values(@report.conclusion[key.to_s], value)
46
+ end
47
+ end
48
+
49
+ Then /^the conclusion of the committee should have "(.*)" of "(.*)"$/ do |attribute, value|
50
+ report_value = coerce_value @report.conclusion.send(attribute)
51
+ report_value.should == coerce_value(value)
52
+ end
53
+
54
+ Then /^the conclusion of the committee should have a record identified with "(.*)" of "(.*)" and having "(.*)" of "(.*)"$/ do |id_field, id, field, value|
55
+ id_field = id_field.to_sym
56
+ records = @report.conclusion
57
+ record = records.send("find_by_#{id_field}", id)
58
+ coerce_value(record.send(field)).should == coerce_value(value)
59
+ end
60
+
61
+ Then /^the conclusion of the committee should include a key of "(.*)" and subvalue "(.*)" of "(.*)" and subvalue "(.*)" of "(.*)"$/ do |key, subkey1, subvalue1, subkey2, subvalue2|
62
+ if key.present?
63
+ @report.conclusion.keys.map(&:to_s).should include(key)
64
+ actual_subvalue1 = coerce_value(@report.conclusion[key.to_s][subkey1.to_sym].to_s)
65
+ compare_values(actual_subvalue1, subvalue1)
66
+ actual_subvalue2 = coerce_value(@report.conclusion[key.to_s][subkey2.to_sym].to_s)
67
+ compare_values(actual_subvalue2, subvalue2)
68
+ else
69
+ @report.conclusion.keys.map(&:to_s).should be_empty
70
+ end
71
+ end
@@ -0,0 +1,21 @@
1
+ def coerce_value(value)
2
+ if value =~ /\d+\.\d+/
3
+ value.to_f
4
+ elsif value =~ /^\d+$/
5
+ value.to_i
6
+ else
7
+ value
8
+ end
9
+ end
10
+
11
+ def compare_values(a, b)
12
+ if b =~ /\d+\.\d+/
13
+ b = b.to_f
14
+ a.should be_close(b, 0.00001)
15
+ elsif b =~ /^\d+$/
16
+ b = b.to_i
17
+ a.should == b
18
+ else
19
+ a.should == b
20
+ end
21
+ end
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: 57
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 19
10
- version: 0.0.19
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Derek Kastner
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-29 00:00:00 -04:00
18
+ date: 2010-08-03 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -233,6 +233,9 @@ files:
233
233
  - lib/sniff/database.rb
234
234
  - lib/sniff/emitter.rb
235
235
  - lib/sniff/tasks.rb
236
+ - lib/test_support/cucumber/step_definitions/carbon_steps.rb
237
+ - lib/test_support/cucumber/step_definitions/committee_steps.rb
238
+ - lib/test_support/cucumber/support/values.rb
236
239
  - lib/test_support/db/fixtures/census_divisions.csv
237
240
  - lib/test_support/db/fixtures/census_regions.csv
238
241
  - lib/test_support/db/fixtures/climate_divisions.csv
@@ -244,7 +247,6 @@ files:
244
247
  - lib/test_support/db/fixtures/states.csv
245
248
  - lib/test_support/db/fixtures/urbanities.csv
246
249
  - lib/test_support/db/fixtures/zip_codes.csv
247
- - lib/test_support/step_definitions/carbon_steps.rb
248
250
  - README.markdown
249
251
  - spec/lib/sniff/database_spec.rb
250
252
  - spec/spec_helper.rb
@@ -285,4 +287,6 @@ summary: Test support for Brighter Planet carbon gems
285
287
  test_files:
286
288
  - spec/lib/sniff/database_spec.rb
287
289
  - spec/spec_helper.rb
288
- - lib/test_support/step_definitions/carbon_steps.rb
290
+ - lib/test_support/cucumber/step_definitions/carbon_steps.rb
291
+ - lib/test_support/cucumber/step_definitions/committee_steps.rb
292
+ - lib/test_support/cucumber/support/values.rb