ruby-measurement 1.2.2 → 1.2.3

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.
@@ -2,33 +2,33 @@ require 'spec_helper'
2
2
 
3
3
  RSpec.describe Measurement::Unit::Builder do
4
4
  subject { described_class.new(name, &block) }
5
-
5
+
6
6
  let(:name) { :hour }
7
7
  let(:block) { proc {} }
8
-
8
+
9
9
  describe '.new' do
10
10
  describe 'with a block' do
11
11
  let(:block) do
12
12
  proc { |unit| unit.alias :hr, :hrs }
13
13
  end
14
-
14
+
15
15
  it 'should evaluate the block' do
16
16
  unit = subject.to_unit
17
17
  expect(unit.aliases).to include 'hr'
18
18
  expect(unit.aliases).to include 'hrs'
19
19
  end
20
20
  end
21
-
21
+
22
22
  describe 'without a block' do
23
23
  let(:block) { nil }
24
-
24
+
25
25
  it 'should not evaluate the block' do
26
26
  unit = subject.to_unit
27
27
  expect(unit.aliases).to_not include 'hr'
28
28
  end
29
29
  end
30
30
  end
31
-
31
+
32
32
  describe '#to_unit' do
33
33
  it 'should return a matching unit' do
34
34
  expect(subject.to_unit).to be_a Measurement::Unit
@@ -36,13 +36,13 @@ RSpec.describe Measurement::Unit::Builder do
36
36
  expect(subject.to_unit.aliases).to eq %w(hour).to_set
37
37
  end
38
38
  end
39
-
39
+
40
40
  describe '#alias' do
41
41
  describe 'with a new alias' do
42
42
  before do
43
43
  expect(subject.to_unit.aliases).to_not include 'hr'
44
44
  end
45
-
45
+
46
46
  it 'should append the new alias' do
47
47
  aliases = subject.to_unit.aliases.dup
48
48
  subject.alias :hr
@@ -50,19 +50,19 @@ RSpec.describe Measurement::Unit::Builder do
50
50
  expect(subject.to_unit.aliases).to include 'hr'
51
51
  end
52
52
  end
53
-
53
+
54
54
  describe 'with multiple new aliases' do
55
55
  before do
56
56
  expect(subject.to_unit.aliases).to_not include 'hr'
57
57
  expect(subject.to_unit.aliases).to_not include 'hrs'
58
58
  end
59
59
  end
60
-
60
+
61
61
  describe 'with an existing alias' do
62
62
  before do
63
63
  subject.alias :hour
64
64
  end
65
-
65
+
66
66
  it 'should not affect the list of aliases' do
67
67
  aliases = subject.to_unit.aliases.dup
68
68
  subject.alias :hour
@@ -70,13 +70,13 @@ RSpec.describe Measurement::Unit::Builder do
70
70
  end
71
71
  end
72
72
  end
73
-
73
+
74
74
  describe '#convert_to' do
75
75
  describe 'with a new target alias' do
76
76
  before do
77
77
  expect(subject.to_unit.conversions['min']).to be_nil
78
78
  end
79
-
79
+
80
80
  it 'should add the conversion' do
81
81
  conversion = proc { |value| value * 60.0 }
82
82
  expect(subject.to_unit.aliases).to_not include 'hr'
@@ -84,13 +84,13 @@ RSpec.describe Measurement::Unit::Builder do
84
84
  expect(subject.to_unit.conversions['min']).to eq conversion
85
85
  end
86
86
  end
87
-
87
+
88
88
  describe 'with an existing target alias' do
89
89
  before do
90
90
  subject.convert_to(:min) { |value| value + 3 }
91
91
  expect(subject.to_unit.conversions['min']).to_not be_nil
92
92
  end
93
-
93
+
94
94
  it 'should replace the conversion' do
95
95
  conversion = proc { |value| value * 60.0 }
96
96
  expect(subject.to_unit.aliases).to_not include 'hr'
@@ -2,85 +2,85 @@ require 'spec_helper'
2
2
 
3
3
  RSpec.describe Measurement::Unit do
4
4
  subject { described_class.new(name) }
5
-
5
+
6
6
  let(:name) { :hour }
7
-
7
+
8
8
  describe '#name' do
9
9
  it 'returns the name' do
10
10
  expect(subject.name).to eq 'hour'
11
11
  end
12
12
  end
13
-
13
+
14
14
  describe '#add_alias' do
15
15
  it 'adds new aliases' do
16
16
  subject.add_alias :hr, :hrs
17
17
  expect(subject.aliases).to eq %w(hour hr hrs).to_set
18
18
  end
19
-
19
+
20
20
  it 'does not add aliases that already exist' do
21
21
  subject.add_alias :hr, :hrs
22
22
  expect { subject.add_alias :hr, :hrs }.to_not raise_error
23
23
  expect(subject.aliases).to eq %w(hour hr hrs).to_set
24
24
  end
25
25
  end
26
-
26
+
27
27
  describe '#add_conversion' do
28
28
  before do
29
29
  subject.add_conversion(:sec) { |value| value * 3600.0 }
30
30
  end
31
-
31
+
32
32
  it 'adds new conversions' do
33
33
  conversion = proc { |value| value * 60.0 }
