midwire_common 1.1.0 → 2.0.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 (48) hide show
  1. checksums.yaml +5 -5
  2. data/.github/mergeable.yml +43 -0
  3. data/.gitignore +23 -0
  4. data/.ruby-version +1 -1
  5. data/CHANGELOG +4 -0
  6. data/CLAUDE.md +95 -0
  7. data/Gemfile +2 -0
  8. data/README.md +8 -5
  9. data/Rakefile +3 -1
  10. data/docs/plans/2026-02-13-refinements-implementation.md +1494 -0
  11. data/docs/plans/2026-02-13-refinements-modernization-design.md +109 -0
  12. data/lib/midwire_common/all.rb +16 -1
  13. data/lib/midwire_common/array.rb +35 -45
  14. data/lib/midwire_common/data_file_cache.rb +6 -5
  15. data/lib/midwire_common/enumerable.rb +12 -8
  16. data/lib/midwire_common/file.rb +13 -1
  17. data/lib/midwire_common/float.rb +10 -3
  18. data/lib/midwire_common/hash.rb +94 -105
  19. data/lib/midwire_common/integer.rb +11 -0
  20. data/lib/midwire_common/number_behavior.rb +4 -2
  21. data/lib/midwire_common/rake_helper.rb +5 -3
  22. data/lib/midwire_common/rake_tasks.rb +2 -0
  23. data/lib/midwire_common/string.rb +76 -108
  24. data/lib/midwire_common/time.rb +10 -6
  25. data/lib/midwire_common/time_tool.rb +6 -2
  26. data/lib/midwire_common/version.rb +3 -1
  27. data/lib/midwire_common/yaml_setting.rb +4 -3
  28. data/lib/midwire_common.rb +8 -2
  29. data/lib/tasks/version.rake +21 -18
  30. data/midwire_common.gemspec +10 -13
  31. data/spec/lib/midwire_common/array_spec.rb +23 -23
  32. data/spec/lib/midwire_common/data_file_cache_spec.rb +14 -14
  33. data/spec/lib/midwire_common/enumerable_spec.rb +8 -4
  34. data/spec/lib/midwire_common/file/stat_spec.rb +8 -4
  35. data/spec/lib/midwire_common/float_spec.rb +7 -3
  36. data/spec/lib/midwire_common/hash_spec.rb +55 -24
  37. data/spec/lib/midwire_common/integer_spec.rb +11 -0
  38. data/spec/lib/midwire_common/rake_helper_spec.rb +6 -3
  39. data/spec/lib/midwire_common/string_spec.rb +47 -77
  40. data/spec/lib/midwire_common/time_spec.rb +19 -20
  41. data/spec/lib/midwire_common/time_tool_spec.rb +4 -2
  42. data/spec/lib/midwire_common/yaml_setting_spec.rb +8 -5
  43. data/spec/spec_helper.rb +18 -12
  44. metadata +29 -99
  45. data/Guardfile +0 -14
  46. data/lib/midwire_common/file/stat.rb +0 -11
  47. data/lib/midwire_common/fixnum.rb +0 -4
  48. data/spec/lib/midwire_common/fixnum_spec.rb +0 -15
@@ -1,54 +1,58 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
- describe BottomlessHash do
4
- subject { described_class.new }
5
+ using MidwireCommon::HashExtensions
6
+
7
+ RSpec.describe MidwireCommon::BottomlessHash do # rubocop:disable RSpec/MultipleDescribes
8
+ subject(:bottomless_hash) { described_class.new }
5
9
 
6
10
  it 'does not raise on missing key' do
7
11
  expect do
8
- subject[:missing][:key]
9
- end.to_not raise_error
12
+ bottomless_hash[:missing][:key]
13
+ end.not_to raise_error
10
14
  end
11
15
 
12
16
  it 'returns an empty value on missing key' do
13
- expect(subject[:missing][:key]).to be_empty
17
+ expect(bottomless_hash[:missing][:key]).to be_empty
14
18
  end
15
19
 
16
20
  it 'stores and returns keys' do
17
- subject[:existing][:key] = :value
18
- expect(subject[:existing][:key]).to eq(:value)
21
+ bottomless_hash[:existing][:key] = :value
22
+ expect(bottomless_hash[:existing][:key]).to eq(:value)
19
23
  end
20
24
 
21
- context '#from_hash' do
22
- let(:hash) do
23
- { existing: { key: { value: :hello } } }
25
+ describe '#from_hash' do
26
+ subject(:bottomless_hash) do
27
+ described_class.from_hash(hash)
24
28
  end
