m9t 0.3.6 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,36 +1,34 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
- require 'm9t/distance'
1
+ require "m9t/distance"
4
2
 
5
3
  describe M9t::Distance do
6
- context 'class methods' do
7
- it 'has a measurement name' do
8
- expect(M9t::Distance.measurement_name).to eq('distance')
4
+ context "class methods" do
5
+ it "has a measurement name" do
6
+ expect(M9t::Distance.measurement_name).to eq("distance")
9
7
  end
10
8
 
11
- context 'default options' do
12
- it 'has options' do
9
+ context "default options" do
10
+ it "has options" do
13
11
  expect(M9t::Distance.options).not_to be_nil
14
12
  end
15
13
 
16
- it 'not abbreviated' do
14
+ it "not abbreviated" do
17
15
  expect(M9t::Distance.options[:abbreviated]).to be_falsey
18
16
  end
19
17
 
20
- it 'units: meters' do
18
+ it "units: meters" do
21
19
  expect(M9t::Distance.options[:units]).to be(:meters)
22
20
  end
23
21
 
24
- it 'precision: 5' do
22
+ it "precision: 5" do
25
23
  expect(M9t::Distance.options[:precision]).to eq(5)
26
24
  end
27
25
  end
28
26
 
29
- it 'constructs from meters' do
27
+ it "constructs from meters" do
30
28
  expect(M9t::Distance.new(0.3).to_f).to eq(0.3)
31
29
  end
32
30
 
