midwire_common 0.1.12 → 0.1.13

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.
@@ -1,27 +1,27 @@
1
- # -*- encoding: utf-8 -*-
1
+ # coding: utf-8
2
2
  require File.expand_path('../lib/midwire_common/version', __FILE__)
3
3
 
4
- Gem::Specification.new do |gem|
5
- gem.authors = ["Chris Blackburn"]
6
- gem.email = ["chris@midwiretech.com"]
7
- gem.description = %q{A useful Ruby library for the Midwire development team}
8
- gem.summary = %q{Midwire Ruby Library}
9
- gem.homepage = "https://github.com/midwire/midwire_common"
4
+ Gem::Specification.new do |spec|
5
+ spec.name = 'midwire_common'
6
+ spec.version = MidwireCommon::VERSION
7
+ spec.authors = ['Chris Blackburn']
8
+ spec.email = ['chris@midwiretech.com']
9
+ spec.description = 'A useful Ruby library for the Midwire development team'
10
+ spec.summary = 'Midwire Ruby Library'
11
+ spec.homepage = 'https://github.com/midwire/midwire_common'
10
12
 
11
- gem.files = `git ls-files`.split($\)
12
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
- gem.name = "midwire_common"
15
- gem.require_paths = ["lib"]
16
- gem.version = MidwireCommon::VERSION
13
+ spec.files = `git ls-files -z`.split("\x0")
14
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
15
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
16
+ spec.require_paths = ['lib']
17
17
 
18
- gem.add_development_dependency "rspec"
19
- gem.add_development_dependency "simplecov"
20
- gem.add_development_dependency "guard"
21
- gem.add_development_dependency "guard-bundler"
22
- gem.add_development_dependency "guard-rspec"
23
- gem.add_development_dependency "guard-rubocop"
24
- gem.add_development_dependency "pry"
25
- gem.add_development_dependency "rake"
26
- gem.add_development_dependency "rubocop"
18
+ spec.add_development_dependency 'rspec', '~> 2.14'
19
+ spec.add_development_dependency 'simplecov', '~> 0.7'
20
+ spec.add_development_dependency 'guard', '~> 2.11'
21
+ spec.add_development_dependency 'guard-bundler', '~> 2.1'
22
+ spec.add_development_dependency 'guard-rspec', '~> 4.5'
23
+ spec.add_development_dependency 'guard-rubocop', '~> 1.2'
24
+ spec.add_development_dependency 'pry', '~> 0.10'
25
+ spec.add_development_dependency 'rake', '~> 10.1'
26
+ spec.add_development_dependency 'rubocop', '~> 0.28'
27
27
  end
@@ -1,42 +1,62 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Array do
4
- it "counts occurrences of an element" do
5
- [1,2,2,3,3,3].count_occurrences.should == {1=>1, 2=>2, 3=>3}
6
- ['asdf','asdf','qwer','asdf'].count_occurrences.should == {'asdf'=>3, 'qwer'=>1}
4
+ it 'counts occurrences of an element' do
5
+ [1, 2, 2, 3, 3, 3].count_occurrences.should eq(1 => 1, 2 => 2, 3 => 3)
6
+ %w(asdf asdf qwer asdf).count_occurrences.should == {
7
+ 'asdf' => 3,
8
+ 'qwer' => 1
9
+ }
7
10
  end
8
11
 
9
- it "randomizes the order of an array" do
10
- myarray = [1,2,3,4,5,6,7,8,9,'0']
11
- myarray.randomize.should_not == myarray
12
+ it 'randomizes the order of an array' do
13
+ myarray = [1, 2, 3, 4, 5, 6, 7, 8, 9, '0']
14
+ myarray.randomize.should_not eq(myarray)
12
15
  myarray.randomize!
13
- myarray.should_not == [1,2,3,4,5,6,7,8,9,'0']
16
+ myarray.should_not == [1, 2, 3, 4, 5, 6, 7, 8, 9, '0']
14
17
  end
15
18
 
16
- it "sorts elements case insensitive" do
19
+ it 'sorts elements case insensitive' do
17
20
  myarray = %w(zebra ghost Zebra cat Cat)
18
- myarray.sort_case_insensitive.should == ["Cat", "cat", "ghost", "Zebra", "zebra"]
21
+ myarray.sort_case_insensitive.should eq(%w(Cat cat ghost Zebra zebra))
19
22
  end
