amee-data-abstraction 2.1.1 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. data/CHANGELOG.txt +3 -0
  2. data/README.txt +26 -14
  3. data/VERSION +1 -1
  4. data/amee-data-abstraction.gemspec +7 -6
  5. data/lib/amee-data-abstraction/calculation.rb +1 -1
  6. data/lib/amee-data-abstraction/calculation_set.rb +152 -10
  7. data/lib/amee-data-abstraction/input.rb +10 -0
  8. data/lib/amee-data-abstraction/ongoing_calculation.rb +1 -1
  9. data/lib/amee-data-abstraction/term.rb +31 -13
  10. data/spec/amee-data-abstraction/calculation_set_spec.rb +247 -9
  11. data/spec/amee-data-abstraction/calculation_spec.rb +24 -19
  12. data/spec/amee-data-abstraction/drill_spec.rb +14 -9
  13. data/spec/amee-data-abstraction/input_spec.rb +113 -73
  14. data/spec/amee-data-abstraction/metadatum_spec.rb +1 -1
  15. data/spec/amee-data-abstraction/ongoing_calculation_spec.rb +38 -30
  16. data/spec/amee-data-abstraction/profile_spec.rb +4 -2
  17. data/spec/amee-data-abstraction/prototype_calculation_spec.rb +13 -8
  18. data/spec/amee-data-abstraction/term_spec.rb +45 -4
  19. data/spec/amee-data-abstraction/terms_list_spec.rb +23 -12
  20. data/spec/config/amee_units_spec.rb +1 -2
  21. data/spec/core-extensions/class_spec.rb +18 -18
  22. data/spec/core-extensions/hash_spec.rb +1 -2
  23. data/spec/core-extensions/ordered_hash_spec.rb +1 -2
  24. data/spec/core-extensions/proc_spec.rb +1 -1
  25. data/spec/fixtures/config/calculations/electricity.rb +35 -0
  26. data/spec/fixtures/config/calculations/electricity_and_transport.rb +53 -0
  27. data/spec/fixtures/{transport.rb → config/calculations/transport.rb} +2 -2
  28. data/spec/fixtures/{electricity.rb → config/electricity.rb} +1 -1
  29. data/spec/spec_helper.rb +30 -2
  30. metadata +28 -27
  31. data/spec/fixtures/electricity_and_transport.rb +0 -55
@@ -1,53 +1,58 @@
1
- require File.dirname(File.dirname(__FILE__)) + '/spec_helper.rb'
1
+ require 'spec_helper'
2
+
2
3
  describe Calculation do
3
-
4
+
5
+ before :all do
6
+ @calc = CalculationSet.find("transport")[:transport]
7
+ end
8
+
4
9
  it 'can create an instance' do
5
- Transport.should be_a Calculation
10
+ @calc.should be_a Calculation
6
11
  end
7
12
  it 'should have ordered terms, with labels' do
8
- Transport.terms.labels.should eql [:fuel,:size,:distance,:co2]
13
+ @calc.terms.labels.should eql [:fuel,:size,:distance,:co2]
9
14
  end
10
15
  it 'should have amee paths for the terms' do
11
- Transport.terms.paths.should eql ['fuel','size','distance',:default]
16
+ @calc.terms.paths.should eql ['fuel','size','distance','default']
12
17
  end
13
18
  it 'should have human names for the terms' do
14
- Transport.terms.names.
19
+ @calc.terms.names.
15
20
  should eql ['Fuel Type','Vehicle Size','Distance Driven','Carbon Dioxide']
16
21
  end
17
22
  it 'should return the inputs' do
18
- Transport.inputs.labels.should eql [:fuel,:size,:distance]
23
+ @calc.inputs.labels.should eql [:fuel,:size,:distance]
19
24
  end
20
25
  it 'should return the outputs' do
21
- Transport.outputs.labels.should eql [:co2]
26
+ @calc.outputs.labels.should eql [:co2]
22
27
  end
23
28
  it 'should generate an discover URL' do