34
34
  subject.add_conversion(:min, &conversion)
35
35
  expect(subject.conversions['min']).to be conversion
36
36
  end
37
-
37
+
38
38
  it 'replaces existing conversions' do
39
39
  conversion = proc { |value| value * 60.0 }
40
40
  subject.add_conversion(:sec, &conversion)
41
41
  expect(subject.conversions['sec']).to be conversion
42
42
  end
43
43
  end
44
-
44
+
45
45
  describe '#aliases' do
46
46
  it 'returns the set of aliases' do
47
47
  expect(subject.aliases).to eq %w(hour).to_set
48
48
  end
49
49
  end
50
-
50
+
51
51
  describe '#conversion' do
52
52
  before do
53
53
  described_class.define(:min)
54
54
  subject.add_conversion(:min) { |value| value * 60.0 }
55
55
  end
56
-
56
+
57
57
  it 'returns conversion if it exists' do
58
58
  expect(subject.conversion(:min)).to_not be_nil
59
59
  end
60
-
60
+
61
61
  it 'returns nil if it does not exist' do
62
62
  expect(subject.conversion(:sec)).to be_nil
63
63
  end
64
64
  end
65
-
65
+
66
66
  describe '#inspect' do
67
67
  it 'returns name' do
68
68
  expect(subject.inspect).to eq subject.name
69
69
  end
70
70
  end
71
-
71
+
72
72
  describe '#to_s' do
73
73
  it 'returns name' do
74
74
  expect(subject.inspect).to eq subject.name
75
75
  end
76
76
  end
77
-
77
+
78
78
  describe '#==' do
79
79
  before do
80
80
  subject.add_alias(:hours, :hr, :hrs)
81
81
  subject.add_conversion(:min) { |value| value * 60.0 }
82
82
  end
83
-
83
+
84
84
  describe 'other object is a Unit' do
85
85
  it 'returns true when name, aliases, and conversions match' do
86
86
  other = described_class.new(:hour)
@@ -88,21 +88,21 @@ RSpec.describe Measurement::Unit do
88
88
  other.add_conversion(:min) { |value| value * 60.0 }
89
89
  expect(subject == other).to be true
90
90
  end
91
-
91
+
92
92
  it "returns false when the name doesn't match" do
93
93
  other = described_class.new(:hoooour)
94
94
  other.add_alias(:hours, :hr, :hrs)
95
95
  other.add_conversion(:min) { |value| value * 60.0 }
96
96
  expect(subject == other).to be false
97
97
  end
98
-
98
+
99
99
  it "returns false when the aliases don't match" do
100
100
  other = described_class.new(:hour)
101
101
  other.add_alias(:hoooours, :hr, :hrs)
102
102
  other.add_conversion(:min) { |value| value * 60.0 }
103
103
  expect(subject == other).to be false
104
104
  end
105
-
105
+
106
106
  it "returns false when the conversions don't match" do
107
107
  other = described_class.new(:hour)
108
108
  other.add_alias(:hours, :hr, :hrs)
@@ -110,41 +110,41 @@ RSpec.describe Measurement::Unit do
110
110
  expect(subject == other).to be false
111
111
  end
112
112
  end
113
-
113
+
114
114
  describe 'other object is not a Unit' do
115
115
  it 'returns false' do
116
116
  expect(subject == :hour).to be false
117
117
  end
118
118
  end
119
119
  end
120
-
120
+
121
121
  describe '.names' do
122
122
  subject { described_class }
123
-
123
+
124
124
  it 'returns all defined unit names' do
125
125
  unit_names = subject.names
126
126
  expect(unit_names).to be_an Array
127
127
  expect(unit_names).to include 'count'
128
128
  end
129
129
  end
130
-
130
+
131
131
  describe '.define' do
132
132
  subject { described_class }
133
-
133
+
134
134
  it 'returns a unit builder' do
135
135
  builder = subject.define(:count)
136
136
  expect(builder).to be_a Measurement::Unit::Builder
137
137
  end
138
-
138
+
139
139
  it 'accepts a block' do
140
140
  builder = subject.define(:count) { |b| b.alias :ct }
141
141
  expect(builder).to be_a Measurement::Unit::Builder
142
142
  end
143
143
  end
144
-
144
+
145
145
  describe '.[]' do
146
146
  subject { described_class }
147
-
147
+
148
148
  describe 'for a unit name that is defined' do
149
149
  it 'returns the unit' do
150
150
  unit = subject[:dozen]
@@ -153,7 +153,7 @@ RSpec.describe Measurement::Unit do
153
153
  expect(unit.aliases).to eq %w(doz dozen).to_set
154
154
  end
155
155
  end
156
-
156
+
157
157
  describe 'for a unit name that is not defined' do
158
158
  it 'returns nil' do
159
159
  expect(subject[:potato]).to be nil
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-measurement
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Huggins
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-14 00:00:00.000000000 Z
11
+ date: 2016-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -112,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
112
  version: '0'
113
113
  requirements: []
114
114
  rubyforge_project:
115
- rubygems_version: 2.2.2
115
+ rubygems_version: 2.5.1
116
116
  signing_key:
117
117
  specification_version: 4
118
118
  summary: Simple gem for calculating and converting measurements