20
23
 
21
- it "can process first and last entries differently than others" do
24
+ it 'can process first and last entries differently than others' do
22
25
  text = ''
23
- ["KU", "K-State", "MU"].each_with_first_last(
24
- lambda {|team| text += "#{team} came first in the NCAA basketball tournament.\n"},
25
- lambda {|team| text += "#{team} did not come first or last in the final four.\n"},
26
- lambda {|team| text += "#{team} came last in the final four this year.\n"}
26
+ ['KU', 'K-State', 'MU'].each_with_first_last(
27
+ lambda do |team|
28
+ text += "#{team} came first in the NCAA basketball tournament.\n"
29
+ end,
30
+ lambda do |team|
31
+ text += "#{team} did not come first or last in the final four.\n"
32
+ end,
33
+ lambda do |team|
34
+ text += "#{team} came last in the final four this year.\n"
35
+ end
27
36
  )
28
- text.should == "KU came first in the NCAA basketball tournament.\nK-State did not come first or last in the final four.\nMU came last in the final four this year.\n"
37
+ text.should == <<-string.here_with_pipe("\n")
38
+ |KU came first in the NCAA basketball tournament.
39
+ |K-State did not come first or last in the final four.
40
+ |MU came last in the final four this year.
41
+ |
42
+ string
29
43
  end
30
44
 
31
- it "can binary search for elements" do
45
+ it 'can binary search for elements' do
32
46
  a = %w(a b c)
33
- a.bsearch('a').should == 0
34
- a.bsearch('b').should == 1
35
- a.bsearch('c').should == 2
47
+ a.bsearch('a').should eq(0)
48
+ a.bsearch('b').should eq(1)
49
+ a.bsearch('c').should eq(2)
36
50
  end
37
51
 
38
- it "can superjoin elements" do
39
- [1,2,3].superjoin(["->","+","<-"]).should == "->1+2+3<-"
40
- [[1,2],[2,3]].superjoin( %w{<table><tr> </tr><tr> </tr></table>}, %w{<td> </td><td> </td>} ).should == "<table><tr><td>1</td><td>2</td></tr><tr><td>2</td><td>3</td></tr></table>"
52
+ # rubocop:disable Metrics/LineLength
53
+ it 'can superjoin elements' do
54
+ [1, 2, 3].superjoin(['->', '+', '<-']).should eq('->1+2+3<-')
55
+ [[1, 2], [2, 3]].superjoin(
56
+ %w(<table><tr> </tr><tr> </tr></table>), %w(<td> </td><td> </td>)
57
+ ).should eq(
58
+ '<table><tr><td>1</td><td>2</td></tr><tr><td>2</td><td>3</td></tr></table>'
59
+ )
41
60
  end
61
+ # rubocop:enable Metrics/LineLength
42
62
  end
@@ -1,40 +1,39 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe MidwireCommon::DataFileCache do
4
- let(:cache_dir) {'/tmp/.cache_dir'}
5
- let(:filename) {"data_file_cache"}
6
- let(:filepath) {"#{cache_dir}/#{filename}"}
7
- let(:data) {'this is my data'}
4
+ let(:cache_dir) { '/tmp/.cache_dir' }
5
+ let(:filename) { 'data_file_cache' }
6
+ let(:filepath) { "#{cache_dir}/#{filename}" }
7
+ let(:data) { 'this is my data' }
8
8
 
9
9
  before(:each) do
10
10
  @cache = MidwireCommon::DataFileCache.new("#{cache_dir}/#{filename}")
11
11
  end
12
12
 
13
- it "creates a directory for the cache file" do
14
- File.exists?(cache_dir).should be_true
13
+ it 'creates a directory for the cache file' do
14
+ File.exist?(cache_dir).should eq(true)
15
15
  end
16
16
 
17
- it "caches data" do
17
+ it 'caches data' do
18
18
  @cache.put(data)
19
- File.exists?(filepath).should be_true
19
+ File.exist?(filepath).should eq(true)
20
20
  x = File.read(filepath)
21
21
  x.should == data
22
22
  end
23
23
 
24
- it "determines the age of the cached data" do
24
+ it 'determines the age of the cached data' do
25
25
  tm = @cache.age
26
- (tm > 0).should be_true
26
+ (tm > 0).should eq(true)
27
27
  end
28
28
 
29
- it "retrieves cached data" do
29
+ it 'retrieves cached data' do
30
30
  dta = @cache.get
31
31
  dta.should == data
32
32
  end
33
33
 
34
- it "prepends the filename with cache dir" do
34
+ it 'prepends the filename with cache dir' do
35
35
  testfile = 'testfile'
36
36
  nf = @cache.send(:normalize_filename, testfile)
37
37
  nf.should == "#{cache_dir}/#{testfile}"
38
38
  end
39
-
40
39
  end
@@ -1,8 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Enumerable do
4
- it "can sort by frequency of occurrences" do
5
- [1,2,3,3,3,3,2].sort_by_frequency.should == [3, 3, 3, 3, 2, 2, 1]
6
- %w(a b c d e f a f f b f a).sort_by_frequency.should == ["f", "f", "f", "f", "a", "a", "a", "b", "b", "c", "d", "e"]
4
+ it 'can sort by frequency of occurrences' do
5
+ [1, 2, 3, 3, 3, 3, 2].sort_by_frequency.should eq([3, 3, 3, 3, 2, 2, 1])
6
+ %w(a b c d e f a f f b f a).sort_by_frequency
7
+ .should eq(%w(f f f f a a a b b c d e))
7
8
  end
8
9
  end
@@ -1,8 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe File::Stat do
4
- it "knows on which devise it resides" do
5
- s = File::Stat.device_name("/tmp")
4
+ it 'knows on which devise it resides' do
5
+ s = File::Stat.device_name('/tmp')
6
6
  s.should_not be_nil
7
7
  end
8
8
  end
@@ -1,15 +1,15 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Fixnum do
4
- it "knows if it is odd or even" do
5
- 777.is_odd?.should be_true
6
- 776.is_odd?.should be_false
4
+ it 'knows if it is odd or even' do
5
+ 777.odd?.should eq(true)
6
+ 776.odd?.should eq(false)
7
7
 
8
- 777.is_even?.should be_false
9
- 776.is_even?.should be_true
8
+ 777.even?.should eq(false)
9
+ 776.even?.should eq(true)
10
10
  end
11
11
 
12
- it "can format itself with commas" do
13
- 8729928827.commify.should == "8,729,928,827"
12
+ it 'can format itself with commas' do
13
+ 8_729_928_827.commify.should == '8,729,928,827'
14
14
  end
15
- end
15
+ end
@@ -1,8 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Float do
4
- it "can format itself with commas" do
5
- 8729928827.0.commify.should == "8,729,928,827.0"
6
- 8729928827.20332002.commify.should == "8,729,928,827.20332"
4
+ it 'can format itself with commas' do
5
+ 8_729_928_827.0.commify.should eq('8,729,928,827.0')
6
+ 8_729_928_827.20332002.commify.should eq('8,729,928,827.20332')
7
7
  end
8
8
  end
@@ -1,40 +1,84 @@
1
1
  require 'spec_helper'
2
2
 
3
+ # rubocop:disable Lint/Void
3
4
  describe Hash do
4
- it "greps key/value pairs using a regular expression" do
5
- h = {a: "this is a test", 'b' => 'this is not the answer'}
6
- h.grep(/a test/).should == [[:a, "this is a test"]]
7
- h.grep(/b/).should == [['b', "this is not the answer"]]
8
- h.grep(/^this/).should == [[:a, "this is a test"], ["b", "this is not the answer"]]
5
+ it 'greps key/value pairs using a regular expression' do
6
+ h = { a: 'this is a test', 'b' => 'this is not the answer' }
7
+ h.grep(/a test/).should == [[:a, 'this is a test']]
8
+ h.grep(/b/).should == [['b', 'this is not the answer']]
9
+ h.grep(/^this/).should == [
10
+ [:a, 'this is a test'], ['b', 'this is not the answer']
11
+ ]
9
12
  end
10
13
 
11
- it "returns elements with certain keys filtered out" do
12
- {a: 1, b: 2, c: 3}.except(:a).should == {b: 2, c: 3}
14
+ it 'returns elements with certain keys filtered out' do
15
+ { a: 1, b: 2, c: 3 }.except(:a).should == { b: 2, c: 3 }
13
16
  end
14
17
 
15
- it "returns elements for discretely passed keys" do
16
- {a: 1, b: 2, c: 3}.only(:a).should == {a: 1}
18
+ it 'returns elements for discretely passed keys' do
19
+ { a: 1, b: 2, c: 3 }.only(:a).should == { a: 1 }
17
20
  end
18
21
 
19
- it "pops an element off of the stack" do
20
- h = {a: 1, b: 2, c: 3}
21
- h.pop(:a).should == {a: 1}
22
- h.should == {b: 2, c: 3}
22
+ it 'pops an element off of the stack' do
23
+ h = { a: 1, b: 2, c: 3 }
24
+ h.pop(:a).should == { a: 1 }
25
+ h.should == { b: 2, c: 3 }
23
26
  end
24
27
 
25
- it "returns a query string" do
26
- { a: 1, b: 2, c: 3}.to_query_string.should == "a=1&b=2&c=3"
28
+ it 'returns a query string' do
29
+ { a: 1, b: 2, c: 3 }.to_query_string.should == 'a=1&b=2&c=3'
27
30
  end
28
31
 
29
- it "symbolizes its keys" do
30
- h = {'a'=>1, 'b'=>2, 'c'=>3}
31
- h.symbolize_keys.should == {a: 1, b: 2, c: 3}
32
+ it 'symbolizes its keys' do
33
+ h = { 'a' => 1, 'b' => 2, 'c' => 3 }
34
+ h.symbolize_keys.should == { a: 1, b: 2, c: 3 }
32
35
  h.symbolize_keys!
33
- h.should == {a: 1, b: 2, c: 3}
36
+ h.should == { a: 1, b: 2, c: 3 }
34
37
  end
35
38
 
36
- it "recursively symbolizes its keys" do
37
- h = {'a'=>1, 'b'=>{'a'=>1, 'b'=>2, 'c'=>{'a'=>1, 'b'=>2, 'c'=>3}}, 'c'=>3}
38
- h.recursively_symbolize_keys!.should == {a: 1, b: {a: 1, b: 2, c: {a: 1, b: 2, c: 3}}, c: 3}
39
+ it 'recursively symbolizes its keys' do
40
+ h = {
41
+ 'a' => 1,
42
+ 'b' => {
43
+ 'a' => 1,
44
+ 'b' => 2,
45
+ 'c' => {
46
+ 'a' => 1,
47
+ 'b' => 2,
48
+ 'c' => 3
49
+ }
50
+ },
51
+ 'c' => 3
52
+ }
53
+ h.recursively_symbolize_keys!.should == {
54
+ a: 1, b: { a: 1, b: 2, c: { a: 1, b: 2, c: 3 } }, c: 3
55
+ }
56
+ end
57
+
58
+ context 'diff methods' do
59
+ let(:h1_keys) { { 'a' => 1, 'b' => 2, 'c' => 3 } }
60
+ let(:h2_keys) { { 'a' => 1, 'b' => 2, 'd' => 3 } }
61
+
62
+ let(:h1_keys_nested) { { 'a' => 1, 'b' => 2, { 'x' => 99 } => 3 } }
63
+ let(:h2_keys_nested) { { 'a' => 1, 'b' => 2, { 'x' => 99 } => 4 } }
64
+
65
+ let(:h1_values) { { 'a' => 1, 'b' => 2, 'c' => 3 } }
66
+ let(:h2_values) { { 'a' => 1, 'b' => 2, 'c' => 4 } }
67
+
68
+ context '.diff' do
69
+ it 'reports different keys' do
70
+ h1_keys.diff(h2_keys).should == { 'c' => [3, nil], 'd' => [nil, 3] }
71
+ end
72
+
73
+ it 'reports different values' do
74
+ h1_values.diff(h2_values).should == { 'c' => [3, nil], 'c' => [3, 4] }
75
+ end
76
+
77
+ it 'reports different keys even with nested hashes' do
78
+ h1_keys_nested.diff(h2_keys_nested).should ==
79
+ { { 'x' => 99 } => [3, 4] }
80
+ end
81
+ end
39
82
  end
40
83
  end
84
+ # rubocop:enable Lint/Void
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
- # encoding: ascii-8bit
3
+ # rubocop:disable Metrics/LineLength
4
4
  require 'spec_helper'
5
5
 
6
6
  describe String do
@@ -44,7 +44,7 @@ describe String do
44
44
  end
45
45
 
46
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"
47
+ " \t \t a test is coming \t \t ".trim.should == 'a test is coming'
48
48
  end
49
49
 
50
50
  it "'trim!' removes whitespace from both sides of the string" do
@@ -74,7 +74,7 @@ describe String do
74
74
  end
75
75
 
76
76
  it 'here_with_pipe - with no space delimeter' do
77
- html = <<-STOP.here_with_pipe("")
77
+ html = <<-STOP.here_with_pipe('')
78
78
  |<!-- Begin: comment -->
79
79
  |<script type="text/javascript">
80
80
  |</script>
@@ -101,7 +101,6 @@ describe String do
101
101
  end
102
102
 
103
103
  it 'shortens itself with elipses at the end' do
104
- #
105
104
  s = 'this is my very long string which I will eventually shorten with the enhanced String class that we are now testing.'
106
105
  short = s.shorten
107
106
  expect(short).to eq('this is my very long string...')
@@ -132,43 +131,44 @@ describe String do
132
131
 
133
132
  context 'characterization' do
134
133
  it 'knows if it is alpha-numeric or not' do
135
- 'abcd-9191'.is_alpha_numeric?.should be_false
136
- 'abcd.9191'.is_alpha_numeric?.should be_false
137
- 'abcd91910'.is_alpha_numeric?.should be_true
138
- 'abcd_9191'.is_alpha_numeric?.should be_false
139
- 'abcd 9191'.is_alpha_numeric?.should be_false
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)
140
139
  end