24
- Transport.discover_url.should eql 'http://discover.amee.com/categories/transport/car/generic'
29
+ @calc.discover_url.should eql 'http://discover.amee.com/categories/transport/car/generic'
25
30
  end
26
31
  it 'should redirect to discover URL' do
27
- Transport.explorer_url.should eql 'http://discover.amee.com/categories/transport/car/generic'
32
+ @calc.explorer_url.should eql 'http://discover.amee.com/categories/transport/car/generic'
28
33
  end
29
34
  it 'can return a term via []' do
30
- Transport[:co2].label.should eql :co2
35
+ @calc[:co2].label.should eql :co2
31
36
  end
32
37
  it 'when copied, should deep copy the values' do
33
- x=Transport.clone
38
+ x=@calc.clone
34
39
  x[:co2].value :somevalue
35
40
  x[:co2].value.should eql :somevalue
36
- Transport[:co2].value.should be_nil
41
+ @calc[:co2].value.should be_nil
37
42
  end
38
43
  it 'knows to get terms that come before or after others' do
39
- t=Transport.clone
44
+ t=@calc.clone
40
45
  t.before(:distance).labels.
41
46
  should eql [:fuel,:size]
42
47
  t.after(:distance).map(&:label).
43
48
  should eql [:co2]
44
49
  end
45
50
  it 'delegates selectors to terms list' do
46
- t=Transport.clone
51
+ t=@calc.clone
47
52
  t.drills.labels.should eql [:fuel,:size]
48
53
  end
49
54
  it 'can find its amee data category' do
50
- t=Transport.clone
55
+ t=@calc.clone
51
56
  mocker=AMEEMocker.new self,:path=>'transport/car/generic'
52
57
  mocker.data_category
53
58
  t.send(:amee_data_category).path.should eql '/data/transport/car/generic'
@@ -55,18 +60,18 @@ describe Calculation do
55
60
  it 'can find its amee item definition' do
56
61
  mocker=AMEEMocker.new self,:path=>'transport/car/generic'
57
62
  mocker.item_definition(:my_itemdef_name).data_category
58
- t=Transport.clone
63
+ t=@calc.clone
59
64
  t.send(:amee_item_definition).name.should eql :my_itemdef_name
60
65
  end
61
66
  it 'can give item value definition list' do
62
67
  mocker=AMEEMocker.new self,:path=>'transport/car/generic'
63
68
  mocker.item_value_definition('distance').item_value_definitions.
64
69
  item_definition.data_category
65
- t=Transport.clone
70
+ t=@calc.clone
66
71
  t.send(:amee_ivds).first.path.should eql 'distance'
67
72
  end
68
73
  it 'can memoise access to AMEE' do
69
- t=Transport.clone
74
+ t=@calc.clone
70
75
  #AMEE::Data::Category.get(connection, "/data#{path}")
71
76
  flexmock(AMEE::Data::Category).should_receive(:get).
72
77
  with(AMEE::DataAbstraction.connection,'/data/transport/car/generic').
@@ -1,24 +1,29 @@
1
- require File.dirname(File.dirname(__FILE__)) + '/spec_helper.rb'
1
+ require 'spec_helper'
2
+
2
3
  describe Drill do
4
+
5
+ before :all do
6
+ @calc = CalculationSet.find("transport")[:transport]
7
+ end
3
8
 
4
9
  it 'knows its options when it is the first choice' do
5
10
  AMEEMocker.new(self,:path=>'transport/car/generic',
6
11
  :selections=>[],
7
12
  :choices=>['diesel','petrol']).drill
8
- Transport.begin_calculation[:fuel].send(:choices).should eql ['diesel','petrol']
13
+ @calc.begin_calculation[:fuel].send(:choices).should eql ['diesel','petrol']
9
14
  end
10
15
 
11
16
  it 'knows its options when it is a later choice' do
12
17
  AMEEMocker.new(self,:path=>'transport/car/generic',
13
18
  :selections=>[['fuel','diesel']],
14
19
  :choices=>['large','small']).drill