33
- context 'units factories' do
31
+ context "units factories" do
34
32
  [
35
33
  [:meters, 0.3, 0.3],
36
34
  [:kilometers, 0.3, 300.0],
@@ -43,10 +41,10 @@ describe M9t::Distance do
43
41
  end
44
42
  end
45
43
 
46
- context 'conversions' do
44
+ context "conversions" do
47
45
  [
48
- ['meters', 'kilometers', 0.3, 0.0003],
49
- ['miles', 'kilometers', 26.21875, 42.194988]
46
+ ["meters", "kilometers", 0.3, 0.0003],
47
+ ["miles", "kilometers", 26.21875, 42.194988]
50
48
  ].each do |from, to, input, expected|
51
49
  method = :"#{from}_to_#{to}"
52
50
  specify method do
@@ -56,75 +54,74 @@ describe M9t::Distance do
56
54
  end
57
55
  end
58
56
 
59
- context '.conversions' do
60
- specify '#to_meters' do
57
+ context ".conversions" do
58
+ specify "#to_meters" do
61
59
  expect(M9t::Distance.new(0.3).to_meters).to eq(0.3)
62
60
  end
63
61
 
64
- specify '#to_kilometers' do
62
+ specify "#to_kilometers" do
65
63
  expect(M9t::Distance.new(0.3).to_kilometers).to eq(0.0003)
66
64
  end
67
65
 
68
- specify '#to_feet' do
66
+ specify "#to_feet" do
69
67
  expect(M9t::Distance.new(0.3).to_feet).to be_within(0.00001).of(0.98425)
70
68
  end
71
69
  end
72
70
 
73
- context '#to_s' do
71
+ context "#to_s" do
74
72
  before do
75
73
  I18n.locale = :en
76
74
  end
77
75
 
78
- it 'handles singluar' do
76
+ it "handles singluar" do
79
77
  distance = M9t::Distance.new(1)
80
- expect(distance.to_s(precision: 0)).to eq('1 meter')
78
+ expect(distance.to_s(precision: 0)).to eq("1 meter")
81
79
  end
82
80
 
83
- it 'handles plural' do
81
+ it "handles plural" do
84
82
  distance = M9t::Distance.new(10)
85
- expect(distance.to_s(precision: 0)).to eq('10 meters')
83
+ expect(distance.to_s(precision: 0)).to eq("10 meters")
86
84
  end
87
85
 
88
- it 'handles abbreviation' do
86
+ it "handles abbreviation" do
89
87
  distance = M9t::Distance.new(0.3)
90
- expect(distance.to_s(abbreviated: true)).to eq('0.30000m')
88
+ expect(distance.to_s(abbreviated: true)).to eq("0.30000m")
91
89
  end
92
90
 
93
- specify 'units: kilometers' do
91
+ specify "units: kilometers" do
94
92
  distance = M9t::Distance.new( 156003 )
95
- expect(distance.to_s(precision: 1, units: :kilometers)).to eq('156.0 kilometers')
93
+ expect(distance.to_s(precision: 1, units: :kilometers)).to eq("156.0 kilometers")
96
94
  end
97
95
 
98
- specify 'units: miles, singular' do
96
+ specify "units: miles, singular" do
99
97
  marathon = M9t::Distance.miles(26.21875)
100
- expect(marathon.to_s(units: :miles, precision: 0)).to eq('26 miles')
98
+ expect(marathon.to_s(units: :miles, precision: 0)).to eq("26 miles")
101
99
  end
102
100
 
103
- specify 'units: miles, plural' do
101
+ specify "units: miles, plural" do
104
102
  ten_km = M9t::Distance.new(10000)
105
- expect(ten_km.to_s(units: :miles, precision: 1)).to eq('6.2 miles')
103
+ expect(ten_km.to_s(units: :miles, precision: 1)).to eq("6.2 miles")
106
104
  end
107
105
 
108
- context 'i18n' do
106
+ context "i18n" do
109
107
  before do
110
108
  I18n.locale = :it
111
109
  end
112
110
 
113
- specify 'precision: 0' do
111
+ specify "precision: 0" do
114
112
  distance = M9t::Distance.new(10)
115
- expect(distance.to_s(precision: 0)).to eq('10 metri')
113
+ expect(distance.to_s(precision: 0)).to eq("10 metri")
116
114
  end
117
115
 
118
- specify 'units: miles' do
116
+ specify "units: miles" do
119
117
  marathon = M9t::Distance.miles(26.21875)
120
- expect(marathon.to_s(units: :miles, precision: 0)).to eq('26 miglia')
118
+ expect(marathon.to_s(units: :miles, precision: 0)).to eq("26 miglia")
121
119
  end
122
120
 
123
- specify 'units: miles, precision: 1' do
121
+ specify "units: miles, precision: 1" do
124
122
  ten_km = M9t::Distance.new(10000)
125
- expect(ten_km.to_s(units: :miles, precision: 1)).to eq('6,2 miglia')
123
+ expect(ten_km.to_s(units: :miles, precision: 1)).to eq("6,2 miglia")
126
124
  end
127
125
  end
128
126
  end
129
127
  end
130
-
data/spec/i18n_spec.rb CHANGED
@@ -1,6 +1,4 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
- require 'm9t/i18n'
1
+ require "m9t/i18n"
4
2
 
5
3
  describe I18n do
6
4
  before do
@@ -11,35 +9,35 @@ describe I18n do
11
9
  I18n.locale = @old_locale
12
10
  end
13
11
 
14
- context 'languages' do
12
+ context "languages" do
15
13
  [
16
- [:en, 'mile'],
17
- [:it, 'miglio'],
18
- [:de, 'Meile'],
14
+ [:en, "mile"],
15
+ [:it, "miglio"],
16
+ [:de, "Meile"],
19
17
  ].each do |locale, expected|
20
18
  it "has #{locale}" do
21
19
  I18n.locale = locale
22
- expect(I18n.t('units.distance.miles.full.one')).to eq(expected)
20
+ expect(I18n.t("units.distance.miles.full.one")).to eq(expected)
23
21
  end
24
22
  end
25
23
  end
26
24
 
27
- context 'decimal separator' do
25
+ context "decimal separator" do
28
26
  [
29
- [:en, '.'],
30
- [:it, ','],
27
+ [:en, "."],
28
+ [:it, ","],
31
29
  ].each do |locale, separator|
32
30
  it "has #{separator} for #{locale}" do
33
31
  I18n.locale = locale
34
- expect(I18n.t('numbers.decimal_separator')).to eq(separator)
32
+ expect(I18n.t("numbers.decimal_separator")).to eq(separator)
35
33
  end
36
34
  end
37
35
  end
38
36
 
39
- context '.localize_float' do
37
+ context ".localize_float" do
40
38
  [
41
- [:en, '.'],
42
- [:it, ','],
39
+ [:en, "."],
40
+ [:it, ","],
43
41
  ].each do |locale, separator|
44
42
  it "uses the #{separator} separator in #{locale}" do
45
43
  I18n.locale = locale
@@ -48,10 +46,9 @@ describe I18n do
48
46
  end
49
47
  end
50
48
 
51
- it 'accepts a format indicator' do
49
+ it "accepts a format indicator" do
52
50
  I18n.locale = :en
53
- expect(I18n.localize_float(1.5, {format: '%0.1f'})).to eq('1.5')
51
+ expect(I18n.localize_float(1.5, {format: "%0.1f"})).to eq("1.5")
54
52
  end
55
53
  end
56
54
  end
57
-
@@ -1,16 +1,14 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
- require 'm9t/pressure'
1
+ require "m9t/pressure"
4
2
 
5
3
  describe M9t::Pressure do
6
- context 'class methods' do
7
- context '.new' do
8
- it 'returns the identity' do
4
+ context "class methods" do
5
+ context ".new" do
6
+ it "returns the identity" do
9
7
  expect(M9t::Pressure.new(1.0).value).to eq(1.0)
10
8
  end
11
9
  end
12
10
 
13
- context 'other units' do
11
+ context "other units" do
14
12
  [
15
13
  [:hectopascals, 0.001],
16
14
  [:inches_of_mercury, 0.03386],
@@ -22,4 +20,3 @@ describe M9t::Pressure do
22
20
  end
23
21
  end
24
22
  end
25
-
data/spec/spec_helper.rb CHANGED
@@ -1,20 +1,20 @@
1
1
  require "codeclimate-test-reporter"
2
- require 'rspec'
2
+ require "rspec"
3
3
 
4
4
  CodeClimate::TestReporter.start
5
5
 
6
- if RUBY_PLATFORM != 'java'
7
- require 'simplecov'
6
+ if RUBY_PLATFORM != "java"
7
+ require "simplecov"
8
8
  SimpleCov.start do
9
- add_filter '/spec/'
9
+ add_filter "/spec/"
10
10
  end
11
11
  end
12
12
 
13
- require 'm9t'
13
+ require "m9t"
14
14
 
15
15
  RSpec.configure do |config|
16
16
  config.run_all_when_everything_filtered = true
17
17
  config.filter_run :focus
18
18
 
19
- config.order = 'random'
19
+ config.order = "random"
20
20
  end
data/spec/speed_spec.rb CHANGED
@@ -1,16 +1,14 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
- require 'm9t/speed'
1
+ require "m9t/speed"
4
2
 
5
3
  describe M9t::Speed do
6
- context 'conversion constants' do
7
- it 'has knots' do
4
+ context "conversion constants" do
5
+ it "has knots" do
8
6
  expect(M9t::Speed::KNOTS).to be_within(0.0001).of(1.9438)
9
7
  end
10
8
  end
11
9
 
12
- context 'known units' do
13
- it 'gives an error for unknown units' do
10
+ context "known units" do
11
+ it "gives an error for unknown units" do
14
12
  speed = M9t::Speed.new(10)
15
13
  expect {
16
14
  speed.to_s(units: :foos)
@@ -18,20 +16,20 @@ describe M9t::Speed do
18
16
  end
19
17
  end
20
18
 
21
- context 'class methods' do
22
- context '.new' do
23
- it 'handles identity' do
19
+ context "class methods" do
20
+ context ".new" do
21
+ it "handles identity" do
24
22
  expect(M9t::Speed.new(45).value).to eq(45)
25
23
  end
26
24
  end
27
25
 
28
- context '.measurement_name' do
26
+ context ".measurement_name" do
29
27
  it "is 'speed'" do
30
- expect(M9t::Speed.measurement_name).to eq('speed')
28
+ expect(M9t::Speed.measurement_name).to eq("speed")
31
29
  end
32
30
  end
33
31
 
34
- context 'conversion factories' do
32
+ context "conversion factories" do
35
33
  [
36
34
  [:kilometers_per_hour, 0.2778],
37
35
  [:miles_per_hour, 0.447],
@@ -43,7 +41,7 @@ describe M9t::Speed do
43
41
  end
44
42
  end
45
43
 
46
- context 'conversions' do
44
+ context "conversions" do
47
45
  [
48
46
  [:meters_per_second, :miles_per_hour, 45.0, 100.6621],
49
47
  ].each do |from, to, input, expected|
@@ -55,7 +53,7 @@ describe M9t::Speed do
55
53
  end
56
54
  end
57
55
 
58
- context 'conversions' do
56
+ context "conversions" do
59
57
  subject { M9t::Speed.new(45) }
60
58
 
61
59
  [
@@ -69,37 +67,36 @@ describe M9t::Speed do
69
67
  end
70
68
  end
71
69
 
72
- context '#to_s' do
70
+ context "#to_s" do
73
71
  subject { M9t::Speed.new(135.0) }
74
72
 
75
- specify 'full en' do
73
+ specify "full en" do
76
74
  I18n.locale = :en
77
- expect(subject.to_s).to eq('135.00000 meters per second')
75
+ expect(subject.to_s).to eq("135.00000 meters per second")
78
76
  end
79
77
 
80
- specify 'full it' do
78
+ specify "full it" do
81
79
  I18n.locale = :it
82
- expect(subject.to_s).to eq('135,00000 metri al second')
80
+ expect(subject.to_s).to eq("135,00000 metri al second")
83
81
  end
84
82
 
85
- specify 'precision' do
83
+ specify "precision" do
86
84
  I18n.locale = :en
87
- expect(subject.to_s(precision: 0)).to eq('135 meters per second')
85
+ expect(subject.to_s(precision: 0)).to eq("135 meters per second")
88
86
  end
89
87
 
90
- specify 'abbreviated' do
91
- expect(subject.to_s(abbreviated: true, precision: 0)).to eq('135m/s')
88
+ specify "abbreviated" do
89
+ expect(subject.to_s(abbreviated: true, precision: 0)).to eq("135m/s")
92
90
  end
93
91
 
94
- specify 'units: knots, en' do
92
+ specify "units: knots, en" do
95
93
  I18n.locale = :en
96
- expect(subject.to_s(units: :knots, precision: 0)).to eq('262 knots')
94
+ expect(subject.to_s(units: :knots, precision: 0)).to eq("262 knots")
97
95
  end
98
96
 
99
- specify 'units: knots, it' do
97
+ specify "units: knots, it" do
100
98
  I18n.locale = :it
101
- expect(subject.to_s(units: :knots, precision: 0)).to eq('262 nodi')
99
+ expect(subject.to_s(units: :knots, precision: 0)).to eq("262 nodi")
102
100
  end
103
101
  end
104
102
  end
105
-
@@ -1,6 +1,4 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
- require 'm9t/temperature'
1
+ require "m9t/temperature"
4
2
 
5
3
  describe M9t::Temperature do
6
4
  CONVERSIONS = [
@@ -8,36 +6,36 @@ describe M9t::Temperature do
8
6
  [:fahrenheit, 100, 212.0],
9
7
  ]
10
8
 
11
- context 'constants' do
12
- specify 'absolute zero' do
9
+ context "constants" do
10
+ specify "absolute zero" do
13
11
  expect(M9t::Temperature::ABSOLUTE_ZERO).to be_within(0.0001).of(-273.15)
14
12
  end
15
13
  end
16
14
 
17
- context 'default options' do
18
- specify 'units: meters' do
15
+ context "default options" do
16
+ specify "units: meters" do
19
17
  expect(M9t::Temperature.options[:units]).to eq(:degrees)
20
18
  end
21
19
 
22
- specify 'precision: 5' do
20
+ specify "precision: 5" do
23
21
  expect(M9t::Temperature.options[:precision]).to eq(5)
24
22
  end
25
23
  end
26
24
 
27
- context 'class methods' do
28
- context '.new' do
29
- it 'handles identity' do
25
+ context "class methods" do
26
+ context ".new" do
27
+ it "handles identity" do
30
28
  expect(M9t::Temperature.new(45.0).value).to eq(45.0)
31
29
  end
32
30
  end
33
31
 
34
- context '.measurement_name' do
32
+ context ".measurement_name" do
35
33
  it "is 'temperature'" do
36
- expect(M9t::Temperature.measurement_name).to eq('temperature')
34
+ expect(M9t::Temperature.measurement_name).to eq("temperature")
37
35
  end
38
36
  end
39
37
 
40
- context 'conversion factories' do
38
+ context "conversion factories" do
41
39
  CONVERSIONS.each do |unit, degrees, other|
42
40
  specify ".#{unit}" do
43
41
  expect(M9t::Temperature.send(unit, other).value).
@@ -46,8 +44,8 @@ describe M9t::Temperature do
46
44
  end
47
45
  end
48
46
 
49
- context 'conversions' do
50
- context 'from degrees' do
47
+ context "conversions" do
48
+ context "from degrees" do
51
49
  CONVERSIONS.each do |unit, degrees, other|
52
50
  method = :"to_#{unit}"
53
51
  specify method do
@@ -56,7 +54,7 @@ describe M9t::Temperature do
56
54
  end
57
55
  end
58
56
 
59
- context 'to degrees' do
57
+ context "to degrees" do
60
58
  CONVERSIONS.each do |unit, degrees, other|
61
59
  method = :"#{unit}_to_degrees"
62
60
  specify method do
@@ -67,8 +65,8 @@ describe M9t::Temperature do
67
65
  end
68
66
  end
69
67
 
70
- context 'conversions' do
71
- context 'from degrees' do
68
+ context "conversions" do
69
+ context "from degrees" do
72
70
  CONVERSIONS.each do |unit, degrees, other|
73
71
  subject { M9t::Temperature.new(degrees) }
74
72
 
@@ -80,48 +78,47 @@ describe M9t::Temperature do
80
78
  end
81
79
  end
82
80
 
83
- context '#to_s' do
81
+ context "#to_s" do
84
82
  subject { M9t::Temperature.new(135) }
85
83
 
86
- specify 'en' do
84
+ specify "en" do
87
85
  I18n.locale = :en
88
- expect(subject.to_s).to eq('135.00000 degrees')
86
+ expect(subject.to_s).to eq("135.00000 degrees")
89
87
  end
90
88
 
91
- specify 'it' do
89
+ specify "it" do
92
90
  I18n.locale = :it
93
- expect(subject.to_s).to eq('135,00000 gradi')
91
+ expect(subject.to_s).to eq("135,00000 gradi")
94
92
  end
95
93
 
96
- specify 'precision' do
94
+ specify "precision" do
97
95
  I18n.locale = :en
98
- expect(subject.to_s(precision: 0)).to eq('135 degrees')
96
+ expect(subject.to_s(precision: 0)).to eq("135 degrees")
99
97
  end
100
98
 
101
- specify 'abbreviated, en' do
99
+ specify "abbreviated, en" do
102
100
  I18n.locale = :en
103
101
  expect(subject.to_s(abbreviated: true, precision: 0)).
104
- to eq('135°C')
102
+ to eq("135°C")
105
103
  end
106
104
 
107
- specify 'kelvin, en' do
105
+ specify "kelvin, en" do
108
106
  I18n.locale = :en
109
107
  expect(subject.to_s(units: :kelvin, precision: 2)).
110
- to eq('408.15 kelvin')
108
+ to eq("408.15 kelvin")
111
109
  end
112
110
 
113
- specify 'kelvin, it' do
111
+ specify "kelvin, it" do
114
112
  I18n.locale = :it
115
113
  expect(subject.to_s(units: :kelvin, precision: 2)).
116
- to eq('408,15 kelvin')
114
+ to eq("408,15 kelvin")
117
115
  end
118
116
 
119
- specify 'abbreviated, kelvin, it' do
117
+ specify "abbreviated, kelvin, it" do
120
118
  I18n.locale = :it
121
119
  expect(
122
120
  subject.to_s(units: :kelvin, abbreviated: true, precision: 2)
123
- ).to eq('408,15K')
121
+ ).to eq("408,15K")
124
122
  end
125
123
  end
126
124
  end
127
-