141
140
 
142
141
  it 'knows if it is an email address or not' do
143
- 'abcd_9191'.is_email_address?.should be_false
144
- 'abcd@9191'.is_email_address?.should be_false
145
- 'abcd@9191.poop'.is_email_address?.should be_false
146
- 'abcd@9191.info'.is_email_address?.should be_true
147
- 'abcd-asdf@9191.com'.is_email_address?.should be_true
148
- 'abcd_asdf@9191.com'.is_email_address?.should be_true
149
- 'abcd.asdf@9191.com'.is_email_address?.should be_true
142
+ 'abcd_9191'.email_address?.should eq(false)
143
+ 'abcd@9191'.email_address?.should eq(false)
144
+ 'abcd@9191.poop'.email_address?.should eq(false)
145
+ 'abcd@9191.info'.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)
148
+ 'abcd.asdf@9191.com'.email_address?.should eq(true)
150
149
  end
151
150
 
152
151
  it 'knows if it is a zipcode or not' do
153
- '13922-2356'.is_zipcode?.should be_true
154
- '13922.2343'.is_zipcode?.should be_false
155
- '13922 2342'.is_zipcode?.should be_false
156
- 'ABSSD'.is_zipcode?.should be_false
157
- 'i3323'.is_zipcode?.should be_false
158
- '13922'.is_zipcode?.should be_true
152
+ '13922-2356'.zipcode?.should eq(true)
153
+ '13922.2343'.zipcode?.should eq(false)
154
+ '13922 2342'.zipcode?.should eq(false)
155
+ 'ABSSD'.zipcode?.should eq(false)
156
+ 'i3323'.zipcode?.should eq(false)
157
+ '13922'.zipcode?.should eq(true)
159
158
  end