25
29
 
26
- subject do
27
- described_class.from_hash(hash)
30
+ let(:hash) do
31
+ { existing: { key: { value: :hello } } }
28
32
  end
29
33
 
30
34
  it 'returns old hash values' do
31
- expect(subject[:existing][:key][:value]).to eq(:hello)
35
+ expect(bottomless_hash[:existing][:key][:value]).to eq(:hello)
32
36
  end
33
37
 
34
38
  it 'provides a bottomless version' do
35
- expect(subject[:missing][:key]).to be_empty
39
+ expect(bottomless_hash[:missing][:key]).to be_empty
36
40
  end
37
41
 
38
42
  it 'stores and returns new values' do
39
- subject[:existing][:key] = :value
40
- expect(subject[:existing][:key]).to eq(:value)
43
+ bottomless_hash[:existing][:key] = :value
44
+ expect(bottomless_hash[:existing][:key]).to eq(:value)
41
45
  end
42
46
 
43
47
  it 'converts nested hashes as well' do
44
48
  expect do
45
- subject[:existing][:key][:missing]
46
- end.to_not raise_error
49
+ bottomless_hash[:existing][:key][:missing]
50
+ end.not_to raise_error
47
51
  end
48
52
  end
49
53
  end
50
54
 
51
- describe Hash do
55
+ RSpec.describe Hash do
52
56
  it 'greps key/value pairs using a regular expression' do
53
57
  h = { a: 'this is a test', 'b' => 'this is not the answer' }
54
58
  expect(h.grep(/a test/)).to eq([[:a, 'this is a test']])
@@ -58,10 +62,6 @@ describe Hash do
58
62
  ).to eq([[:a, 'this is a test'], ['b', 'this is not the answer']])
59
63
  end
60
64
 
61
- it 'returns elements with certain keys filtered out' do
62
- expect({ a: 1, b: 2, c: 3 }.except(:a)).to eq(b: 2, c: 3)
63
- end
64
-
65
65
  it 'returns elements for discretely passed keys' do
66
66
  expect({ a: 1, b: 2, c: 3 }.only(:a)).to eq(a: 1)
67
67
  end
@@ -112,7 +112,7 @@ describe Hash do
112
112
  let(:h1_values) { { 'a' => 1, 'b' => 2, 'c' => 3 } }
113
113
  let(:h2_values) { { 'a' => 1, 'b' => 2, 'c' => 4 } }
114
114
 
115
- context '.diff' do
115
+ describe '.diff' do
116
116
  it 'reports different keys' do
117
117
  expect(h1_keys.diff(h2_keys)).to eq('c' => [3, nil], 'd' => [nil, 3])
118
118
  end
@@ -127,5 +127,36 @@ describe Hash do
127
127
  )
128
128
  end
129
129
  end
130
+
131
+ describe '.apply_diff!' do
132
+ it 'applies diff to the right by default' do
133
+ diff = h1_values.diff(h2_values)
134
+ result = h1_values.apply_diff!(diff)
135
+ expect(result).to eq('a' => 1, 'b' => 2, 'c' => 4)
136
+ expect(h1_values).to eq('a' => 1, 'b' => 2, 'c' => 4)
137
+ end
138
+
139
+ it 'applies diff to the left' do
140
+ diff = h1_values.diff(h2_values)
141
+ result = h2_values.apply_diff!(diff, :left)
142
+ expect(result).to eq('a' => 1, 'b' => 2, 'c' => 3)
143
+ end
144
+ end
145
+
146
+ describe '.apply_diff' do
147
+ it 'returns a new hash with diff applied' do
148
+ diff = h1_values.diff(h2_values)
149
+ result = h1_values.apply_diff(diff)
150
+ expect(result).to eq('a' => 1, 'b' => 2, 'c' => 4)
151
+ expect(h1_values).to eq('a' => 1, 'b' => 2, 'c' => 3)
152
+ end
153
+
154
+ it 'applies diff to the left' do
155
+ diff = h1_values.diff(h2_values)
156
+ result = h2_values.apply_diff(diff, :left)
157
+ expect(result).to eq('a' => 1, 'b' => 2, 'c' => 3)
158
+ expect(h2_values).to eq('a' => 1, 'b' => 2, 'c' => 4)
159
+ end
160
+ end
130
161
  end