15
- t=Transport.begin_calculation
20
+ t=@calc.begin_calculation
16
21
  t[:fuel].value 'diesel'
17
22
  t[:size].send(:choices).should eql ['large','small']
18
23
  end
19
24
 
20
- it 'is enabled iff it is the next choice or has been chosen' do
21
- t=Transport.begin_calculation
25
+ it 'is enabled if it is the next choice or has been chosen' do
26
+ t=@calc.begin_calculation
22
27
  t[:fuel].enabled?.should be_true
23
28
  t[:size].enabled?.should be_false
24
29
  t[:fuel].value 'diesel'
@@ -29,11 +34,11 @@ describe Drill do
29
34
  t[:size].enabled?.should be_true
30
35
  end
31
36
 
32
- it 'is valid iff assigned a choice in the choices' do
37
+ it 'is valid if assigned a choice in the choices' do
33
38
  AMEEMocker.new(self,:path=>'transport/car/generic',
34
39
  :selections=>[],
35
40
  :choices=>['diesel','petrol']).drill
36
- t=Transport.begin_calculation
41
+ t=@calc.begin_calculation
37
42
  t[:fuel].value 'diesel'
38
43
  t[:fuel].send(:valid?).should be_true
39
44
  t[:fuel].value 'banana'
@@ -41,7 +46,7 @@ describe Drill do
41
46
  end
42
47
 
43
48
  it "should set and get custom choices" do
44
- t=Transport.begin_calculation
49
+ t=@calc.begin_calculation
45
50
  t[:fuel].choices 'anthracite', 'lignite'
46
51
  t[:fuel].choices.should eql ['anthracite', 'lignite']
47
52
  end
@@ -50,7 +55,7 @@ describe Drill do
50
55
  mocker = AMEEMocker.new(self,:path=>'transport/car/generic',
51
56
  :selections=>[['fuel','diesel']])
52
57
  mocker.drill_with_skip('size'=>'small')
53
- t=Transport.begin_calculation
58
+ t=@calc.begin_calculation
54
59
  t[:fuel].value 'diesel'
55
60
  t[:fuel].should_not be_disabled
56
61
  t[:size].choices.should eql ['small']
@@ -1,77 +1,117 @@
1
- require File.dirname(File.dirname(__FILE__)) + '/spec_helper.rb'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Input do
4
- it 'can be given a fixed value' do
5
- i=Input.new{fixed 6}
6
- i.value.should eql 6
7
- i.fixed?.should be_true
8
- lambda{i.value 7}.should raise_error Exceptions::FixedValueInterference
9
- end
10
- it 'raises exception when invalid' do
11
- i=Input.new{validation /bark/}
12
- i.value 'barking'
13
- lambda{i.validate!}.should_not raise_error
14
- i.value.should eql 'barking'
15
- i.value 'marking'
16
- lambda{i.validate!}.should raise_error Exceptions::ChoiceValidation
17
- j=Input.new{}
18
- j.value 'marking'
19
- j.value.should eql 'marking'
20
- end
21
- it "can accept a numeric symbol validation" do
22
- i=Input.new{validation :numeric}
23
- i.value 3
24
- lambda{i.validate!}.should_not raise_error
25
- i.value '3'
26
- lambda{i.validate!}.should_not raise_error
27
- i.value 'e'
28
- lambda{i.validate!}.should raise_error Exceptions::ChoiceValidation
29
- end
30
- it "can accept a date symbol validation" do
31
- i=Input.new{validation :date}
32
- i.value Date.today
33
- lambda{i.validate!}.should_not raise_error
34
- i.value '2011-01-01'
35
- lambda{i.validate!}.should_not raise_error
36
- i.value 'e'
37
- lambda{i.validate!}.should raise_error Exceptions::ChoiceValidation
38
- end
39
4
 
