ski_binding_calculator 0.7.1 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,4 @@
1
- class SkiBinding::Error < StandardError
2
-
1
+ class SkiBinding::Error < StandardError
3
2
  def initialize(key = nil, value = nil)
4
3
  @messages = {}
5
4
 
@@ -0,0 +1,3 @@
1
+ module SkiBinding
2
+ VERSION = "0.8.0"
3
+ end
@@ -1,4 +1,4 @@
1
- require 'ski_binding_calculator/ski_binding'
1
+ require 'ski_binding_calculator/version'
2
2
  require 'ski_binding_calculator/calculator'
3
3
  require 'ski_binding_calculator/config_loader'
4
4
  require 'ski_binding_calculator/code'
@@ -1,20 +1,22 @@
1
- Gem::Specification.new do |s|
1
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
2
+ require 'ski_binding_calculator/version'
2
3
 
4
+ Gem::Specification.new do |s|
3
5
  s.name = 'ski_binding_calculator'
4
- s.version = '0.7.1'
5
- s.summary = "Ski Binding Calculator"
6
- s.description = "Calculates the z-value according to ISO 11088."
6
+ s.version = SkiBinding::VERSION
7
+ s.summary = "Ski binding release value calculator (ISO 11088)"
8
+ s.description = "Calculates the initial indicator value (z-value) according to ISO 11088 standard."
7
9
  s.authors = ["Jonas Ruef, Felix Langenegger"]
8
10
  s.email = 'support@fadendaten.ch'
9
11
  s.homepage = 'http://fadendaten.ch'
10
12
  s.license = 'MIT'
11
13
 
14
+ s.add_dependency "activesupport", "~> 4.0.0"
12
15
  s.add_development_dependency "rspec", "~> 2.14.1"
13
16
  s.add_development_dependency "spork", "~> 0.9.2"
14
17
  s.add_development_dependency "simplecov", "~> 0.7.1"
15
18
  s.add_development_dependency "timecop", "~> 0.6.3"
16
- s.add_development_dependency "fuubar", "~> 1.1.1"
17
- s.add_development_dependency "activesupport", "~> 4.0.0"
19
+ s.add_development_dependency "fuubar", "~> 1.2.1"
18
20
 
19
21
  s.files = Dir.glob("{config,lib,spec}/**/*")
20
22
  s.files += %w(Rakefile ski_binding_calculator.gemspec)
@@ -6,7 +6,7 @@ require 'timecop'
6
6
  # 315mm, and is born 01/01/1983 has code "L" or in our notation 11
7
7
  # (see readme for details on codes). Furthermore it's z_value is 6.
8
8
  describe SkiBinding::Calculator do
9
- subject(:skiers_parameters) do
9
+ let(:skiers_parameter) do
10
10
  { :type => "Type2",
11
11
  :weight => "70",
12
12
  :height => "170",
@@ -15,7 +15,7 @@ describe SkiBinding::Calculator do
15
15
  :birthday_month => "01",
16
16
  :birthday_day => "01" }
17
17
  end
18
- subject(:skiers_parameters_string_keys) do
18
+ let(:skiers_parameter_string_keys) do
19
19
  { "type" => "Type2",
20
20
  "weight" => "70",
21
21
  "height" => "170",
@@ -24,7 +24,7 @@ describe SkiBinding::Calculator do
24
24
  "birthday_month" => "01",
25
25
  "birthday_day" => "01" }
26
26
  end
27
- subject(:expected_preped) do
27
+ let(:expected_preped) do
28
28
  { :type => "Type2",
29
29
  :weight => 70.0,
30
30
  :height => 170.0,
@@ -33,22 +33,22 @@ describe SkiBinding::Calculator do
33
33
  :birthday_month => 1,
34
34
  :birthday_day => 1 }
35
35
  end
36
- subject(:expected_aged) do
36
+ let(:expected_aged) do
37
37
  { :type => "Type2",
38
38
  :weight => 70.0,
39
39
  :height => 170.0,
40
40
  :sole_length => 315.0,
41
41
  :age => 30 }
42
42
  end