131
162
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ using MidwireCommon::IntegerExtensions
6
+
7
+ RSpec.describe Integer do
8
+ it 'can format itself with commas' do
9
+ expect(8_729_928_827.commify).to eq('8,729,928,827')
10
+ end
11
+ end
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module MidwireCommon
4
6
  RSpec.describe RakeHelper do
5
7
  let(:rake_helper) { described_class.new(Dir.pwd) }
6
8
 
7
- context '#new' do
9
+ describe '#new' do
8
10
  it 'returns an instance' do
9
11
  expect(rake_helper).to be_a(described_class)
10
12
  end
@@ -14,7 +16,7 @@ module MidwireCommon
14
16
  end
15
17
  end
16
18
 
17
- context '.install' do
19
+ describe '.install' do
18
20
  it 'returns version.rake' do
19
21
  file = rake_helper.install.first
20
22
  expect(File.basename(file)).to eq('version.rake')
@@ -22,8 +24,9 @@ module MidwireCommon
22
24
 
23
25
  it 'loads version.rake' do
24
26
  file = File.join(MidwireCommon.root, 'lib/tasks/version.rake')
25
- expect(rake_helper).to receive(:load).with(file)
27
+ allow(rake_helper).to receive(:load)
26
28
  rake_helper.install
29
+ expect(rake_helper).to have_received(:load).with(file)
27
30
  end
28
31
  end
29
32
  end
@@ -1,56 +1,26 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
- # rubocop:disable Metrics/LineLength
4
3
  require 'spec_helper'
5
4
 
5
+ using MidwireCommon::StringExtensions
6
+
6
7
  RSpec.describe String do
7
8
  it 'is a String' do
8
- ''.should be_a String
9
+ string = described_class.new
10
+ expect(string).to be_a described_class
9
11
  end
10
12
 
11
13
  it 'generates a random string' do
12
- String.random.length.should == 6
14
+ expect(described_class.random.length).to eq(6)
13
15
  end
14
16
 
15
17
  context 'slicing methods' do
16
18
  it "'left' returns the leftmost 'n' characters" do
17
- 'My Bogus String'.left(2).should == 'My'
18
- end
19
-
20
- it "'right' returns the rightmost 'n' characters " do
21
- 'My Bogus String'.right(2).should == 'ng'
22
- end
23
- end
24
-
25
- context 'trim method' do
26
- it "'left_trim' removes all whitespace from the left of the string" do
27
- " \t = this is a string".left_trim.should == '= this is a string'
28
- end
29
-
30
- it "'left_trim!' removes all whitespace from the left of the string" do
31
- mystring = " \t \t a test is coming"
32
- mystring.left_trim!
33
- mystring.should == 'a test is coming'
34
- end
35
-
36
- it "'right_trim' removes all whitespace from the right of the string" do
37
- "= this is a string \t ".right_trim.should == '= this is a string'
38
- end
39
-
40
- it "'right_trim!' removes all whitespace from the right of the string" do
41
- mystring = " \t \t a test is coming \t \t "
42
- mystring.right_trim!
43
- mystring.should == " \t \t a test is coming"
44
- end
45
-
46
- it "'trim' removes whitespace from both sides of the string" do
47
- " \t \t a test is coming \t \t ".trim.should == 'a test is coming'
19
+ expect('My Bogus String'.left_substr(2)).to eq('My')
48
20
  end
49
21
 
50
- it "'trim!' removes whitespace from both sides of the string" do
51
- mystring = " \t \t a test is coming \t \t "
52
- mystring.trim!
53
- mystring.should == 'a test is coming'
22
+ it "'right' returns the rightmost 'n' characters" do
23
+ expect('My Bogus String'.right_substr(2)).to eq('ng')
54
24
  end
55
25
  end
56
26
 
@@ -61,7 +31,7 @@ RSpec.describe String do
61
31
  |<script type="text/javascript">
62
32
  |</script>
63
33
  STOP
64
- html.should == '<!-- Begin: comment --> <script type="text/javascript"> </script>'
34
+ expect(html).to eq('<!-- Begin: comment --> <script type="text/javascript"> </script>')
65
35
  end
66
36
 
67
37
  it 'here_with_pipe - with linefeeds' do
@@ -70,7 +40,7 @@ RSpec.describe String do
70
40
  |<script type="text/javascript">
71
41
  |</script>
72
42
  STOP
73
- html.should == "<!-- Begin: comment -->\n<script type=\"text/javascript\">\n</script>"
43
+ expect(html).to eq("<!-- Begin: comment -->\n<script type=\"text/javascript\">\n</script>")
74
44
  end