160
159
 
161
160
  it 'knows if it is numeric or not' do
162
- '12341'.is_numeric?.should be_true
163
- '12341.23'.is_numeric?.should be_true
164
- '12341.00000000000000023'.is_numeric?.should be_true
165
- '0.12341'.is_numeric?.should be_true
166
- '0x2E'.is_numeric?.should be_true
167
- ' 0.12341'.is_numeric?.should be_true
168
- ' 0.12341 '.is_numeric?.should be_true
169
- '.12341'.is_numeric?.should be_true
170
- ' 12341.'.is_numeric?.should be_false
171
- ' 12341. '.is_numeric?.should be_false
161
+ '12341'.numeric?.should eq(true)
162
+ '12341.23'.numeric?.should eq(true)
163
+ '12341.00000000000000023'.numeric?.should eq(true)
164
+ '0.12341'.numeric?.should eq(true)
165
+ '0x2E'.numeric?.should eq(true)
166
+ ' 0.12341'.numeric?.should eq(true)
167
+ ' 0.12341 '.numeric?.should eq(true)
168
+ '.12341'.numeric?.should eq(true)
169
+ ' 12341.'.numeric?.should eq(false)
170
+ ' 12341. '.numeric?.should eq(false)
172
171
  end
173
172
  end
174
173
  end
174
+ # rubocop:enable Metrics/LineLength