43
- subject(:expected_validated) do
43
+ let(:expected_type_validated) do
44
44
  { :type => 1,
45
45
  :weight => 70.0,
46
46
  :height => 170.0,
47
47
  :sole_length => 315.0,
48
48
  :age => 30 }
49
49
  end
50
- subject(:expected_code) { 11 }
51
- subject(:expected_setting) do
50
+ let(:expected_code) { 11 }
51
+ let(:expected_setting) do
52
52
  { :z_value => 6 }
53
53
  end
54
54
 
@@ -56,155 +56,177 @@ describe SkiBinding::Calculator do
56
56
  #freeze time! so birthday will always be 30 years back
57
57
  Timecop.freeze(2013, 8, 13)
58
58
  end
59
-
60
- describe "#new" do
61
- it { SkiBinding::Calculator.new.class.should == SkiBinding::Calculator }
62
- end
63
59
 
64
- describe "#validate_attrs" do
65
- subject(:calculated_attr_validation) { SkiBinding::Calculator.validate_attrs(parameters) }
66
- let(:parameters) do
67
- skiers_parameters[:weight] = ""
68
- skiers_parameters[:height] = ""
69
- skiers_parameters
70
- end
60
+ describe ".validate_attrs" do
61
+ let(:calculated_validated) { SkiBinding::Calculator.validate_attrs(parameters) }
71
62
 
72
- it "raise error with two messages" do
73
- expect { calculated_attr_validation }.to raise_error(SkiBinding::Error) { |e|
74
- e.messages.should == { :weight => "is blank", :height => "is blank" } }
75
- end
63
+ context "when attributes are blank" do
64
+ let(:parameters) do
65
+ skiers_parameter[:weight] = ""
66
+ skiers_parameter[:height] = ""
67
+ skiers_parameter
68
+ end
69
+
70
+ it "raises SkiBinding::Error" do
71
+ expect { calculated_validated }.to raise_error(SkiBinding::Error) { |e|
72
+ e.messages.should == { :weight => "is blank", :height => "is blank" } }
73
+ end
74
+ end
76
75
  end
77
76
 
78
- describe "#prep_attributes" do
79
- subject(:calculated_preped) { SkiBinding::Calculator.prep_attributes(parameters) }
80
- let(:parameters) { skiers_parameters }
77
+ describe ".prep_attributes" do
78
+ let(:calculated_preped) { SkiBinding::Calculator.prep_attributes(parameters) }
81
79
 
82
- it { calculated_preped.should == expected_preped }
80
+ context "when input hash keys are symbols" do
81
+ let(:parameters) { skiers_parameter }
82
+
83
+ it "calculates the expected preped hash" do
84
+ expect(calculated_preped).to eq(expected_preped)
85
+ end
86
+ end
83
87
 
84
- context "when hash keys are strings" do
85
- let(:parameters) { skiers_parameters_string_keys}
86
- it { calculated_preped.should == expected_preped }
88
+ context "when input hash key are strings" do
89
+ let(:parameters) { skiers_parameter_string_keys}
90
+
91
+ it "calculates the expected preped hash" do
92
+ expect(calculated_preped).to eq(expected_preped)
93
+ end
87
94
  end
88
95
 
89
- context "when weight < 10kg" do
96
+ context "when weight is less than 9kg" do
90
97
  let(:parameters) do
91
- skiers_parameters[:weight] = 9
92
- skiers_parameters
98
+ skiers_parameter[:weight] = 9
99
+ skiers_parameter
93
100
  end
94
- it "raise error" do
101
+ it "raises SkiBinding::Error" do
95
102
  expect { calculated_preped }.to raise_error(SkiBinding::Error) { |e|
96
103
  e.messages.should == { :weight => "is less than 10kg" } }
97
104
  end
98
105
  end
99
106
  end
100
107
 
101
- describe "#age" do
102
- subject(:calculated_aged) { SkiBinding::Calculator.age(preped) }
103
- let(:preped) { expected_preped }
108
+ describe ".age" do
109
+ let(:calculated_aged) { SkiBinding::Calculator.age(expected_preped) }
104
110
 
105
- it { calculated_aged.should == expected_aged }
111
+ it "replaces birthday by age" do
112
+ expect(calculated_aged).to eq(expected_aged)
113
+ end
106
114
  end