40
- it "can accept a time symbol validation" do
41
- i=Input.new{validation :datetime}
42
- i.value DateTime.now
43
- lambda{i.validate!}.should_not raise_error
44
- i.value '2011-01-01 09:00:00'
45
- lambda{i.validate!}.should_not raise_error
46
- i.value 'e'
47
- lambda{i.validate!}.should raise_error Exceptions::ChoiceValidation
48
- end
49
- it 'can have custom validation message' do
50
- i=Input.new{label :woof; validation /bark/; validation_message {"#{value} does not match pattern /bark/"}}
51
- i.value 'marking'
52
- lambda{i.validate!}.should raise_error Exceptions::ChoiceValidation,"marking does not match pattern /bark/"
53
- j=Input.new{}
54
- j.value 'marking'
55
- j.value.should eql 'marking'
56
- end
57
- it 'can have default validation message' do
58
- i=Input.new{label :woof; validation /bark/}
59
- i.value 'barking'
60
- lambda{i.validate!}.should_not raise_error
61
- i.value.should eql 'barking'
62
- i.value 'marking'
63
- lambda{i.validate!}.should raise_error Exceptions::ChoiceValidation,"Woof is invalid."
64
- j=Input.new{}
65
- j.value 'marking'
66
- j.value.should eql 'marking'
67
- end
68
- it 'is always valid if it is fixed' do
69
- i=Input.new{fixed 5; validation /7/}
70
- lambda{i.validate!}.should_not raise_error
71
- i.value.should eql 5
72
- end
73
- it 'is always disabled if it is fixed' do
74
- i=Input.new{fixed 5}
75
- i.disabled?.should eql true
76
- end
5
+ it 'can be given a fixed value' do
6
+ i=Input.new{fixed 6}
7
+ i.value.should eql 6
8
+ i.fixed?.should be_true
9
+ lambda{i.value 7}.should raise_error Exceptions::FixedValueInterference
10
+ end
11
+
12
+ it "can be made optional" do
13
+ i=Input.new{label :mass; value 6}
14
+ i.should_not be_optional
15
+ i.should be_compulsory
16
+ i.optional!
17
+ i.should be_optional
18
+ i.should_not be_compulsory
19
+ end
20
+
21
+ it "can be made compulsory" do
22
+ i=Input.new{label :mass; value 6}
23
+ i.should_not be_optional
24
+ i.optional!
25
+ i.should be_optional
26
+ i.should_not be_compulsory
27
+ i.compulsory!
28
+ i.should_not be_optional
29
+ i.should be_compulsory
30
+ end
31
+
32
+ it 'raises exception when invalid' do
33
+ i=Input.new{validation /bark/}
34
+ i.value 'barking'
35
+ lambda{i.validate!}.should_not raise_error
36
+ i.value.should eql 'barking'
37
+ i.value 'marking'
38
+ lambda{i.validate!}.should raise_error Exceptions::ChoiceValidation
39
+ j=Input.new{}
40
+ j.value 'marking'
41
+ j.value.should eql 'marking'
42
+ end
43
+
44
+ it "can accept a numeric symbol validation" do
45
+ i=Input.new{validation :numeric}
46
+ i.value 3
47
+ lambda{i.validate!}.should_not raise_error
48
+ i.value '3'
49
+ lambda{i.validate!}.should_not raise_error
50
+ i.value 'e'
51
+ lambda{i.validate!}.should raise_error Exceptions::ChoiceValidation
52
+ end
53
+
54
+ it "can accept a date symbol validation" do
55
+ i=Input.new{validation :date}
56
+ i.value Date.today
57
+ lambda{i.validate!}.should_not raise_error
58
+ i.value '2011-01-01'
59
+ lambda{i.validate!}.should_not raise_error
60
+ i.value 'e'
61
+ lambda{i.validate!}.should raise_error Exceptions::ChoiceValidation
62
+ end
63
+
64
+ it "can accept a time symbol validation" do
65
+ i=Input.new{validation :datetime}
66
+ i.value DateTime.now
67
+ lambda{i.validate!}.should_not raise_error
68
+ i.value '2011-01-01 09:00:00'
69
+ lambda{i.validate!}.should_not raise_error
70
+ i.value 'e'
71
+ lambda{i.validate!}.should raise_error Exceptions::ChoiceValidation
72
+ end
73
+
74
+ it 'can have custom validation message' do
75
+ i=Input.new{label :woof; validation /bark/; validation_message {"#{value} does not match pattern /bark/"}}
76
+ i.value 'marking'
77
+ lambda{i.validate!}.should raise_error Exceptions::ChoiceValidation,"marking does not match pattern /bark/"
78
+ j=Input.new{}
79
+ j.value 'marking'
80
+ j.value.should eql 'marking'
81
+ end
82
+
83
+ it 'can have default validation message' do
84
+ i=Input.new{label :woof; validation /bark/}
85
+ i.value 'barking'
86
+ lambda{i.validate!}.should_not raise_error
87
+ i.value.should eql 'barking'
88
+ i.value 'marking'
89
+ lambda{i.validate!}.should raise_error Exceptions::ChoiceValidation,"Woof is invalid."
90
+ j=Input.new{}
91
+ j.value 'marking'
92
+ j.value.should eql 'marking'
93
+ end
94
+
95
+ it 'is always valid if it is fixed' do
96
+ i=Input.new{fixed 5; validation /7/}
97
+ lambda{i.validate!}.should_not raise_error
98
+ i.value.should eql 5
99
+ end
100
+
101
+ it 'is always disabled if it is fixed' do
102
+ i=Input.new{fixed 5}
103
+ i.disabled?.should eql true
104
+ end
105
+
106
+ it "should start with dirty set as false" do
107
+ i=Input.new{fixed 5}
108
+ i.dirty?.should eql false
109
+ end
110
+
111
+ it "should be dirty when the value is changed" do
112
+ i=Input.new
113
+ i.value 5
114
+ i.dirty?.should eql true
115
+ end
116
+
77
117
  end
