sniff 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,15 +1,22 @@
1
- Given /^a purchase emitter$/ do
2
- @activity = PurchaseRecord
1
+ Given /^a (.+) emitter$/ do |name|
2
+ name = name.gsub(/\s+/,'_').camelize + 'Record'
3
+ @activity = name.constantize
4
+ @characteristics ||= {}
3
5
  end
4
6
 
5
7
  Given /^(a )?characteristic "(.*)" of "(.*)"$/ do |_, name, value|
6
- @characteristics ||= {}
7
-
8
8
  if name =~ /\./
9
9
  model_name, attribute = name.split /\./
10
- model = model_name.singularize.camelize.constantize
10
+ model = begin
11
+ model_name.singularize.camelize.constantize
12
+ rescue NameError
13
+ association = @activity.reflect_on_association model_name.to_sym
14
+ association.klass
15
+ end
11
16
  value = model.send "find_by_#{attribute}", value
12
17
  @characteristics[model_name.to_sym] = value
18
+ elsif name == 'timeframe' and value.present?
19
+ @characteristics[name.to_sym] = Timeframe.interval value
13
20
  else
14
21
  value = coerce_value(value)
15
22
  @characteristics[name.to_sym] = value
@@ -19,16 +26,27 @@ end
19
26
  When /^the "(.*)" committee is calculated$/ do |committee_name|
20
27
  @decision ||= @activity.decisions[:emission]
21
28
  @committee = @decision.committees.find { |c| c.name.to_s == committee_name }
22
- @report = @committee.report(@characteristics, [])
23
- @characteristics[committee_name.to_sym] = @report.conclusion
29
+ args = [@characteristics]
30
+ if @characteristics[:timeframe]
31
+ args << [@characteristics[:timeframe]]
32
+ else
33
+ args << []
34
+ end
35
+ @report = @committee.report *args
36
+ @characteristics[committee_name.to_sym] = @report.andand.conclusion
24
37
  end
25
38
 
26
39
  Then /^the committee should have used quorum "(.*)"$/ do |quorum|
40
+ raise "Missing report for committee #{@committee.name}" if @report.nil?
27
41
  @report.quorum.name.should == quorum
28
42
  end
29
43
 
30
- Then /^the conclusion of the committee should be "(.+)"$/ do |conclusion|
31
- compare_values(@report.conclusion, conclusion)
44
+ Then /^the conclusion of the committee should be "(.*)"$/ do |conclusion|
45
+ compare_values(@report.andand.conclusion, conclusion)
46
+ end
47
+
48
+ Then /^the conclusion of the committee should be nil$/ do
49
+ compare_values(@report.andand.conclusion, nil)
32
50
  end
33
51
 
34
52
  Then /^the conclusion of the committee should include a key of (.*) and value (.*)$/ do |key, value|
@@ -58,6 +76,11 @@ Then /^the conclusion of the committee should have a record identified with "(.*
58
76
  coerce_value(record.send(field)).should == coerce_value(value)
59
77
  end
60
78
 
79
+ Then /^the conclusion of the committee should have a record with "([^"]*)" equal to "([^"]*)"$/ do |field, value|
80
+ record = @report.conclusion
81
+ compare_values(coerce_value(record.send(field)),value)
82
+ end
83
+
61
84
  Then /^the conclusion of the committee should include a key of "(.*)" and subvalue "(.*)" of "(.*)" and subvalue "(.*)" of "(.*)"$/ do |key, subkey1, subvalue1, subkey2, subvalue2|
62
85
  if key.present?
63
86
  @report.conclusion.keys.map(&:to_s).should include(key)
@@ -1,5 +1,14 @@
1
+ require 'date'
2
+
1
3
  def coerce_value(value)
2
- if value =~ /\d+\.\d+/
4
+ # what is this, PHP?
5
+ if value.nil?
6
+ nil
7
+ elsif value == 'true'
8
+ true
9
+ elsif value == 'false'
10
+ false
11
+ elsif value =~ /\d+\.\d+/
3
12
  value.to_f
4
13
  elsif value =~ /^\d+$/
5
14
  value.to_i
@@ -9,7 +18,12 @@ def coerce_value(value)
9
18
  end
10
19
 
11
20
  def compare_values(a, b)
12
- if b =~ /\d+\.\d+/
21
+ if b.nil?
22
+ a.should be_nil
23
+ elsif a.is_a? Date or a.is_a? Time
24
+ b = Date.parse b
25
+ a.should == b
26
+ elsif b =~ /\d+\.\d+/
13
27
  b = b.to_f
14
28
  a.should be_close(b, 0.00001)
15
29
  elsif b =~ /^\d+$/
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: 25
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Derek Kastner