75
45
 
76
46
  it 'here_with_pipe - with no space delimeter' do
@@ -79,7 +49,7 @@ RSpec.describe String do
79
49
  |<script type="text/javascript">
80
50
  |</script>
81
51
  STOP
82
- html.should == '<!-- Begin: comment --><script type="text/javascript"></script>'
52
+ expect(html).to eq('<!-- Begin: comment --><script type="text/javascript"></script>')
83
53
  end
84
54
 
85
55
  it 'format_phone returns a formatted phone number string' do
@@ -95,13 +65,14 @@ RSpec.describe String do
95
65
  expect('ßogus'.sanitize).to eq('ogus')
96
66
  expect('<tag>bogus</tag>'.sanitize).to eq('tagbogustag')
97
67
  expect('<tag>.bogus.</tag>'.sanitize).to eq('tag.bogus.tag')
98
- s = '|∫|ß'
68
+ s = +'|∫|ß'
99
69
  s.sanitize!
100
- s.should == ''
70
+ expect(s).to eq('')
101
71
  end
102
72
 
103
73
  it 'shortens itself with elipses at the end' do
104
- s = 'this is my very long string which I will eventually shorten with the enhanced String class that we are now testing.'
74
+ s = 'this is my very long string which I will eventually shorten ' \
75
+ 'with the enhanced String class that we are now testing.'
105
76
  short = s.shorten
106
77
  expect(short).to eq('this is my very long string...')
107
78
  expect(short.length).to eq(30)
@@ -119,58 +90,58 @@ RSpec.describe String do
119
90
 
120
91
  context 'quotes' do
121
92
  it 'escapes single quotes' do
122
- "this is a 'test'".escape_single_quotes.should == "this is a \\'test\\'"
93
+ expect("this is a 'test'".escape_single_quotes).to eq("this is a \\'test\\'")
123
94
  end
124
95
 
125
96
  it 'escapes double quotes' do
126
97
  expect('this is a "test"'.escape_double_quotes)
127
- .to eq('this is a \\\\"test\\\\"')
98
+ .to eq('this is a \\\\"test\\\\"')
128
99
  end
129
100
  end
130
101
  end
131
102
 
132
103
  context 'characterization' do
133
104
  it 'knows if it is alpha-numeric or not' do
134
- 'abcd-9191'.alpha_numeric?.should eq(false)
135
- 'abcd.9191'.alpha_numeric?.should eq(false)
136
- 'abcd91910'.alpha_numeric?.should eq(true)
137
- 'abcd_9191'.alpha_numeric?.should eq(false)
138
- 'abcd 9191'.alpha_numeric?.should eq(false)
105
+ expect('abcd-9191'.alpha_numeric?).to be(false)
106
+ expect('abcd.9191'.alpha_numeric?).to be(false)
107
+ expect('abcd91910'.alpha_numeric?).to be(true)
108
+ expect('abcd_9191'.alpha_numeric?).to be(false)
109
+ expect('abcd 9191'.alpha_numeric?).to be(false)
139
110
  end
140
111
 
141
112
  it 'knows if it is an email address or not' do
142
- 'abcd_9191'.email_address?.should eq(false)
143
- 'abcd@9191'.email_address?.should eq(false)
144
- 'abcd@9191.info'.email_address?.should eq(true)
145
- 'abcd-asdf@9191.com'.email_address?.should eq(true)
146
- 'abcd_asdf@9191.com'.email_address?.should eq(true)
147
- 'abcd.asdf@9191.com'.email_address?.should eq(true)
113
+ expect('abcd_9191'.email_address?).to be(false)
114
+ expect('abcd@9191'.email_address?).to be(false)
115
+ expect('abcd@9191.info'.email_address?).to be(true)
116
+ expect('abcd-asdf@9191.com'.email_address?).to be(true)
117
+ expect('abcd_asdf@9191.com'.email_address?).to be(true)
118
+ expect('abcd.asdf@9191.com'.email_address?).to be(true)
148
119
  end
149
120
 
150
121
  it 'knows if it is a zipcode or not' do