@@ -1,4 +1,4 @@
1
- require File.dirname(File.dirname(__FILE__)) + '/spec_helper.rb'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Metadatum do
4
4
  it 'defaults to be a drop-down' do
@@ -1,7 +1,15 @@
1
- require File.dirname(File.dirname(__FILE__)) + '/spec_helper.rb'
1
+ require 'spec_helper'
2
+
2
3
  describe OngoingCalculation do
4
+
5
+ before :all do
6
+ @elec = CalculationSet.find("electricity")[:electricity]
7
+ @transport = CalculationSet.find("transport")[:transport]
8
+ @elec_and_transport = CalculationSet.find("electricity_and_transport")
9
+ end
10
+
3
11
  it 'can return set and unset inputs' do
4
- d=Electricity.begin_calculation
12
+ d=@elec.begin_calculation
5
13
  d.inputs.set.labels.should eql [:country]
6
14
  d.inputs.unset.labels.should eql [:energy_used]
7
15
  d[:energy_used].value :somevalue
@@ -9,7 +17,7 @@ describe OngoingCalculation do
9
17
  d.inputs.unset.labels.should eql []
10
18
  end
11
19
  it 'can return set and unset terms' do
12
- d=Electricity.begin_calculation
20
+ d=@elec.begin_calculation
13
21
  d.set.labels.should eql [:country]
14
22
  d.unset.labels.should eql [:energy_used,:co2]
15
23
  d[:energy_used].value :somevalue
@@ -17,7 +25,7 @@ describe OngoingCalculation do
17
25
  d.unset.labels.should eql [:co2]
18
26
  end
19
27
  it 'can return set and unset outputs' do
20
- d=Electricity.begin_calculation
28
+ d=@elec.begin_calculation
21
29
  d.outputs.set.labels.should eql []
22
30
  d.outputs.unset.labels.should eql [:co2]
23
31
  d[:co2].value 5
@@ -25,7 +33,7 @@ describe OngoingCalculation do
25
33
  d.outputs.unset.labels.should eql []
26
34
  end
27
35
  it 'can clear outputs' do