107
115
 
108
- describe "#validate_type" do
109
- subject(:calculated_validated) { SkiBinding::Calculator.validate_type(aged) }
116
+ describe ".validate_type" do
117
+ let(:calculated_type_validated) { SkiBinding::Calculator.validate_type(aged) }
110
118
  let(:aged) { expected_aged }
111
119
 
112
- it "sets \"Type2\" to 1" do
113
- calculated_validated.should == expected_validated
120
+ it "sets 'Type2' to 1" do
121
+ expect(calculated_type_validated[:type]).to eq(expected_type_validated[:type])
114
122
  end
115
123
 
116
- context "when type is \"unknown\"" do
124
+ context "when type is 'unknown'" do
117
125
  let(:aged) do
118
126
  expected_aged[:type] = "unknown"
119
127
  expected_aged
120
128
  end
121
129
 
122
- it "raise error" do
123
- expect { calculated_validated }.to raise_error(SkiBinding::Error) { |e|
130
+ it "raises SkiBinding::Error" do
131
+ expect { calculated_type_validated }.to raise_error(SkiBinding::Error) { |e|
124
132
  e.messages.should == { :type => "You have entered an invalid type." } }
125
133
  end
126
134
  end
127
135
  end
128
136
 
129
- describe "#binding_code" do
130
- subject(:calculated_code) { SkiBinding::Calculator.binding_code(validated) }
131
- let(:validated) { expected_validated }
137
+ describe ".binding_code" do
138
+ let(:calculated_code) { SkiBinding::Calculator.binding_code(validated) }
139
+ let(:validated) { expected_type_validated }
132
140
 
133
- it{ calculated_code.should == 11 }
141
+ it "calculates the expected code" do
142
+ expect(calculated_code).to eq(11)
143
+ end
134
144
 
135
- context "when weight < 13kg" do
145
+ context "when weight less than 13kg" do
136
146
  let(:validated) do
137
- expected_validated[:weight] = 12
138
- expected_validated
147
+ expected_type_validated[:weight] = 12
148
+ expected_type_validated
139
149
  end
150
+
140
151
  #because "Type 2" is given the code would be changed to 1
141
- it{ calculated_code.should == 0 }
152
+ it "code is unchanged" do
153
+ expect(calculated_code).to eq(0)
154
+ end
142
155
  end
143
156
 
144
157
  context "when no code found" do
145
158
  let(:validated) do
146
- expected_validated[:weight] = -1
147
- expected_validated[:height] = -1
148
- expected_validated
159
+ expected_type_validated[:weight] = -1
160
+ expected_type_validated[:height] = -1
161
+ expected_type_validated
149
162
  end
150
163
 
151
- it "raises error" do
164
+ it "raises SkiBinding::Error" do
152
165
  expect { calculated_code }.to raise_error(SkiBinding::Error) { |e|
153
166
  e.messages.should == { :base => "You have entered invalid weight and/or height" } }
154
167
  end
155
168
  end
156
169
 
157
- context "when age >= 50 || age < 10" do
158
- context "age is 50" do
170
+ context "when age is bigger or equal 50 or less than 10" do
171
+ context "when age is 50" do
159
172
  let(:validated) do
160
- expected_validated[:age] = 50
161
- expected_validated
173
+ expected_type_validated[:age] = 50
174
+ expected_type_validated
162
175
  end
163
176
 
164
- it { calculated_code.should == (expected_code - 1) }
177
+ it "code changes by -1" do
178
+ expect(calculated_code).to eq(expected_code - 1)
179
+ end
165
180
  end
166
181
 
167
- context "age is 51" do
182
+ context "when age is 51" do
168
183
  let(:validated) do
169
- expected_validated[:age] = 51
170
- expected_validated
184
+ expected_type_validated[:age] = 51
185
+ expected_type_validated
171
186
  end
172
187
 
173
- it { calculated_code.should == (expected_code - 1) }
188
+ it "code changes by -1" do
189
+ expect(calculated_code).to eq(expected_code - 1)
190
+ end
174
191
  end
175
192
 
176
- context "age is 9" do
193
+ context "when age is 9" do
177
194
  let(:validated) do
178
- expected_validated[:age] = 9
179
- expected_validated
195
+ expected_type_validated[:age] = 9
196
+ expected_type_validated
180
197
  end
181
198
 
182
- it { calculated_code.should == (expected_code - 1) }
199
+ it "code changes by -1" do
200
+ expect(calculated_code).to eq(expected_code - 1)
201
+ end
183
202
  end
184
203
  end
185
204
  end
186
-
187
- describe "#binding_setting" do
188
- subject(:calculated_setting) { SkiBinding::Calculator.binding_setting(validated, binding_code) }
205
+
206
+ describe ".binding_setting" do
207
+ let(:calculated_setting) { SkiBinding::Calculator.binding_setting(expected_type_validated, binding_code) }
189
208
  let(:binding_code) { expected_code }
190
- let(:validated) { expected_validated }
191
209
 
192
- it{ calculated_setting.should == expected_setting }
210
+ it "calculates the expected setting" do
211
+ expect(calculated_setting).to eq(expected_setting)
212
+ end
193
213
 
194
214
  context "when no setting found" do
195
215
  let(:binding_code) { 0 }
196
- it "raise error" do
216
+
217
+ it "raises SkiBinding::Error" do
197
218
  expect { calculated_setting }.to raise_error(SkiBinding::Error) { |e|
198
219
  e.messages.should == { :base => "Please calculate z-index by hand." } }
199
220
  end
200
221
  end
201
222
  end
202
-
203
- describe "#setting" do
204
- subject(:all_at_once_calculated) { SkiBinding::Calculator.setting(parameters) }
205
- let(:parameters) { skiers_parameters }
223
+
224
+ describe ".setting" do
225
+ subject(:one_pass_calculated_setting) { SkiBinding::Calculator.setting(skiers_parameter) }
206
226
 
207
- it{ all_at_once_calculated.should == expected_setting }
227
+ it "calculates the expected setting in one pass" do
228
+ expect(one_pass_calculated_setting).to eq(expected_setting)
229
+ end
208
230
  end
209
231
 
210
232
  after(:all) do
@@ -1,15 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe SkiBinding::Code do
4
- describe "#new" do
5
- it "should return a Code class" do
6
- SkiBinding::Code.new.class.should == SkiBinding::Code
7
- end
8
- end
9
-
10
- context "when instantiated Code class" do
11
- it { should respond_to :weight }
12
- it { should respond_to :height }
13
- end
3
+ describe SkiBinding::Code do
4
+ it { should respond_to :weight }
5
+ it { should respond_to :height }
14
6
  end
15
7
 
@@ -1,36 +1,31 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  # For original table with codes referred to in this tests see iso 11088
4
- # Table B.1
4
+ # table B.1
5
5
  describe "ConfigLoader" do
6
- subject(:dummy_class) { DummyClass.new.extend(SkiBinding::ConfigLoader) }
6
+ subject(:dummy_class) { double('empty class').extend SkiBinding::ConfigLoader }
7
7
 
8
- describe "loading binding codes:" do
9
- it { dummy_class.load_binding_codes.class.should_not == nil }
10
-
11
- context "when loaded codes" do
12
- subject(:codes) { dummy_class.load_binding_codes }
8
+ describe "#load_binding_codes" do
9
+ context "loaded binding codes" do
10
+ let(:loaded_codes) { dummy_class.load_binding_codes }
13
11
 
14
- it{ codes.class.should == Array }
15
- it{ codes[0].class.should == SkiBinding::Code }
16
- it{ codes.size.should == 13 }
12
+ it{ expect(loaded_codes).to be_instance_of(Array)}
13
+ it{ loaded_codes.should have(13).elements }
14
+ it "first element is instance of SkiBinding::Code" do
15
+ expect(loaded_codes[0]).to be_instance_of(SkiBinding::Code)
16
+ end
17
17
  end
18
18
  end
19
19
 
20
- describe "loading binding settings for all codes" do
21
- subject(:settings_all_codes) do
22
- settings = []
23
- (0..15).each { |i| settings << dummy_class.load_binding_settings(i) }
24
- settings
25
- end
20
+ describe "#load_binding_setting" do
21
+ let(:settings_all_codes) { (0..15).map { |i| dummy_class.load_binding_settings(i) } }
26
22
 
27
- context "for each code" do
28
- it { settings_all_codes.each { |s| s.class.should == Array } }
29
- it { settings_all_codes.each { |s| s[0].class.should == SkiBinding::Setting } }
30
- it { settings_all_codes.each { |s| s.size.should == 8 } }
23
+ context "for each code loaded settings" do
24
+ it { settings_all_codes.each { |s| expect(s).to be_instance_of(Array) } }
25
+ it { settings_all_codes.each { |s| s.should have(8).elements } }
26
+ it "first element is instance of SkiBinding::Setting" do
27
+ settings_all_codes.each { |s| expect(s[0]).to be_instance_of(SkiBinding::Setting) }
28
+ end
31
29
  end
32
30
  end
33
- end
34
-
35
- class DummyClass
36
31
  end
@@ -1,16 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe SkiBinding::Setting do
4
- describe "#new" do
5
- it "should return a Setting class" do
6
- SkiBinding::Setting.new.class.should == SkiBinding::Setting
7
- end
8
- end
9
-
10
- context "when instantiated Setting class" do
11
- it { should respond_to :sole_length_range }
12
- it { should respond_to :z_value }
13
- it { should respond_to :twist }
14
- it { should respond_to :forward_lean }
15
- end
4
+ it { should respond_to :sole_length_range }
5
+ it { should respond_to :z_value }
6
+ it { should respond_to :twist }
7
+ it { should respond_to :forward_lean }
16
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ski_binding_calculator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.8.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-16 00:00:00.000000000 Z
12
+ date: 2013-08-17 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activesupport
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 4.0.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 4.0.0
14
30
  - !ruby/object:Gem::Dependency
15
31
  name: rspec
16
32
  requirement: !ruby/object:Gem::Requirement
@@ -82,7 +98,7 @@ dependencies:
82
98
  requirements:
83
99
  - - ~>
84
100
  - !ruby/object:Gem::Version
85
- version: 1.1.1
101
+ version: 1.2.1
86
102
  type: :development
87
103
  prerelease: false
88
104
  version_requirements: !ruby/object:Gem::Requirement
@@ -90,24 +106,9 @@ dependencies:
90
106
  requirements:
91
107
  - - ~>
92
108
  - !ruby/object:Gem::Version
93
- version: 1.1.1
94
- - !ruby/object:Gem::Dependency
95
- name: activesupport
96
- requirement: !ruby/object:Gem::Requirement
97
- none: false
98
- requirements:
99
- - - ~>
100
- - !ruby/object:Gem::Version
101
- version: 4.0.0
102
- type: :development
103
- prerelease: false
104
- version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
- requirements:
107
- - - ~>
108
- - !ruby/object:Gem::Version
109
- version: 4.0.0
110
- description: Calculates the z-value according to ISO 11088.
109
+ version: 1.2.1
110
+ description: Calculates the initial indicator value (z-value) according to ISO 11088
111
+ standard.
111
112
  email: support@fadendaten.ch
112
113
  executables: []
113
114
  extensions: []
@@ -120,7 +121,7 @@ files:
120
121
  - lib/ski_binding_calculator/config_loader.rb
121
122
  - lib/ski_binding_calculator/error.rb
122
123
  - lib/ski_binding_calculator/setting.rb
123
- - lib/ski_binding_calculator/ski_binding.rb
124
+ - lib/ski_binding_calculator/version.rb
124
125
  - lib/ski_binding_calculator.rb
125
126
  - spec/lib/calculator_spec.rb
126
127
  - spec/lib/code_spec.rb
@@ -153,5 +154,5 @@ rubyforge_project:
153
154
  rubygems_version: 1.8.25
154
155
  signing_key:
155
156
  specification_version: 3
156
- summary: Ski Binding Calculator
157
+ summary: Ski binding release value calculator (ISO 11088)
157
158
  test_files: []
@@ -1,2 +0,0 @@
1
- module SkiBinding
2
- end