151
- '13922-2356'.zipcode?.should eq(true)
152
- '13922.2343'.zipcode?.should eq(false)
153
- '13922 2342'.zipcode?.should eq(false)
154
- 'ABSSD'.zipcode?.should eq(false)
155
- 'i3323'.zipcode?.should eq(false)
156
- '13922'.zipcode?.should eq(true)
122
+ expect('13922-2356'.zipcode?).to be(true)
123
+ expect('13922.2343'.zipcode?).to be(false)
124
+ expect('13922 2342'.zipcode?).to be(false)
125
+ expect('ABSSD'.zipcode?).to be(false)
126
+ expect('i3323'.zipcode?).to be(false)
127
+ expect('13922'.zipcode?).to be(true)
157
128
  end
158
129
 
159
130
  it 'knows if it is numeric or not' do
160
- '12341'.numeric?.should eq(true)
161
- '12341.23'.numeric?.should eq(true)
162
- '12341.00000000000000023'.numeric?.should eq(true)
163
- '0.12341'.numeric?.should eq(true)
164
- '0x2E'.numeric?.should eq(true)
165
- ' 0.12341'.numeric?.should eq(true)
166
- ' 0.12341 '.numeric?.should eq(true)
167
- '.12341'.numeric?.should eq(true)
168
- ' 12341.'.numeric?.should eq(false)
169
- ' 12341. '.numeric?.should eq(false)
131
+ expect('12341'.numeric?).to be(true)
132
+ expect('12341.23'.numeric?).to be(true)
133
+ expect('12341.00000000000000023'.numeric?).to be(true)
134
+ expect('0.12341'.numeric?).to be(true)
135
+ expect('0x2E'.numeric?).to be(true)
136
+ expect(' 0.12341'.numeric?).to be(true)
137
+ expect(' 0.12341 '.numeric?).to be(true)
138
+ expect('.12341'.numeric?).to be(true)
139
+ expect(' 12341.'.numeric?).to be(true)
140
+ expect(' 12341. '.numeric?).to be(true)
170
141
  end
171
142
  end
172
143
 
173
- context '.snakerize' do
144
+ describe '.snakerize' do
174
145
  it 'changes CamelCased string to snake_cased' do
175
146
  expect('CamelCased'.snakerize).to eq('camel_cased')
176
147
  end
@@ -180,7 +151,7 @@ RSpec.describe String do
180
151
  end
181
152
  end
182
153
 
183
- context '.camelize' do
154
+ describe '.camelize' do
184
155
  it 'changes snake cased string to camelized' do
185
156
  expect('camel_cased'.camelize).to eq('CamelCased')
186
157
  end
@@ -190,4 +161,3 @@ RSpec.describe String do
190
161
  end
191
162
  end
192
163
  end
193
- # rubocop:enable Metrics/LineLength
@@ -1,47 +1,46 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
- describe Time do
5
+ using MidwireCommon::StringExtensions
6
+ using MidwireCommon::TimeExtensions
7
+
8
+ RSpec.describe Time do
4
9
  context 'generates a timestamp' do
5
- it 'appropriate for a filename' do
6
- ts = Time.timestamp
10
+ it 'defaults to nanosecond resolution appropriate for a filename' do
11
+ ts = described_class.timestamp
7
12
  expect(ts.length).to eq(18)
8
- expect(ts.numeric?).to eq(true)
13
+ expect(ts.numeric?).to be(true)
9
14
  end
10
15
 
11
16
  it 'with the only seconds' do
12
- ts = Time.timestamp(0)
17
+ ts = described_class.timestamp(0)
13
18
  expect(ts.length).to eq(14)
14
- expect(ts.numeric?).to eq(true)
15
- end
16
-
17
- it 'defaults to nanosecond resolution' do
18
- ts = Time.timestamp
19
- expect(ts.length).to eq(18)
20
- expect(ts.numeric?).to eq(true)
19
+ expect(ts.numeric?).to be(true)
21
20
  end
22
21
 
23
22
  it 'with the millisecond resolution' do
24
- ts = Time.timestamp(3)
23
+ ts = described_class.timestamp(3)
25
24
  expect(ts.length).to eq(18)
26
- expect(ts.numeric?).to eq(true)
25
+ expect(ts.numeric?).to be(true)
27
26
  end
28
27
 
29
28
  it 'with the microsecond resolution' do
30
- ts = Time.timestamp(6)
29
+ ts = described_class.timestamp(6)
31
30
  expect(ts.length).to eq(21)
32
- expect(ts.numeric?).to eq(true)
31
+ expect(ts.numeric?).to be(true)
33
32
  end
34
33
 
35
34
  it 'with the nanosecond resolution' do
36
- ts = Time.timestamp(9)
35
+ ts = described_class.timestamp(9)
37
36
  expect(ts.length).to eq(24)