28
- d=Electricity.begin_calculation
36
+ d=@elec.begin_calculation
29
37
  d.outputs.unset.labels.should eql [:co2]
30
38
  d[:co2].value 5
31
39
  d[:co2].value.should eql 5
@@ -37,7 +45,7 @@ describe OngoingCalculation do
37
45
  :selections=>[['country','argentina']],
38
46
  :choices=>[]).drill
39
47
 
40
- d=Electricity.begin_calculation
48
+ d=@elec.begin_calculation
41
49
 
42
50
  d.inputs.set.values.should eql ['argentina']
43
51
  d.inputs.unset.values.should eql [nil]
@@ -51,7 +59,7 @@ describe OngoingCalculation do
51
59
  AMEEMocker.new(self,:path=>'business/energy/electricity/grid',
52
60
  :selections=>[['country','argentina']],
53
61
  :choices=>[]).drill
54
- d=Electricity.begin_calculation
62
+ d=@elec.begin_calculation
55
63
  d.satisfied?.should be_false
56
64
  d.choose!(:energy_used=>5.0)
57
65
  d.satisfied?.should be_true
@@ -66,7 +74,7 @@ describe OngoingCalculation do
66
74
  mocker.select('size'=>'large')
67
75
  mocker.choices=[]
68
76
  mocker.drill
69
- t=Transport.begin_calculation
77
+ t=@transport.begin_calculation
70
78
  t.terms.labels.should eql [:fuel,:size,:distance,:co2]
71
79
  t.satisfied?.should be_false
72
80
 
@@ -75,13 +83,13 @@ describe OngoingCalculation do
75
83
  t.inputs.unset.labels.should eql [:size,:distance]
76
84
  t.satisfied?.should be_false
77
85
 
78
- t2=Transport.begin_calculation
86
+ t2=@transport.begin_calculation
79
87
  t2.choose!('fuel'=>'diesel','size'=>'large')
80
88
  t2.inputs.set.labels.should eql [:fuel,:size]
81
89
  t2.inputs.unset.labels.should eql [:distance]
82
90
  t2.satisfied?.should be_false
83
91
 
84
- t3=Transport.begin_calculation
92
+ t3=@transport.begin_calculation
85
93
  t3.choose!('fuel'=>'diesel','size'=>'large','distance'=>5)
86
94
  t3.inputs.set.labels.should eql [:fuel,:size,:distance]
87
95
  t3.inputs.unset.labels.should eql []
@@ -100,7 +108,7 @@ describe OngoingCalculation do
100
108
  mocker.choices=[]
101
109
  mocker.drill
102
110
  mocker.profile_list.profile_category.timestamp.create_and_get
103
- mycalc=Transport.begin_calculation
111
+ mycalc=@transport.begin_calculation
104
112
  mycalc.choose!('fuel'=>'diesel','size'=>'large','distance'=>5)
105
113
  mycalc.calculate!
106
114
  mycalc.outputs.first.value.should eql :somenumber
@@ -118,7 +126,7 @@ describe OngoingCalculation do
118
126
  mocker.choices=[]
119
127
  mocker.drill
120
128
  mocker.profile_list.profile_category.timestamp.create_and_get
121
- mycalc=ElectricityAndTransport[:transport].begin_calculation
129
+ mycalc=@elec_and_transport[:transport].begin_calculation
122
130
  mycalc.choose!('fuel'=>'diesel','size'=>'large','distance'=>5,'department'=>'stuff')
123
131
  mycalc.calculate!
124
132
  mycalc.outputs.first.value.should eql :somenumber
@@ -142,7 +150,7 @@ describe OngoingCalculation do
142
150
  #end
143
151
 
144
152
  it 'can be supplied just a UID, and recover PIVs and drill values from AMEE' do
145
- mycalc=Transport.begin_calculation
153
+ mycalc=@transport.begin_calculation
146
154
  mocker=AMEEMocker.new(self,:path=>'transport/car/generic',
147
155
  :result=>:somenumber,
148
156
  :existing=>{'distance'=>5},:choices=>['petrol','diesel'])
