more_core_extensions 1.2.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4e072368f5dec0db13f1df4e2ff8319494087d15
4
+ data.tar.gz: cf9f2bbb0c0a9ae9857a073479e44816ea622149
5
+ SHA512:
6
+ metadata.gz: f2a860d28460607a3d28f51e140754171ee53e49c5546a25f5202f35f620e3d2bfb8609a3ffe6afbe826a0ccac48abe033d0e0f2a9a058d35450d67ce213d4c7
7
+ data.tar.gz: 4515f726acb409bff78d078e92f3ce56daf3d60d57f45858149782be684f5c33b213f132d71267171e03d577cc7c8fd21e66718d747a03d69077e558491e7ee5
data/.rspec CHANGED
@@ -1,2 +1,3 @@
1
1
  --color
2
- --format progress
2
+ --warnings
3
+ --require spec_helper
data/README.md CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  MoreCoreExtensions are a set of core extensions beyond those provided by ActiveSupport.
4
4
 
5
- [![Gem Version](https://badge.fury.io/rb/more_core_extensions.png)](http://badge.fury.io/rb/more_core_extensions)
6
- [![Build Status](https://travis-ci.org/ManageIQ/more_core_extensions.png?branch=master)](https://travis-ci.org/ManageIQ/more_core_extensions)
7
- [![Code Climate](https://codeclimate.com/github/ManageIQ/more_core_extensions.png)](https://codeclimate.com/github/ManageIQ/more_core_extensions)
8
- [![Coverage Status](https://coveralls.io/repos/ManageIQ/more_core_extensions/badge.png)](https://coveralls.io/r/ManageIQ/more_core_extensions)
9
- [![Dependency Status](https://gemnasium.com/ManageIQ/more_core_extensions.png)](https://gemnasium.com/ManageIQ/more_core_extensions)
5
+ [![Gem Version](https://badge.fury.io/rb/more_core_extensions.svg)](http://badge.fury.io/rb/more_core_extensions)
6
+ [![Build Status](https://travis-ci.org/ManageIQ/more_core_extensions.svg?branch=master)](https://travis-ci.org/ManageIQ/more_core_extensions)
7
+ [![Code Climate](http://img.shields.io/codeclimate/github/ManageIQ/more_core_extensions.svg)](https://codeclimate.com/github/ManageIQ/more_core_extensions)
8
+ [![Coverage Status](http://img.shields.io/coveralls/ManageIQ/more_core_extensions.svg)](https://coveralls.io/r/ManageIQ/more_core_extensions)
9
+ [![Dependency Status](https://gemnasium.com/ManageIQ/more_core_extensions.svg)](https://gemnasium.com/ManageIQ/more_core_extensions)
10
10
 
11
11
  ## Extensions Provided
12
12
 
@@ -1,3 +1,4 @@
1
+ require 'active_support'
1
2
  require 'active_support/core_ext/object/blank'
2
3
 
3
4
  module MoreCoreExtensions
@@ -18,4 +19,4 @@ module MoreCoreExtensions
18
19
  end
19
20
  end
20
21
 
21
- Array.send(:include, MoreCoreExtensions::ArrayDeletes)
22
+ Array.send(:include, MoreCoreExtensions::ArrayDeletes)
@@ -7,7 +7,7 @@ module MoreCoreExtensions
7
7
  #
8
8
  # [1, 2, 3, 4, 2, 4].duplicates #=> [2, 4]
9
9
  def duplicates
10
- element_counts.reject { |k, v| v == 1 }.keys
10
+ element_counts.select { |_k, v| v > 1 }.keys
11
11
  end
12
12
  end
13
13
  end
@@ -1,10 +1,16 @@
1
1
  module MoreCoreExtensions
2
2
  module ArrayElementCounts
3
- # Returns a Hash of each element to the count of those elements.
3
+ # Returns a Hash of each element to the count of those elements. Optionally
4
+ # pass a block to count by a different criteria.
4
5
  #
5
6
  # [1, 2, 3, 1, 3, 1].counts # => {1 => 3, 2 => 1, 3 => 2}
7
+ # %w(a aa aaa a aaa a).counts { |i| i.length } # => {1 => 3, 2 => 1, 3 => 2}
8
+ #
6
9
  def element_counts
7
- each_with_object(Hash.new(0)) { |i, h| h[i] += 1 }
10
+ each_with_object(Hash.new(0)) do |i, h|
11
+ key = block_given? ? yield(i) : i
12
+ h[key] += 1
13
+ end
8
14
  end
9
15
  end
10
16
  end
@@ -7,6 +7,7 @@ module MoreCoreExtensions
7
7
  # [1, 2, 3].include_any?(1, 4) #=> true
8
8
  # [1, 2, 3].include_any?(4, 5) #=> false
9
9
  def include_any?(*items)
10
+ items = items.first if items.length == 1 && items.first.kind_of?(Array)
10
11
  !(self & items).empty?
11
12
  end
12
13
 
@@ -17,6 +18,7 @@ module MoreCoreExtensions
17
18
  # [1, 2, 3].include_none?(1, 4) #=> false
18
19
  # [1, 2, 3].include_none?(4, 5) #=> true
19
20
  def include_none?(*items)
21
+ items = items.first if items.length == 1 && items.first.kind_of?(Array)
20
22
  (self & items).empty?
21
23
  end
22
24
 
@@ -27,6 +29,7 @@ module MoreCoreExtensions
27
29
  # [1, 2, 3].include_all?(1, 4) #=> false
28
30
  # [1, 2, 3].include_all?(4, 5) #=> false
29
31
  def include_all?(*items)
32
+ items = items.first if items.length == 1 && items.first.kind_of?(Array)
30
33
  (items - self).empty?
31
34
  end
32
35
 
@@ -1,3 +1,4 @@
1
+ require 'active_support'
1
2
  require 'active_support/core_ext/object/blank'
2
3
 
3
4
  module MoreCoreExtensions
@@ -11,15 +11,7 @@ module MoreCoreExtensions
11
11
  # Aaa::Bbb::Ccc::Eee.in_namespace?(Aaa::Bbb::Ccc::Ddd) #=> false
12
12
  def in_namespace?(val)
13
13
  val_ns = val.to_s.split("::")
14
- val_ns == namespace[0, val_ns.length]
15
- end
16
-
17
- #
18
- # Returns an Array with the namespace to an Instance.
19
- #
20
- # Aaa::Bbb::Ccc::Ddd.new.namespace #=> ["Aaa", "Bbb", "Ccc", "Ddd"]
21
- def namespace
22
- self.class.namespace
14
+ val_ns == (kind_of?(Module) ? namespace : self.class.namespace)[0, val_ns.length]
23
15
  end
24
16
  end
25
17
  end
@@ -1,3 +1,3 @@
1
1
  module MoreCoreExtensions
2
- VERSION = "1.2.0"
2
+ VERSION = "2.0.0"
3
3
  end
@@ -1,17 +1,15 @@
1
- require_relative "../../spec_helper"
2
-
3
1
  describe Array do
4
2
  it "#delete_nils" do
5
- [].delete_nils.should == []
6
- [1].delete_nils.should == [1]
7
- [nil].delete_nils.should == []
8
- [1, [], nil].delete_nils.should == [1, []]
3
+ expect([].delete_nils).to eq([])
4
+ expect([1].delete_nils).to eq([1])
5
+ expect([nil].delete_nils).to eq([])
6
+ expect([1, [], nil].delete_nils).to eq([1, []])
9
7
  end
10
8
 
11
9
  it "#delete_blanks" do
12
- [].delete_blanks.should == []
13
- [1].delete_blanks.should == [1]
14
- [nil].delete_blanks.should == []
15
- [1, [], nil].delete_blanks.should == [1]
10
+ expect([].delete_blanks).to eq([])
11
+ expect([1].delete_blanks).to eq([1])
12
+ expect([nil].delete_blanks).to eq([])
13
+ expect([1, [], nil].delete_blanks).to eq([1])
16
14
  end
17
- end
15
+ end
@@ -1,11 +1,9 @@
1
- require_relative "../../spec_helper"
2
-
3
1
  describe Array do
4
2
  it '#duplicates' do
5
- [1, 2, 3, 4].duplicates.should be_empty
6
- [1, 2, 3, 4, 2, 4].duplicates.should match_array [2, 4]
3
+ expect([1, 2, 3, 4].duplicates).to be_empty
4
+ expect([1, 2, 3, 4, 2, 4].duplicates).to match_array [2, 4]
7
5
 
8
- ['1', '2', '3', '4'].duplicates.should be_empty
9
- ['1', '2', '3', '4', '2', '4'].duplicates.should match_array ['2', '4']
6
+ expect(['1', '2', '3', '4'].duplicates).to be_empty
7
+ expect(['1', '2', '3', '4', '2', '4'].duplicates).to match_array ['2', '4']
10
8
  end
11
9
  end
@@ -1,10 +1,16 @@
1
- require "spec_helper"
2
-
3
1
  describe Array do
4
- it "#element_counts" do
5
- [].element_counts.should == {}
6
- [1].element_counts.should == {1 => 1}
7
- [nil].element_counts.should == {nil => 1}
8
- [1, 2, 3, 1, 3, 1].element_counts.should == {1 => 3, 2 => 1, 3 => 2}
2
+ describe "#element_counts" do
3
+ it "without a block" do
4
+ expect([].element_counts).to eq({})
5
+ expect([1].element_counts).to eq({1 => 1})
6
+ expect([nil].element_counts).to eq({nil => 1})
7
+ expect([1, 2, 3, 1, 3, 1].element_counts).to eq({1 => 3, 2 => 1, 3 => 2})
8
+ end
9
+
10
+ it "with a block" do
11
+ expect([].element_counts(&:size)).to eq({})
12
+ expect(%w(a).element_counts(&:size)).to eq({1 => 1})
13
+ expect(%w(a aa aaa a aaa a).element_counts(&:size)).to eq({1 => 3, 2 => 1, 3 => 2})
14
+ end
9
15
  end
10
16
  end
@@ -1,41 +1,51 @@
1
- require_relative "../../spec_helper"
2
-
3
1
  describe Array do
4
2
  it '#include_any?' do
5
- [1, 2, 3].include_any?(1, 2).should be_true
6
- [1, 2, 3].include_any?(1, 4).should be_true
7
- [1, 2, 3].include_any?(4, 5).should be_false
3
+ expect([1, 2, 3].include_any?(1, 2)).to be_truthy
4
+ expect([1, 2, 3].include_any?(1, 4)).to be_truthy
5
+ expect([1, 2, 3].include_any?(4, 5)).to be_falsey
6
+ expect([1, 2, 3].include_any?([1, 4])).to be_truthy
7
+ expect([1, 2, 3].include_any?([4, 5])).to be_falsey
8
8
 
9
- ['1', '2', '3'].include_any?('1', '2').should be_true
10
- ['1', '2', '3'].include_any?('1', '4').should be_true
11
- ['1', '2', '3'].include_any?('4', '5').should be_false
9
+ expect(['1', '2', '3'].include_any?('1', '2')).to be_truthy
10
+ expect(['1', '2', '3'].include_any?('1', '4')).to be_truthy
11
+ expect(['1', '2', '3'].include_any?('4', '5')).to be_falsey
12
+ expect(['1', '2', '3'].include_any?(['1', '4'])).to be_truthy
13
+ expect(['1', '2', '3'].include_any?(['4', '5'])).to be_falsey
12
14
  end
13
15
 
14
16
  it '#include_none?' do
15
- [1, 2, 3].include_none?(1, 2).should be_false
16
- [1, 2, 3].include_none?(1, 4).should be_false
17
- [1, 2, 3].include_none?(4, 5).should be_true
17
+ expect([1, 2, 3].include_none?(1, 2)).to be_falsey
18
+ expect([1, 2, 3].include_none?(1, 4)).to be_falsey
19
+ expect([1, 2, 3].include_none?(4, 5)).to be_truthy
20
+ expect([1, 2, 3].include_none?([1, 4])).to be_falsey
21
+ expect([1, 2, 3].include_none?([4, 5])).to be_truthy
18
22
 
19
- ['1', '2', '3'].include_none?('1', '2').should be_false
20
- ['1', '2', '3'].include_none?('1', '4').should be_false
21
- ['1', '2', '3'].include_none?('4', '5').should be_true
23
+ expect(['1', '2', '3'].include_none?('1', '2')).to be_falsey
24
+ expect(['1', '2', '3'].include_none?('1', '4')).to be_falsey
25
+ expect(['1', '2', '3'].include_none?('4', '5')).to be_truthy
26
+ expect(['1', '2', '3'].include_none?(['1', '4'])).to be_falsey
27
+ expect(['1', '2', '3'].include_none?(['4', '5'])).to be_truthy
22
28
  end
23
29
 
24
30
  it '#include_all?' do
25
- [1, 2, 3].include_all?(1, 2).should be_true
26
- [1, 2, 3].include_all?(1, 4).should be_false
27
- [1, 2, 3].include_all?(4, 5).should be_false
31
+ expect([1, 2, 3].include_all?(1, 2)).to be_truthy
32
+ expect([1, 2, 3].include_all?(1, 4)).to be_falsey
33
+ expect([1, 2, 3].include_all?(4, 5)).to be_falsey
34
+ expect([1, 2, 3].include_all?([1, 2])).to be_truthy
35
+ expect([1, 2, 3].include_all?([1, 4])).to be_falsey
28
36
 
29
- ['1', '2', '3'].include_all?('1', '2').should be_true
30
- ['1', '2', '3'].include_all?('1', '4').should be_false
31
- ['1', '2', '3'].include_all?('4', '5').should be_false
37
+ expect(['1', '2', '3'].include_all?('1', '2')).to be_truthy
38
+ expect(['1', '2', '3'].include_all?('1', '4')).to be_falsey
39
+ expect(['1', '2', '3'].include_all?('4', '5')).to be_falsey
40
+ expect(['1', '2', '3'].include_all?(['1', '2'])).to be_truthy
41
+ expect(['1', '2', '3'].include_all?(['1', '4'])).to be_falsey
32
42
  end
33
43
 
34
44
  it "#includes_index?" do
35
- [1, 2, 3].includes_index?(-4).should be_false
36
- [1, 2, 3].includes_index?(-3).should be_true
37
- [1, 2, 3].includes_index?(1).should be_true
38
- [1, 2, 3].includes_index?(2).should be_true
39
- [1, 2, 3].includes_index?(3).should be_false
45
+ expect([1, 2, 3].includes_index?(-4)).to be_falsey
46
+ expect([1, 2, 3].includes_index?(-3)).to be_truthy
47
+ expect([1, 2, 3].includes_index?(1)).to be_truthy
48
+ expect([1, 2, 3].includes_index?(2)).to be_truthy
49
+ expect([1, 2, 3].includes_index?(3)).to be_falsey
40
50
  end
41
51
  end
@@ -1,5 +1,3 @@
1
- require_relative "../../spec_helper"
2
-
3
1
  shared_examples_for "core_ext/array/nested will not modify arguments" do |meth|
4
2
  it "will not modify arguments" do
5
3
  args = (meth == :store_path ? [1] : [])
@@ -7,44 +5,44 @@ shared_examples_for "core_ext/array/nested will not modify arguments" do |meth|
7
5
  key = [3, 0, 1, 2]
8
6
  key2 = key.dup
9
7
  array.send(meth, key2, *args)
10
- key2.should == key
8
+ expect(key2).to eq(key)
11
9
 
12
10
  key = [4, 0, 1]
13
11
  key2 = key.dup
14
12
  array.send(meth, key2, *args)
15
- key2.should == key
13
+ expect(key2).to eq(key)
16
14
  end
17
15
  end
18
16
 
19
17
  shared_examples_for "core_ext/array/nested" do
20
18
  context '#fetch_path' do
21
19
  it "with various values" do
22
- array.fetch_path(0).should == 1
23
- array.fetch_path(1).should == []
24
- array.fetch_path(1, 0).should be_nil
25
- array.fetch_path(1, 0, 1).should be_nil
26
- array.fetch_path(2).should == [2]
27
- array.fetch_path(2, 0).should == 2
28
- array.fetch_path(-4, 0).should == 2
29
- array.fetch_path(2, 0, 1).should be_nil
30
- array.fetch_path(3, 0, 0, 0).should == 3
31
- array.fetch_path(3, 0, 1, 999).should be_nil
32
- array.fetch_path(3, 0, 1, 2, 3).should be_nil
33
- array.fetch_path(4).should == [nil, nil, nil, nil]
34
- array.fetch_path(4, 0).should be_nil
35
- array.fetch_path(4, 0, 1).should be_nil
36
- array.fetch_path(5).should == []
37
- array.fetch_path(5, 0).should be_nil
38
- array.fetch_path(5, 0, 1).should be_nil
20
+ expect(array.fetch_path(0)).to eq(1)
21
+ expect(array.fetch_path(1)).to eq([])
22
+ expect(array.fetch_path(1, 0)).to be_nil
23
+ expect(array.fetch_path(1, 0, 1)).to be_nil
24
+ expect(array.fetch_path(2)).to eq([2])
25
+ expect(array.fetch_path(2, 0)).to eq(2)
26
+ expect(array.fetch_path(-4, 0)).to eq(2)
27
+ expect(array.fetch_path(2, 0, 1)).to be_nil
28
+ expect(array.fetch_path(3, 0, 0, 0)).to eq(3)
29
+ expect(array.fetch_path(3, 0, 1, 999)).to be_nil
30
+ expect(array.fetch_path(3, 0, 1, 2, 3)).to be_nil
31
+ expect(array.fetch_path(4)).to eq([nil, nil, nil, nil])
32
+ expect(array.fetch_path(4, 0)).to be_nil
33
+ expect(array.fetch_path(4, 0, 1)).to be_nil
34
+ expect(array.fetch_path(5)).to eq([])
35
+ expect(array.fetch_path(5, 0)).to be_nil
36
+ expect(array.fetch_path(5, 0, 1)).to be_nil
39
37
  end
40
38
 
41
39
  it "with a nil value should raise ArgumentError" do
42
- lambda { array.fetch_path(nil) }.should raise_error(ArgumentError)
43
- lambda { array.fetch_path(3, nil, 0) }.should raise_error(ArgumentError)
40
+ expect { array.fetch_path(nil) }.to raise_error(ArgumentError)
41
+ expect { array.fetch_path(3, nil, 0) }.to raise_error(ArgumentError)
44
42
  end
45
43
 
46
44
  it "with invalid values" do
47
- lambda { array.fetch_path }.should raise_error(ArgumentError)
45
+ expect { array.fetch_path }.to raise_error(ArgumentError)
48
46
  end
49
47
 
50
48
  include_examples "core_ext/array/nested will not modify arguments", :fetch_path
@@ -54,56 +52,56 @@ shared_examples_for "core_ext/array/nested" do
54
52
  it "on an empty array" do
55
53
  a = described_class.new
56
54
  a.store_path(0, 1)
57
- a.should == [1]
55
+ expect(a).to eq([1])
58
56
 
59
57
  a = described_class.new
60
58
  a.store_path(1, 0, 2)
61
- a.should == [nil, [2]]
59
+ expect(a).to eq([nil, [2]])
62
60
  end
63
61
 
64
62
  it "on an existing array" do
65
63
  array.store_path(1, 0, 2)
66
- array[1].should == [2]
64
+ expect(array[1]).to eq([2])
67
65
  array.store_path(2, 0, 3)
68
- array[2].should == [3]
66
+ expect(array[2]).to eq([3])
69
67
  array.store_path(-4, 0, 3)
70
- array[2].should == [3]
68
+ expect(array[2]).to eq([3])
71
69
  end
72
70
 
73
71
  it "on an existing item that is not a array" do
74
72
  array.store_path(0, 2)
75
- array[0].should == 2
73
+ expect(array[0]).to eq(2)
76
74
  array.store_path(0, 0, 3)
77
- array[0].should == [3]
75
+ expect(array[0]).to eq([3])
78
76
  end
79
77
 
80
78
  it "with an array of args" do
81
79
  a = described_class.new
82
80
  a.store_path([3, 0, 1, 2], 3)
83
- a.should == [nil, nil, nil, [[nil, [nil, nil, 3]]]]
81
+ expect(a).to eq([nil, nil, nil, [[nil, [nil, nil, 3]]]])
84
82
  end
85
83
 
86
84
  it "with a nil value" do
87
85
  a = described_class.new
88
86
  a.store_path(0, 1, nil)
89
- a.should == [[nil, nil]]
87
+ expect(a).to eq([[nil, nil]])
90
88
  end
91
89
 
92
90
  it "with an Array value" do
93
91
  a = described_class.new
94
92
  a.store_path(0, 1, [2, 3])
95
- a.should == [[nil, [2, 3]]]
93
+ expect(a).to eq([[nil, [2, 3]]])
96
94
  end
97
95
 
98
96
  it "with a Hash value" do
99
97
  a = described_class.new
100
98
  a.store_path(0, 1, {2 => 3})
101
- a.should == [[nil, {2 => 3}]]
99
+ expect(a).to eq([[nil, {2 => 3}]])
102
100
  end
103
101
 
104
102
  it "with invalid values" do
105
- lambda { described_class.new.store_path }.should raise_error(ArgumentError)
106
- lambda { described_class.new.store_path(1) }.should raise_error(ArgumentError)
103
+ expect { described_class.new.store_path }.to raise_error(ArgumentError)
104
+ expect { described_class.new.store_path(1) }.to raise_error(ArgumentError)
107
105
  end
108
106
 
109
107
  include_examples "core_ext/array/nested will not modify arguments", :store_path
@@ -111,31 +109,31 @@ shared_examples_for "core_ext/array/nested" do
111
109
 
112
110
  context '#has_key_path?' do
113
111
  it "with various values" do
114
- array.has_key_path?(0).should be_true
115
- array.has_key_path?(1).should be_true
116
- array.has_key_path?(1, 0).should be_false
117
- array.has_key_path?(1, 0, 1).should be_false
118
- array.has_key_path?(2).should be_true
119
- array.has_key_path?(2, 0).should be_true
120
- array.has_key_path?(2, 0, 1).should be_false
121
- array.has_key_path?(3, 0, 1, 2).should be_false
122
- array.has_key_path?(3, 0, 1, 999).should be_false
123
- array.has_key_path?(3, 0, 1, 2, 3).should be_false
124
- array.has_key_path?(4).should be_true
125
- array.has_key_path?(4, 0).should be_true
126
- array.has_key_path?(4, 0, 1).should be_false
127
- array.has_key_path?(5).should be_true
128
- array.has_key_path?(5, 0).should be_false
129
- array.has_key_path?(5, 0, 1).should be_false
112
+ expect(array.has_key_path?(0)).to be_truthy
113
+ expect(array.has_key_path?(1)).to be_truthy
114
+ expect(array.has_key_path?(1, 0)).to be_falsey
115
+ expect(array.has_key_path?(1, 0, 1)).to be_falsey
116
+ expect(array.has_key_path?(2)).to be_truthy
117
+ expect(array.has_key_path?(2, 0)).to be_truthy
118
+ expect(array.has_key_path?(2, 0, 1)).to be_falsey
119
+ expect(array.has_key_path?(3, 0, 1, 2)).to be_falsey
120
+ expect(array.has_key_path?(3, 0, 1, 999)).to be_falsey
121
+ expect(array.has_key_path?(3, 0, 1, 2, 3)).to be_falsey
122
+ expect(array.has_key_path?(4)).to be_truthy
123
+ expect(array.has_key_path?(4, 0)).to be_truthy
124
+ expect(array.has_key_path?(4, 0, 1)).to be_falsey
125
+ expect(array.has_key_path?(5)).to be_truthy
126
+ expect(array.has_key_path?(5, 0)).to be_falsey
127
+ expect(array.has_key_path?(5, 0, 1)).to be_falsey
130
128
  end
131
129
 
132
130
  it "with a nil value" do
133
- lambda { array.fetch_path(nil) }.should raise_error(ArgumentError)
134
- lambda { array.fetch_path(3, nil, 0) }.should raise_error(ArgumentError)
131
+ expect { array.fetch_path(nil) }.to raise_error(ArgumentError)
132
+ expect { array.fetch_path(3, nil, 0) }.to raise_error(ArgumentError)
135
133
  end
136
134
 
137
135
  it "with invalid values" do
138
- lambda { array.has_key_path? }.should raise_error(ArgumentError)
136
+ expect { array.has_key_path? }.to raise_error(ArgumentError)
139
137
  end
140
138
 
141
139
  include_examples "core_ext/array/nested will not modify arguments", :has_key_path?
@@ -144,28 +142,28 @@ shared_examples_for "core_ext/array/nested" do
144
142
  context "#delete_path" do
145
143
  it "on a nested array" do
146
144
  array.delete_path(3, 0, 0, 0)
147
- array[3].should == [[[]]]
145
+ expect(array[3]).to eq([[[]]])
148
146
  end
149
147
 
150
148
  it "with an invalid path" do
151
149
  array.delete_path(3, 0, 5)
152
- array[3].should == [[[3]]]
150
+ expect(array[3]).to eq([[[3]]])
153
151
  end
154
152
 
155
153
  include_examples "core_ext/array/nested will not modify arguments", :delete_path
156
154
  end
157
155
 
158
156
  it "#delete_blank_paths" do
159
- array.delete_blank_paths.should == [1, [2], [[[3]]]]
157
+ expect(array.delete_blank_paths).to eq([1, [2], [[[3]]]])
160
158
  end
161
159
 
162
160
  context "#find_path" do
163
161
  it "with a real value" do
164
- array.find_path(3).should == [3, 0, 0, 0]
162
+ expect(array.find_path(3)).to eq([3, 0, 0, 0])
165
163
  end
166
164
 
167
165
  it "with non-existent value" do
168
- array.find_path(42).should == []
166
+ expect(array.find_path(42)).to eq([])
169
167
  end
170
168
  end
171
169
  end
@@ -177,9 +175,9 @@ describe Array do
177
175
  [2],
178
176
  [[[3]]],
179
177
  Array.new(4),
180
- described_class.new { |i| i = described_class.new }
178
+ described_class.new
181
179
  ]
182
180
  end
183
181
 
184
182
  include_examples "core_ext/array/nested"
185
- end
183
+ end
@@ -1,5 +1,3 @@
1
- require_relative "../../spec_helper"
2
-
3
1
  describe Array do
4
2
  around do |example|
5
3
  old_seed = srand(12072)
@@ -8,16 +6,16 @@ describe Array do
8
6
  end
9
7
 
10
8
  it '#random_index' do
11
- 20.times.collect { [].random_index }.uniq.sort.should == [nil]
12
- 20.times.collect { %w{a}.random_index }.uniq.sort.should == [0]
13
- 20.times.collect { %w{a b}.random_index }.uniq.sort.should == [0, 1]
14
- 20.times.collect { %w{a b c d}.random_index }.uniq.sort.should == [0, 1, 2, 3]
9
+ expect(20.times.collect { [].random_index }.uniq.sort).to eq([nil])
10
+ expect(20.times.collect { %w{a}.random_index }.uniq.sort).to eq([0])
11
+ expect(20.times.collect { %w{a b}.random_index }.uniq.sort).to eq([0, 1])
12
+ expect(20.times.collect { %w{a b c d}.random_index }.uniq.sort).to eq([0, 1, 2, 3])
15
13
  end
16
14
 
17
15
  it '#random_element' do
18
- 20.times.collect { [].random_element }.uniq.sort.should == [nil]
19
- 20.times.collect { %w{a}.random_element }.uniq.sort.should == %w{a}
20
- 20.times.collect { %w{a b}.random_element }.uniq.sort.should == %w{a b}
21
- 20.times.collect { %w{a b c d}.random_element }.uniq.sort.should == %w{a b c d}
16
+ expect(20.times.collect { [].random_element }.uniq.sort).to eq([nil])
17
+ expect(20.times.collect { %w{a}.random_element }.uniq.sort).to eq(%w{a})
18
+ expect(20.times.collect { %w{a b}.random_element }.uniq.sort).to eq(%w{a b})
19
+ expect(20.times.collect { %w{a b c d}.random_element }.uniq.sort).to eq(%w{a b c d})
22
20
  end
23
21
  end
@@ -1,5 +1,3 @@
1
- require_relative "../../spec_helper"
2
-
3
1
  describe Array do
4
2
  STRETCH_CASES = [
5
3
  # 2 parameter cases
@@ -28,8 +26,8 @@ describe Array do
28
26
  it "where #{msg}" do
29
27
  result = Array.stretch(*test_case)
30
28
  result.each_with_index do |r, i|
31
- r.should_not equal(test_case[i])
32
- r.should == expected[i]
29
+ expect(r).not_to equal(test_case[i])
30
+ expect(r).to eq(expected[i])
33
31
  end
34
32
  end
35
33
  end
@@ -40,8 +38,8 @@ describe Array do
40
38
  it "where #{msg}" do
41
39
  result = Array.stretch!(*test_case)
42
40
  result.each_with_index do |r, i|
43
- r.should equal(test_case[i])
44
- r.should == expected[i]
41
+ expect(r).to equal(test_case[i])
42
+ expect(r).to eq(expected[i])
45
43
  end
46
44
  end
47
45
  end
@@ -52,8 +50,8 @@ describe Array do
52
50
  it "where #{msg}" do
53
51
  receiver, params = test_case[0], test_case[1..-1]
54
52
  result = receiver.stretch(*params)
55
- result.should_not equal(receiver)
56
- result.should == expected[0]
53
+ expect(result).not_to equal(receiver)
54
+ expect(result).to eq(expected[0])
57
55
  end
58
56
  end
59
57
  end
@@ -63,8 +61,8 @@ describe Array do
63
61
  it "where #{msg}" do
64
62
  receiver, params = test_case[0].dup, test_case[1..-1]
65
63
  result = receiver.stretch!(*params)
66
- result.should equal(receiver)
67
- result.should == expected[0]
64
+ expect(result).to equal(receiver)
65
+ expect(result).to eq(expected[0])
68
66
  end
69
67
  end
70
68
  end
@@ -89,7 +87,7 @@ describe Array do
89
87
  context '#zip_stretched' do
90
88
  ZIP_STRETCHED_CASES.each_slice(4) do |msg, receiver, params, expected|
91
89
  it "where #{msg}" do
92
- receiver.zip_stretched(*params).should == expected
90
+ expect(receiver.zip_stretched(*params)).to eq(expected)
93
91
  end
94
92
  end
95
93
  end