38
- expect(ts.numeric?).to eq(true)
37
+ expect(ts.numeric?).to be(true)
39
38
  end
40
39
 
41
40
  it 'with the picosecond resolution' do
42
- ts = Time.timestamp(12)
41
+ ts = described_class.timestamp(12)
43
42
  expect(ts.length).to eq(27)
44
- expect(ts.numeric?).to eq(true)
43
+ expect(ts.numeric?).to be(true)
45
44
  end
46
45
  end
47
46
  end
@@ -1,11 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe MidwireCommon::TimeTool do
4
6
  it 'converts seconds to timestamp' do
5
- MidwireCommon::TimeTool.seconds_to_time(92_353).should == '25:39:13'
7
+ expect(described_class.seconds_to_time(92_353)).to eq('25:39:13')
6
8
  end
7
9
 
8
10
  it 'converts timestamp to seconds' do
9
- MidwireCommon::TimeTool.time_to_seconds('25:39:13').should == 92_353
11
+ expect(described_class.time_to_seconds('25:39:13')).to eq(92_353)
10
12
  end
11
13
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe MidwireCommon::YamlSetting do
@@ -7,6 +9,7 @@ describe MidwireCommon::YamlSetting do
7
9
  let(:setting) { YamlSetting.new(file) }
8
10
 
9
11
  before do
12
+ FileUtils.mkdir_p(tmpdir)
10
13
  FileUtils.touch(file)
11
14
  setting[:test] = {}
12
15
  setting[:test][:a] = 1
@@ -15,13 +18,13 @@ describe MidwireCommon::YamlSetting do
15
18
  setting.save
16
19
  end
17
20
 
18
- context '#new' do
21
+ describe '#new' do
19
22
  it 'sets the :file accessor' do
20
23
  expect(setting.file).to eq(file)
21
24
  end
22
25
  end
23
26
 
24
- context '.load' do
27
+ describe '.load' do
25
28
  it 'returns self' do
26
29
  expect(setting.load).to be_a(YamlSetting)
27
30
  end
@@ -35,7 +38,7 @@ describe MidwireCommon::YamlSetting do
35
38
  end
36
39
  end
37
40
 
38
- context '.save' do
41
+ describe '.save' do
39
42
  it 'stores the current hash' do
40
43
  setting[:test] = 'bogus'
41
44
  setting.save
@@ -43,13 +46,13 @@ describe MidwireCommon::YamlSetting do
43
46
  end
44
47
  end
45
48
 
46
- context '.config' do
49
+ describe '.config' do
47
50
  it 'returns the data hash' do
48
51
  expect(setting.config[:test]).to eq(a: 1, b: 2, c: 3)
49
52
  end
50
53
  end
51
54
 
52
- context '.data' do
55
+ describe '.data' do
53
56
  it 'returns the data hash' do
54
57
  expect(setting.data[:test]).to eq(a: 1, b: 2, c: 3)
55
58
  end
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  if ENV['COVERAGE']
2
4
  require 'simplecov'
3
5
  SimpleCov.start do
@@ -6,7 +8,7 @@ if ENV['COVERAGE']
6
8
  end
7
9
  end
8
10
 
9
- require 'pry'
11
+ require 'debug'
10
12
  require File.join(File.dirname(__FILE__), '..', 'lib', 'midwire_common')
11
13
  require 'midwire_common/all'
12
14
 
@@ -15,20 +17,24 @@ PROJECT_ROOT = File.expand_path('..', File.dirname(__FILE__))
15
17
  RSpec.configure do |config|
16
18
  include MidwireCommon
17
19
 
18
- config.mock_with :rspec
19
- config.color = true
20
20
  config.order = 'random'
21
21
 
22
22
  def capture(stream)
23
- begin
24
- stream = stream.to_s
25
- eval "$#{stream} = StringIO.new"
26
- yield
27
- result = eval("$#{stream}").string
28
- ensure
29
- eval("$#{stream} = #{stream.upcase}")
23
+ stream = stream.to_s
24
+ captured = StringIO.new
25
+ original = stream == 'stdout' ? $stdout : $stderr
26
+ if stream == 'stdout'
27
+ $stdout = captured
28
+ else
29
+ $stderr = captured
30
+ end
31
+ yield
32
+ captured.string
33
+ ensure
34
+ if stream == 'stdout'
35
+ $stdout = original
36
+ else
37
+ $stderr = original
30
38
  end
31
-
32
- result
33
39
  end
34
40
  end