@@ -159,7 +167,7 @@ describe OngoingCalculation do
159
167
  end
160
168
 
161
169
  it 'refuses to load values from AMEE which conflict with local drill values' do
162
- mycalc=Transport.begin_calculation
170
+ mycalc=@transport.begin_calculation
163
171
  mocker=AMEEMocker.new(self,:path=>'transport/car/generic',
164
172
  :result=>:somenumber,
165
173
  :existing=>{'distance'=>7},
@@ -195,7 +203,7 @@ describe OngoingCalculation do
195
203
  mocker.choices=[]
196
204
  mocker.drill
197
205
  mocker.profile_list.update.get(true)
198
- mycalc=Transport.begin_calculation
206
+ mycalc=@transport.begin_calculation
199
207
  mycalc.choose!(:profile_item_uid=>mocker.uid,'fuel'=>'diesel','size'=>'large','distance'=>9)
200
208
  mycalc.calculate!
201
209
  mycalc[:distance].value.should eql 9
@@ -219,7 +227,7 @@ describe OngoingCalculation do
219
227
  mocker.params={'distance'=>9}
220
228
  mocker.update.get(true)
221
229
 
222
- mycalc=Transport.begin_calculation
230
+ mycalc=@transport.begin_calculation
223
231
  mycalc.choose!('fuel'=>'diesel','size'=>'large','distance'=>5)
224
232
  mycalc.calculate!
225
233
  mycalc.choose!('fuel'=>'diesel','size'=>'large','distance'=>9)
@@ -244,7 +252,7 @@ describe OngoingCalculation do
244
252
  mocker.select('size'=>'small')
245
253
  mocker.drill.create_and_get
246
254
 
247
- mycalc=Transport.begin_calculation
255
+ mycalc=@transport.begin_calculation
248
256
  mycalc.choose!('fuel'=>'diesel','size'=>'large','distance'=>5)
249
257
  mycalc.calculate!
250
258
  mycalc.choose!('fuel'=>'diesel','size'=>'small')
@@ -253,7 +261,7 @@ describe OngoingCalculation do
253
261
  end
254
262
 
255
263
  it 'memoizes profile information, but not across a pass' do
256
- mycalc=Transport.begin_calculation
264
+ mycalc=@transport.begin_calculation
257
265
  mocker=AMEEMocker.new(self,:path=>'transport/car/generic',
258
266
  :result=>:somenumber,
259
267
  :existing=>{'distance'=>5},:choices=>['petrol','diesel'])
@@ -285,7 +293,7 @@ describe OngoingCalculation do
285
293
  mocker.choices=[]
286
294
  mocker.drill
287
295
  mocker.profile_list.profile_category.timestamp.create_and_get
288
- myproto=Transport.clone
296
+ myproto=@transport.clone
289
297
  myproto.instance_eval{
290
298
  start_and_end_dates
291
299
  }
@@ -308,7 +316,7 @@ describe OngoingCalculation do
308
316
  mocker.select('size'=>'large')
309
317
  mocker.choices=[]
310
318
  mocker.drill
311
- myproto=Transport.clone
319
+ myproto=@transport.clone
312
320
  myproto.instance_eval{
313
321
  start_and_end_dates
314
322
  }
@@ -318,7 +326,7 @@ describe OngoingCalculation do
318
326
  end
319
327
 
320
328
  it 'starts off dirty' do
321
- mycalc=Transport.begin_calculation
329
+ mycalc=@transport.begin_calculation
322
330
  mycalc.should be_dirty
323
331
  end
324
332
 
@@ -335,7 +343,7 @@ describe OngoingCalculation do
335
343
  mocker.choices=[]
336
344
  mocker.drill
337
345
  mocker.profile_list.profile_category.timestamp.create_and_get
338
- mycalc=Transport.begin_calculation
346
+ mycalc=@transport.begin_calculation
339
347
  mycalc.should be_dirty
340
348
  mycalc.choose!('fuel'=>'diesel','size'=>'large','distance'=>5)
341
349
  mycalc.calculate!
@@ -357,7 +365,7 @@ describe OngoingCalculation do
357
365
  mocker.choices=[]
358
366
  mocker.drill
359
367
  mocker.profile_list.profile_category.timestamp.create_and_get
360
- mycalc=Transport.begin_calculation
368
+ mycalc=@transport.begin_calculation
361
369
  mycalc.should be_dirty
362
370
  mycalc.choose!('fuel'=>'diesel','size'=>'large','distance'=>5)
363
371
  mycalc.calculate!
@@ -380,7 +388,7 @@ describe OngoingCalculation do
380
388
  mocker.select('size'=>'marge')
381
389
  mocker.choices=[]
382
390
  mocker.drill
383
- mycalc=Transport.begin_calculation
391
+ mycalc=@transport.begin_calculation
384
392
  lambda{mycalc.choose!('fuel'=>'diesel','size'=>'marge','distance'=>5)}.should raise_error Exceptions::ChoiceValidation
385
393
  mycalc.invalidity_messages.keys.should eql [:size]
386
394
  end
@@ -397,7 +405,7 @@ describe OngoingCalculation do
397
405
  mocker.select('size'=>'marge')
398
406
  mocker.choices=[]
399
407
  mocker.drill
400
- mycalc=Transport.begin_calculation
408
+ mycalc=@transport.begin_calculation
401
409
  mycalc.choose('fuel'=>'diesel','size'=>'marge','distance'=>5).should be_false
402
410
  mycalc.invalidity_messages.keys.should eql [:size]
403
411
  end
@@ -414,12 +422,12 @@ describe OngoingCalculation do
414
422
  mocker.select('size'=>'large')
415
423
  mocker.choices=[]
416
424
  mocker.drill
417
- mycalc=Transport.begin_calculation
425
+ mycalc=@transport.begin_calculation
418
426
  mycalc.choose('fuel'=>'diesel','size'=>'large','distance'=>5).should be_true
419
427
  end
420
428
 
421
429
  it 'can blank individual term attributes with empty string' do
422
- myproto=Transport.clone
430
+ myproto=@transport.clone
423
431
  mycalc=myproto.begin_calculation
424
432
  mycalc.choose_without_validation!('fuel'=>'diesel','size'=>'large','distance'=>{:value =>5, :unit=> Unit.km})
425
433
  mycalc['fuel'].value.should eql 'diesel'
@@ -434,7 +442,7 @@ describe OngoingCalculation do
434
442
  end
435
443
 
436
444
  it 'can blank individual term attributes with nil' do
437
- myproto=Transport.clone
445
+ myproto=@transport.clone
438
446
  mycalc=myproto.begin_calculation
439
447
  mycalc.choose_without_validation!('fuel'=>'diesel','size'=>'large','distance'=>{:value =>5, :unit=> Unit.km})
440
448
  mycalc['fuel'].value.should eql 'diesel'
@@ -449,7 +457,7 @@ describe OngoingCalculation do
449
457
  end
450
458
 
451
459
  it 'can update individual term attributes without nullifying others' do
452
- myproto=Transport.clone
460
+ myproto=@transport.clone
453
461
  mycalc=myproto.begin_calculation
454
462
  mycalc.choose_without_validation!('fuel'=>'diesel','size'=>'large','distance'=>{:value =>5, :unit=> Unit.km})
455
463
  mycalc['fuel'].value.should eql 'diesel'
@@ -490,7 +498,7 @@ describe OngoingCalculation do
490
498
  mocker.select('size'=>'marge')
491
499
  mocker.choices=[]
492
500
  mocker.drill
493
- mycalc=Transport.begin_calculation
501
+ mycalc=@transport.begin_calculation
494
502
  mycalc.choose('fuel'=>'diesel','size'=>'marge','distance'=>5).should be_false
495
503
  mycalc.invalidity_messages.keys.should eql [:size]
496
504
  mycalc[:size].value.should eql 'marge'