nutella 0.11.1 → 0.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2a987835f74115420358299ced5270af19f6f07d
4
- data.tar.gz: edb583cff27a3152e6482bd88850a3bba3803dce
3
+ metadata.gz: ef8876f7754fa5b0b422e9ab7ca092e9298ee436
4
+ data.tar.gz: 63636995f8ba8417326f52026f07ff0c5fc33272
5
5
  SHA512:
6
- metadata.gz: 0435310cb4a5e2589766dd4cc2330409bc9dfaf9043b557df8dd8a49053523770af93fe800961b1fd785f7adeda115ff16034e3d969743342521985c771d69a9
7
- data.tar.gz: fe0f174e16f1919b1e57ec5dbe0f4829b536b7ae489616a622dde02c56fba391b539a3f2f4fd03d3b53011efc9daea44f548d929c94501791e1dcf4ad9886b35
6
+ metadata.gz: 77c51d26b2d0af83884a6e188993e5c4e58d3b4e71bd3bb59310660820c37082dbcdba45e31529c02c50c0346d6927ea09374c9aaa29c5e3d4b2e250e50ed68b
7
+ data.tar.gz: bd3e50152263964033c4cf070c8d7c4c2208b2f32d319f56f47164026cf85d07aabace679a7816d7bd264c5acfb7e58d7d8a79ef3795c7d40611720295915ece
@@ -0,0 +1,41 @@
1
+ class Module
2
+ # A DRYer way to create a constructor where all of its arguments are assigned
3
+ # to instance variables of the same name.
4
+ #
5
+ # @example Comparison of constructor creation with and without Nutella
6
+ # # Pure Ruby
7
+ # class Test
8
+ # def initialize(a, b, c, d)
9
+ # @a, @b, @c, @d = a, b, c, d
10
+ # end
11
+ # end
12
+ # Test.new(0, 0, 0, 0).instance_variables # => [:@a, :@b, :@c, :@d]
13
+ #
14
+ # # Ruby with Nutella
15
+ # class Test
16
+ # initializer *%i[a b c d]
17
+ # end
18
+ # Test.new(0, 0, 0, 0).instance_variables # => [:@a, :@b, :@c, :@d]
19
+ #
20
+ # # It can also take a block with additional code to run
21
+ # class Test
22
+ # initializer :a, :b do
23
+ # @in_block = 0
24
+ # end
25
+ # end
26
+ # Test.new(0, 0).instance_variables # => [:@a, :@b, :@in_block]
27
+ #
28
+ # @param [Array] args the names of the arguments to the constructor as symbols
29
+ # @yield code to be executed on construction
30
+ def initializer(*args, &block)
31
+ define_method :initialize do |*input|
32
+ (input.last.is_a?(Hash) \
33
+ ? input[-1]
34
+ : Hash[args.zip input]).each do |name, value|
35
+ instance_variable_set "@#{name}", value
36
+ end
37
+
38
+ instance_eval(&block) if block_given?
39
+ end
40
+ end
41
+ end
@@ -13,8 +13,12 @@ class String
13
13
  #
14
14
  # @return [String] the string with excess leading whitespace stripped
15
15
  def heredoc
16
- gsub /^[ \t]{#{scan(/^[ \t]*(?=\S)/).min.size}}/, ""
16
+ gsub /^[ \t]{#{scan(/^[ \t]*(?=\S)/).min.size || 0}}/, ""
17
17
  end
18
18
  alias format_heredoc heredoc
19
19
  alias strip_heredoc heredoc
20
+
21
+ def in_heredoc indentation
22
+ lines[1..-1].map { |line| line.prepend " " * indentation }.join "\n"
23
+ end
20
24
  end
@@ -1,4 +1,4 @@
1
1
  module Nutella
2
2
  # The current version of Nutella.
3
- VERSION = "0.11.1"
3
+ VERSION = "0.12"
4
4
  end
data/nutella.gemspec CHANGED
@@ -20,10 +20,10 @@ Gem::Specification.new do |gem|
20
20
  ]
21
21
 
22
22
  gem.required_ruby_version = "~> 2.0"
23
- gem.add_development_dependency "fuubar", "~> 1.1"
23
+ gem.add_development_dependency "fuubar", "~> 2.0"
24
24
  gem.add_development_dependency "rake", "~> 10.0"
25
25
  gem.add_development_dependency "redcarpet", "~> 2.2"
26
26
  gem.add_development_dependency "rdoc", "~> 3.12"
27
- gem.add_development_dependency "rspec", "~> 2.11"
27
+ gem.add_development_dependency "rspec", "~> 3.1"
28
28
  gem.add_development_dependency "yard", "~> 0.8"
29
29
  end
@@ -15,19 +15,19 @@ describe Enumerable do
15
15
 
16
16
  it "works for a function that takes one argument" do
17
17
  testers.apply :increment_value
18
- testers.map(&:value).should == [6] * 5
18
+ expect(testers.map(&:value)).to eq([6] * 5)
19
19
  end
20
20
 
21
21
  context "with a function that takes two arguments" do
22
22
  it "allows multi-dimensional arrays" do
23
23
  multi = testers.zip([2] * 5)
24
24
  multi.apply :increment_value
25
- multi.each { |arr| arr.first.value.should == 7 }
25
+ multi.each { |arr| expect(arr.first.value).to eq(7) }
26
26
  end
27
27
 
28
28
  it "allows multiple arguments" do
29
29
  testers.apply :increment_value, 2
30
- testers.map(&:value).should == [7] * 5
30
+ expect(testers.map(&:value)).to eq([7] * 5)
31
31
  end
32
32
  end
33
33
 
@@ -35,58 +35,58 @@ describe Enumerable do
35
35
  it "allows multi-dimensional arrays" do
36
36
  multi = testers.map { |elem| [elem, 2, 2] }
37
37
  multi.apply :increment_value
38
- multi.each { |arr| arr.first.value.should == 9 }
38
+ multi.each { |arr| expect(arr.first.value).to eq(9) }
39
39
  end
40
40
 
41
41
  it "allows multiple arguments" do
42
42
  testers.apply :increment_value, 2, 2
43
- testers.map(&:value).should == [9] * 5
43
+ expect(testers.map(&:value)).to eq([9] * 5)
44
44
  end
45
45
 
46
46
  it "allows multi-dimensional arrays with multiple arguments" do
47
47
  multi = testers.zip([2] * 5)
48
48
  multi.apply :increment_value, 2
49
- multi.each { |arr| arr.first.value.should == 9 }
49
+ multi.each { |arr| expect(arr.first.value).to eq(9) }
50
50
  end
51
51
  end
52
52
  end
53
53
 
54
54
  describe "#exclude?" do
55
55
  it "returns true if the collection does not contain the input" do
56
- [1, 2, 3].exclude?(4).should be_true
56
+ expect([1, 2, 3].exclude?(4)).to be_truthy
57
57
  end
58
58
 
59
59
  it "returns false if the collection contains the input" do
60
- [1, 2, 3].exclude?(2).should be_false
60
+ expect([1, 2, 3].exclude?(2)).to be_falsey
61
61
  end
62
62
  end
63
63
 
64
64
  describe "#group" do
65
65
  it "groups elements" do
66
- [].group(2).should == []
67
- [1, 2].group(2).should == [[1, 2]]
68
- (1..4).group(2).should == [[1, 2], [3, 4]]
69
- (1..9).group(3).should == [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
66
+ expect([].group(2)).to eq([])
67
+ expect([1, 2].group(2)).to eq([[1, 2]])
68
+ expect((1..4).group(2)).to eq([[1, 2], [3, 4]])
69
+ expect((1..9).group(3)).to eq([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
70
70
  end
71
71
 
72
72
  it "puts all excess into the last group" do
73
- [1, 2].group(4).should == [[1, 2]]
74
- (1..8).group(3).should == [[1, 2, 3], [4, 5, 6], [7, 8]]
73
+ expect([1, 2].group(4)).to eq([[1, 2]])
74
+ expect((1..8).group(3)).to eq([[1, 2, 3], [4, 5, 6], [7, 8]])
75
75
  end
76
76
 
77
77
  it "discards all excess if instructed to" do
78
- (1..3).group(2, true).should == [[1, 2]]
79
- (1..8).group(3, true).should == [[1, 2, 3], [4, 5, 6]]
78
+ expect((1..3).group(2, true)).to eq([[1, 2]])
79
+ expect((1..8).group(3, true)).to eq([[1, 2, 3], [4, 5, 6]])
80
80
  end
81
81
 
82
82
  it "does not discard anything if there is no excess" do
83
- (1..4).group(2, true).should == [[1, 2], [3, 4]]
83
+ expect((1..4).group(2, true)).to eq([[1, 2], [3, 4]])
84
84
  end
85
85
 
86
86
  it "does not modify in place" do
87
87
  arr = (1..10).to_a
88
88
  arr.group 2
89
- arr.should == (1..10).to_a
89
+ expect(arr).to eq((1..10).to_a)
90
90
  end
91
91
  end
92
92
 
@@ -98,18 +98,18 @@ describe Enumerable do
98
98
  end
99
99
 
100
100
  it "returns the modified string" do
101
- arr.group!(2).should == arr
101
+ expect(arr.group!(2)).to eq(arr)
102
102
  end
103
103
 
104
104
  it "returns nil if nothing was modified" do
105
- [].group!(2).should be_nil
105
+ expect([].group!(2)).to be_nil
106
106
  end
107
107
  end
108
108
 
109
109
  describe "#map" do
110
110
  it "takes a symbol and maps that method" do
111
- [1, 2, 3].map(:succ).should == [2, 3, 4]
112
- (1..10).map(:succ).should == (2..11).to_a
111
+ expect([1, 2, 3].map(:succ)).to eq([2, 3, 4])
112
+ expect((1..10).map(:succ)).to eq((2..11).to_a)
113
113
  end
114
114
 
115
115
  it "passes additional arguments into the method in the first argument" do
@@ -117,49 +117,49 @@ describe Enumerable do
117
117
  alpha = ("a".."z")
118
118
  args = [/[aeiou]/, "x"]
119
119
 
120
- arr.map(:gsub, *args).should == arr.map { |e| e.gsub *args }
121
- alpha.map(:gsub, *args).should == alpha.map { |e| e.gsub *args }
120
+ expect(arr.map(:gsub, *args)).to eq(arr.map { |e| e.gsub *args })
121
+ expect(alpha.map(:gsub, *args)).to eq(alpha.map { |e| e.gsub *args })
122
122
  end
123
123
 
124
124
  context "when using as the original #map" do
125
125
  it "doesn't break passing in blocks" do
126
- [1, 2, 3].map { |n| n + 1 }.should == [2, 3, 4]
126
+ expect([1, 2, 3].map { |n| n + 1 }).to eq([2, 3, 4])
127
127
  end
128
128
 
129
129
  it "doesn't break when passing in Proc" do
130
- [1, 2, 3].map(&:succ).should == [2, 3, 4]
130
+ expect([1, 2, 3].map(&:succ)).to eq([2, 3, 4])
131
131
  end
132
132
  end
133
133
  end
134
134
 
135
135
  describe "#sum" do
136
136
  it "returns the sum of elements" do
137
- [].sum.should == 0
138
- [5].sum.should == 5
139
- [1, 2, 3].sum.should == 6
140
- (1..4).sum.should == 10
137
+ expect([].sum).to eq(0)
138
+ expect([5].sum).to eq(5)
139
+ expect([1, 2, 3].sum).to eq(6)
140
+ expect((1..4).sum).to eq(10)
141
141
  end
142
142
 
143
143
  it "flattens the elements before adding" do
144
- [[4, 5], 1].sum.should == 10
145
- [[1, 2, 3], [4, 5]].sum.should == 15
144
+ expect([[4, 5], 1].sum).to eq(10)
145
+ expect([[1, 2, 3], [4, 5]].sum).to eq(15)
146
146
  end
147
147
 
148
148
  it "filters out all non-numbers" do
149
- { a: 2, b: 4 }.sum.should == 6
150
- [1, "str", 4].sum.should == 5
151
- ["no numbers"].sum.should == 0
149
+ expect({ a: 2, b: 4 }.sum).to eq(6)
150
+ expect([1, "str", 4].sum).to eq(5)
151
+ expect(["no numbers"].sum).to eq(0)
152
152
  end
153
153
 
154
154
  context "with a block" do
155
155
  it "returns the sum of the elements that pass the filter block" do
156
- (1..10).sum(&:even?).should == 30
157
- (1..10).sum { |n| n % 3 == 0 }.should == 18
156
+ expect((1..10).sum(&:even?)).to eq(30)
157
+ expect((1..10).sum { |n| n % 3 == 0 }).to eq(18)
158
158
  end
159
159
 
160
160
  it "still filters out all non-numbers" do
161
- { a: 1, b: 2, c: 3 }.sum(&:odd?).should == 4
162
- [2, "str", 4, 7].sum(&:even?).should == 6
161
+ expect({ a: 1, b: 2, c: 3 }.sum(&:odd?)).to eq(4)
162
+ expect([2, "str", 4, 7].sum(&:even?)).to eq(6)
163
163
  end
164
164
  end
165
165
  end
@@ -6,41 +6,41 @@ describe File do
6
6
  describe "::human_size" do
7
7
  context "when given a Numeric" do
8
8
  it "does not change bytes" do
9
- File.human_size(150.bytes).should == "150 Bytes"
9
+ expect(File.human_size(150.bytes)).to eq("150 Bytes")
10
10
  end
11
11
 
12
12
  it "changes kilobytes" do
13
- File.human_size(1.5.kilobytes).should == "1.5 KB"
13
+ expect(File.human_size(1.5.kilobytes)).to eq("1.5 KB")
14
14
  end
15
15
 
16
16
  it "changes megabytes" do
17
- File.human_size(1.5.megabytes).should == "1.5 MB"
17
+ expect(File.human_size(1.5.megabytes)).to eq("1.5 MB")
18
18
  end
19
19
 
20
20
  it "changes gigabytes" do
21
- File.human_size(1.5.gigabytes).should == "1.5 GB"
21
+ expect(File.human_size(1.5.gigabytes)).to eq("1.5 GB")
22
22
  end
23
23
 
24
24
  it "rounds down properly to the tenths" do
25
- File.human_size(1.72.megabytes).should == "1.7 MB"
25
+ expect(File.human_size(1.72.megabytes)).to eq("1.7 MB")
26
26
  end
27
27
 
28
28
  it "rounds up properly to the tenths" do
29
- File.human_size(1.78.megabytes).should == "1.8 MB"
29
+ expect(File.human_size(1.78.megabytes)).to eq("1.8 MB")
30
30
  end
31
31
 
32
32
  it "has a singular unit for 1 byte" do
33
- File.human_size(1.byte).should == "1 Byte"
33
+ expect(File.human_size(1.byte)).to eq("1 Byte")
34
34
  end
35
35
 
36
36
  it "returns 'Empty' for an empty file or a blank parameter" do
37
- File.human_size(0).should == "Empty"
38
- File.human_size(nil).should == "Empty"
37
+ expect(File.human_size(0)).to eq("Empty")
38
+ expect(File.human_size(nil)).to eq("Empty")
39
39
  end
40
40
 
41
41
  it "displays whole numbers without a decimal" do
42
- File.human_size(1.megabyte).should == "1 MB"
43
- File.human_size(24.gigabytes).should == "24 GB"
42
+ expect(File.human_size(1.megabyte)).to eq("1 MB")
43
+ expect(File.human_size(24.gigabytes)).to eq("24 GB")
44
44
  end
45
45
  end
46
46
 
@@ -48,7 +48,7 @@ describe File do
48
48
  it "detects empty files properly" do
49
49
  begin
50
50
  f = File.new("temp", "w")
51
- File.human_size(f).should == "Empty"
51
+ expect(File.human_size(f)).to eq("Empty")
52
52
  ensure
53
53
  File.delete "temp"
54
54
  end
@@ -57,10 +57,10 @@ describe File do
57
57
  it "detects the file size properly" do
58
58
  begin
59
59
  File.truncate(f = File.new("temp", "w"), 1.5.kilobytes)
60
- File.human_size(f).should == "1.5 KB"
60
+ expect(File.human_size(f)).to eq("1.5 KB")
61
61
 
62
62
  File.truncate(f = File.new("temp", "w"), 3.kilobytes)
63
- File.human_size(f).should == "3 KB"
63
+ expect(File.human_size(f)).to eq("3 KB")
64
64
  ensure
65
65
  File.delete "temp"
66
66
  end
@@ -71,10 +71,10 @@ describe File do
71
71
  it "detects the file size properly" do
72
72
  begin
73
73
  File.truncate(f = File.new("temp", "w"), 1.5.kilobytes)
74
- File.human_size("temp").should == "1.5 KB"
74
+ expect(File.human_size("temp")).to eq("1.5 KB")
75
75
 
76
76
  File.truncate(f = File.new("temp", "w"), 3.kilobytes)
77
- File.human_size("temp").should == "3 KB"
77
+ expect(File.human_size("temp")).to eq("3 KB")
78
78
  ensure
79
79
  File.delete "temp"
80
80
  end
@@ -85,7 +85,7 @@ describe File do
85
85
  describe "#human_size" do
86
86
  it "detects empty files properly" do
87
87
  begin
88
- File.new("temp", "w").human_size.should == "Empty"
88
+ expect(File.new("temp", "w").human_size).to eq("Empty")
89
89
  ensure
90
90
  File.delete "temp"
91
91
  end
@@ -94,10 +94,10 @@ describe File do
94
94
  it "detects the file size properly" do
95
95
  begin
96
96
  File.truncate(f = File.new("temp", "w"), 1.5.kilobytes)
97
- f.human_size.should == "1.5 KB"
97
+ expect(f.human_size).to eq("1.5 KB")
98
98
 
99
99
  File.truncate(f = File.new("temp", "w"), 3.kilobytes)
100
- f.human_size.should == "3 KB"
100
+ expect(f.human_size).to eq("3 KB")
101
101
  ensure
102
102
  File.delete "temp"
103
103
  end
@@ -11,17 +11,17 @@ describe Hash do
11
11
 
12
12
  describe "#grab" do
13
13
  it "selects the given items from a hash" do
14
- hash.slice(:a, :c).should == {a: 1, c: 3}
14
+ expect(hash.slice(:a, :c)).to eq({a: 1, c: 3})
15
15
  end
16
16
 
17
17
  it "skips items that do not exist in the hash" do
18
- hash.slice(:a, :d, :f).should == {a: 1, d: 4}
18
+ expect(hash.slice(:a, :d, :f)).to eq({a: 1, d: 4})
19
19
  end
20
20
 
21
21
  it "does not modify in place" do
22
22
  start = hash
23
23
  hash.slice :a, :b
24
- hash.should == start
24
+ expect(hash).to eq(start)
25
25
  end
26
26
  end
27
27
 
@@ -31,11 +31,11 @@ describe Hash do
31
31
  end
32
32
 
33
33
  it "returns the removed pairs" do
34
- hash.slice!(:a, :c).should == {b: 2, d: 4}
34
+ expect(hash.slice!(:a, :c)).to eq({b: 2, d: 4})
35
35
  end
36
36
 
37
37
  it "does not return pairs that did not affect the hash" do
38
- hash.slice!(:a, :c, :g).should == {b: 2, d: 4}
38
+ expect(hash.slice!(:a, :c, :g)).to eq({b: 2, d: 4})
39
39
  end
40
40
  end
41
41
  end
@@ -9,147 +9,147 @@ describe Integer do
9
9
 
10
10
  describe "#digits" do
11
11
  it "returns an array of the digits in the integer" do
12
- (0..9).each { |n| n.digits.should == [n] }
13
- 10.digits.should == [1, 0]
14
- 349.digits.should == [3, 4, 9]
15
- 1000.digits.should == [1, 0, 0, 0]
12
+ (0..9).each { |n| expect(n.digits).to eq([n]) }
13
+ expect(10.digits).to eq([1, 0])
14
+ expect(349.digits).to eq([3, 4, 9])
15
+ expect(1000.digits).to eq([1, 0, 0, 0])
16
16
  end
17
17
 
18
18
  it "trims the '-' from negative numbers" do
19
- -3.digits.should == [3]
20
- -20.digits.should == [2, 0]
19
+ expect(-3.digits).to eq([3])
20
+ expect(-20.digits).to eq([2, 0])
21
21
  end
22
22
  end
23
23
 
24
24
  describe "#ordinalize" do
25
25
  NUMBER_FORMATS.each do |cardinal, ordinal|
26
26
  it "returns the ordinal #{ordinal} for the integer #{cardinal}" do
27
- cardinal.ordinalize.should == ordinal
27
+ expect(cardinal.ordinalize).to eq(ordinal)
28
28
  end
29
29
  end
30
30
  end
31
31
 
32
32
  describe "#goes_into?" do
33
33
  it "returns true if the number goes evenly into the argument" do
34
- 5.goes_into?(10).should be_true
35
- 3.goes_into?(21).should be_true
36
- 25.goes_into?(100).should be_true
34
+ expect(5.goes_into?(10)).to be_truthy
35
+ expect(3.goes_into?(21)).to be_truthy
36
+ expect(25.goes_into?(100)).to be_truthy
37
37
  end
38
38
 
39
39
  it "returns false if the number does not go evenly in" do
40
- 3.goes_into?(10).should be_false
41
- 9.goes_into?(40).should be_false
42
- 10.goes_into?(5).should be_false
40
+ expect(3.goes_into?(10)).to be_falsey
41
+ expect(9.goes_into?(40)).to be_falsey
42
+ expect(10.goes_into?(5)).to be_falsey
43
43
  end
44
44
 
45
45
  context "when passing in zero" do
46
46
  it "returns false if one tries to divide by zero" do
47
- 0.goes_into?(20).should be_false
48
- 0.goes_into?(30).should be_false
47
+ expect(0.goes_into?(20)).to be_falsey
48
+ expect(0.goes_into?(30)).to be_falsey
49
49
  end
50
50
 
51
51
  it "allows zero to go into zero" do
52
- 0.goes_into?(0).should be_true
52
+ expect(0.goes_into?(0)).to be_truthy
53
53
  end
54
54
  end
55
55
 
56
56
  context "with multiple arguments" do
57
57
  it "returns true if all arguments succeed" do
58
- 5.goes_into?(10, 15, 50).should be_true
59
- 2.goes_into?(2, 4, 10).should be_true
58
+ expect(5.goes_into?(10, 15, 50)).to be_truthy
59
+ expect(2.goes_into?(2, 4, 10)).to be_truthy
60
60
  end
61
61
 
62
62
  it "returns false if only some arguments succeed" do
63
- 5.goes_into?(10, 12, 15).should be_false
64
- 8.goes_into?(4, 16).should be_false
63
+ expect(5.goes_into?(10, 12, 15)).to be_falsey
64
+ expect(8.goes_into?(4, 16)).to be_falsey
65
65
  end
66
66
 
67
67
  it "returns false if no arguments succeed" do
68
- 3.goes_into?(8, 16, 20).should be_false
69
- 6.goes_into?(5, 10, 15).should be_false
68
+ expect(3.goes_into?(8, 16, 20)).to be_falsey
69
+ expect(6.goes_into?(5, 10, 15)).to be_falsey
70
70
  end
71
71
  end
72
72
  end
73
73
 
74
74
  describe "#goes_into_any?" do
75
75
  it "returns true if all arguments succeed" do
76
- 5.goes_into_any?(10, 15, 50).should be_true
77
- 2.goes_into_any?(2, 4, 10).should be_true
76
+ expect(5.goes_into_any?(10, 15, 50)).to be_truthy
77
+ expect(2.goes_into_any?(2, 4, 10)).to be_truthy
78
78
  end
79
79
 
80
80
  it "returns true if only some arguments succeed" do
81
- 5.goes_into_any?(10, 12, 15).should be_true
82
- 8.goes_into_any?(4, 16).should be_true
81
+ expect(5.goes_into_any?(10, 12, 15)).to be_truthy
82
+ expect(8.goes_into_any?(4, 16)).to be_truthy
83
83
  end
84
84
 
85
85
  it "returns false if no arguments succeed" do
86
- 3.goes_into_any?(8, 16, 20).should be_false
87
- 6.goes_into_any?(5, 10, 15).should be_false
86
+ expect(3.goes_into_any?(8, 16, 20)).to be_falsey
87
+ expect(6.goes_into_any?(5, 10, 15)).to be_falsey
88
88
  end
89
89
  end
90
90
 
91
91
  describe "#multiple_of?" do
92
92
  it "returns true if the number is evenly divisible" do
93
- 5.should be_multiple_of(5)
94
- 15.should be_multiple_of(5)
95
- 10.should be_multiple_of(2)
96
- 6000.should be_multiple_of(6)
93
+ expect(5).to be_multiple_of(5)
94
+ expect(15).to be_multiple_of(5)
95
+ expect(10).to be_multiple_of(2)
96
+ expect(6000).to be_multiple_of(6)
97
97
  end
98
98
 
99
99
  it "returns false if the number is not evenly divisible" do
100
- 20.should_not be_multiple_of(7)
101
- 4.should_not be_multiple_of(3)
102
- 5.should_not be_multiple_of(15)
103
- 100.should_not be_multiple_of(3)
100
+ expect(20).not_to be_multiple_of(7)
101
+ expect(4).not_to be_multiple_of(3)
102
+ expect(5).not_to be_multiple_of(15)
103
+ expect(100).not_to be_multiple_of(3)
104
104
  end
105
105
 
106
106
  context "when passing in zero" do
107
107
  it "returns false if one tries to divide by zero" do
108
- 20.should_not be_multiple_of(0)
109
- 30.should_not be_multiple_of(0)
108
+ expect(20).not_to be_multiple_of(0)
109
+ expect(30).not_to be_multiple_of(0)
110
110
  end
111
111
 
112
112
  it "allows zero to go into zero" do
113
- 0.should be_multiple_of(0)
113
+ expect(0).to be_multiple_of(0)
114
114
  end
115
115
  end
116
116
 
117
117
  context "with multiple arguments" do
118
118
  it "returns true if evenly divisible by all arguments" do
119
- 15.should be_multiple_of(3, 15)
120
- 100.should be_multiple_of(2, 5, 25)
121
- 0.should be_multiple_of(0, 1, 2)
119
+ expect(15).to be_multiple_of(3, 15)
120
+ expect(100).to be_multiple_of(2, 5, 25)
121
+ expect(0).to be_multiple_of(0, 1, 2)
122
122
  end
123
123
 
124
124
  it "returns false if evenly divisible by only some arguments" do
125
- 15.should_not be_multiple_of(2, 3)
126
- 12.should_not be_multiple_of(3, 4, 6, 8)
127
- 10.should_not be_multiple_of(0, 5)
125
+ expect(15).not_to be_multiple_of(2, 3)
126
+ expect(12).not_to be_multiple_of(3, 4, 6, 8)
127
+ expect(10).not_to be_multiple_of(0, 5)
128
128
  end
129
129
 
130
130
  it "returns false if evenly divisible by none of the arguments" do
131
- 6.should_not be_multiple_of(4, 5)
132
- 17.should_not be_multiple_of(2, 4)
131
+ expect(6).not_to be_multiple_of(4, 5)
132
+ expect(17).not_to be_multiple_of(2, 4)
133
133
  end
134
134
  end
135
135
  end
136
136
 
137
137
  describe "#multiple_of_any?" do
138
138
  it "returns true if evenly divisible by all arguments" do
139
- 15.should be_multiple_of_any(3, 15)
140
- 100.should be_multiple_of_any(2, 5, 25)
141
- 0.should be_multiple_of_any(0, 1, 2)
139
+ expect(15).to be_multiple_of_any(3, 15)
140
+ expect(100).to be_multiple_of_any(2, 5, 25)
141
+ expect(0).to be_multiple_of_any(0, 1, 2)
142
142
  end
143
143
 
144
144
  it "returns true if evenly divisible by only some arguments" do
145
- 15.should be_multiple_of_any(2, 3)
146
- 12.should be_multiple_of_any(3, 4, 6, 8)
147
- 10.should be_multiple_of_any(0, 5)
145
+ expect(15).to be_multiple_of_any(2, 3)
146
+ expect(12).to be_multiple_of_any(3, 4, 6, 8)
147
+ expect(10).to be_multiple_of_any(0, 5)
148
148
  end
149
149
 
150
150
  it "returns false if evenly divisible by none of the arguments" do
151
- 6.should_not be_multiple_of_any(4, 5)
152
- 17.should_not be_multiple_of_any(2, 4)
151
+ expect(6).not_to be_multiple_of_any(4, 5)
152
+ expect(17).not_to be_multiple_of_any(2, 4)
153
153
  end
154
154
  end
155
155
  end
@@ -0,0 +1,23 @@
1
+ require "spec_helper"
2
+ require "nutella/core_ext/module"
3
+
4
+ describe Module do
5
+ describe "initializer" do
6
+ it "defines the instance variables" do
7
+ expect(InitTest.new *INIT_VALUES).
8
+ to have_instance_variables(*INIT_INSTANCE_VARS)
9
+ end
10
+
11
+ context "with a block" do
12
+ let!(:t) { InitBlockTest.new *INIT_VALUES }
13
+
14
+ it "defines the instance variables" do
15
+ expect(t).to have_instance_variables(*INIT_INSTANCE_VARS)
16
+ end
17
+
18
+ it "runs the block" do
19
+ expect(t.block_run?).to be true
20
+ end
21
+ end
22
+ end
23
+ end
@@ -11,57 +11,57 @@ describe Numeric do
11
11
 
12
12
  describe "#percent" do
13
13
  it "returns the percent for an integer" do
14
- 5.percent.should == 0.05
15
- 15.percent.should == 0.15
16
- 50.percent.should == 0.5
17
- 125.percent.should == 1.25
14
+ expect(5.percent).to eq(0.05)
15
+ expect(15.percent).to eq(0.15)
16
+ expect(50.percent).to eq(0.5)
17
+ expect(125.percent).to eq(1.25)
18
18
  end
19
19
 
20
20
  it "returns an integer for multiples of 100" do
21
- 100.percent.should == 1
22
- 500.percent.should == 5
21
+ expect(100.percent).to eq(1)
22
+ expect(500.percent).to eq(5)
23
23
  end
24
24
 
25
25
  it "returns the percent for a floating point" do
26
- 0.5.percent.should == 0.005
27
- 5.5.percent.should == 0.055
28
- 10.5.percent.should == 0.105
26
+ expect(0.5.percent).to eq(0.005)
27
+ expect(5.5.percent).to eq(0.055)
28
+ expect(10.5.percent).to eq(0.105)
29
29
  end
30
30
 
31
31
  it "returns an integer for floating point multiples of 100" do
32
- 100.0.percent.should == 1
32
+ expect(100.0.percent).to eq(1)
33
33
  end
34
34
 
35
35
  it "returns zero for 0" do
36
- 0.percent.should be_zero
36
+ expect(0.percent).to be_zero
37
37
  end
38
38
  end
39
39
 
40
40
  describe "#sanity_check_min" do
41
41
  it "returns the parameter if the number is lower" do
42
- 5.sanity_check_min(7).should == 7
42
+ expect(5.sanity_check_min(7)).to eq(7)
43
43
  end
44
44
 
45
45
  it "doesn't change anything if the number is equal" do
46
- 5.sanity_check_min(5).should == 5
46
+ expect(5.sanity_check_min(5)).to eq(5)
47
47
  end
48
48
 
49
49
  it "returns the number if the number is higher" do
50
- 5.sanity_check_min(2).should == 5
50
+ expect(5.sanity_check_min(2)).to eq(5)
51
51
  end
52
52
  end
53
53
 
54
54
  describe "#sanity_check_max" do
55
55
  it "returns the parameter if the number is higher" do
56
- 5.sanity_check_max(2).should == 2
56
+ expect(5.sanity_check_max(2)).to eq(2)
57
57
  end
58
58
 
59
59
  it "doesn't change anything if the number is equal" do
60
- 5.sanity_check_max(5).should == 5
60
+ expect(5.sanity_check_max(5)).to eq(5)
61
61
  end
62
62
 
63
63
  it "returns the number if the number is lower" do
64
- 5.sanity_check_max(7).should == 5
64
+ expect(5.sanity_check_max(7)).to eq(5)
65
65
  end
66
66
  end
67
67
  end
@@ -8,44 +8,44 @@ describe Object do
8
8
 
9
9
  describe "#blank?" do
10
10
  it "is blank when nil" do
11
- nil.should be_blank
11
+ expect(nil).to be_blank
12
12
  end
13
13
 
14
14
  it "is blank when false" do
15
- false.should be_blank
15
+ expect(false).to be_blank
16
16
  end
17
17
 
18
18
  it "is not blank when true" do
19
- true.should_not be_blank
19
+ expect(true).not_to be_blank
20
20
  end
21
21
 
22
22
  it "is not blank when numeric" do
23
- [0, 1].each { |n| n.should_not be_blank }
23
+ [0, 1].each { |n| expect(n).not_to be_blank }
24
24
  end
25
25
 
26
26
  context "when a string" do
27
27
  it "is blank if the string is empty" do
28
- "".should be_blank
28
+ expect("").to be_blank
29
29
  end
30
30
 
31
31
  it "is blank if only whitespace" do
32
- [" ", "\n \t"].each { |str| str.should be_blank }
33
- " something here ".should_not be_blank
32
+ [" ", "\n \t"].each { |str| expect(str).to be_blank }
33
+ expect(" something here ").not_to be_blank
34
34
  end
35
35
 
36
36
  it "is not blank if the string has content" do
37
- "string".should_not be_blank
37
+ expect("string").not_to be_blank
38
38
  end
39
39
  end
40
40
 
41
41
  context "when a collection" do
42
42
  it "is blank if the collection is empty" do
43
- [[], {}].each { |collection| collection.should be_blank }
43
+ [[], {}].each { |collection| expect(collection).to be_blank }
44
44
  end
45
45
 
46
46
  it "is not blank if there are elements in the collection" do
47
47
  [[1, 2, 3], { 1 => 2, 3 => 4 }].each do |collection|
48
- collection.should_not be_blank
48
+ expect(collection).not_to be_blank
49
49
  end
50
50
  end
51
51
  end
@@ -53,22 +53,22 @@ describe Object do
53
53
 
54
54
  describe "#present?" do
55
55
  it "is the inverse of #blank?" do
56
- [0, 1].each { |n| n.should be_present }
57
- [[], {}].each { |collection| collection.should_not be_present }
58
- ["", " "].each { |str| str.should_not be_present }
59
- ["str", " str "].each { |str| str.should be_present }
56
+ [0, 1].each { |n| expect(n).to be_present }
57
+ [[], {}].each { |collection| expect(collection).not_to be_present }
58
+ ["", " "].each { |str| expect(str).not_to be_present }
59
+ ["str", " str "].each { |str| expect(str).to be_present }
60
60
  end
61
61
  end
62
62
 
63
63
  describe "#presence" do
64
64
  it "returns the object if the object is present" do
65
- 1.presence.should == 1
66
- "str".presence.should == "str"
65
+ expect(1.presence).to eq(1)
66
+ expect("str".presence).to eq("str")
67
67
  end
68
68
 
69
69
  it "returns nil if the object is not present" do
70
- "".presence.should be_nil
71
- false.presence.should be_nil
70
+ expect("".presence).to be_nil
71
+ expect(false.presence).to be_nil
72
72
  end
73
73
  end
74
74
  end
@@ -1,7 +1,7 @@
1
1
  require "spec_helper"
2
2
  require "nutella/core_ext/string"
3
3
 
4
- describe Enumerable do
4
+ describe String do
5
5
  describe "aliases" do
6
6
  test_alias String, :contains?, :include?
7
7
  test_alias String, :includes?, :include?
@@ -15,11 +15,11 @@ describe Enumerable do
15
15
 
16
16
  describe "#exclude?" do
17
17
  it "returns true if the string does not contain the input string" do
18
- "hello".exclude?("test").should be_true
18
+ expect("hello".exclude?("test")).to be_truthy
19
19
  end
20
20
 
21
21
  it "returns false if the string contains the input string" do
22
- "hello".exclude?("llo").should be_false
22
+ expect("hello".exclude?("llo")).to be_falsey
23
23
  end
24
24
  end
25
25
 
@@ -35,7 +35,7 @@ describe Enumerable do
35
35
  Left-aligned again.
36
36
  EOS
37
37
 
38
- test.should == <<EOS
38
+ expect(test).to eq <<EOS
39
39
  This is a test of String#heredoc.
40
40
  This text should be left-aligned.
41
41
  This text is indented by four spaces.
@@ -45,5 +45,32 @@ This text should be left-aligned.
45
45
  Left-aligned again.
46
46
  EOS
47
47
  end
48
+
49
+ =begin
50
+ it "works with string interpolation" do
51
+ short = "Test"
52
+ inner = <<-EOS.heredoc.strip
53
+ This text should be left-aligned.
54
+ This is indented by two.
55
+ Last line of the inner string, left-aligned.
56
+ EOS
57
+
58
+ test = <<-EOS.heredoc
59
+ Testing short in-line: #{short}
60
+ Testing next-line:
61
+ #{inner.in_heredoc 8}
62
+ Ending interpolation test.
63
+ EOS
64
+
65
+ test.should == <<EOS
66
+ Testing short in-line: Test
67
+ Testing next-line:
68
+ This text should be left-aligned.
69
+ This is indented by two.
70
+ Last line of the inner string, left-aligned.
71
+ Ending interpolation test.
72
+ EOS
73
+ end
74
+ =end
48
75
  end
49
76
  end
@@ -2,7 +2,7 @@
2
2
  def test_alias(cls, method_a, method_b)
3
3
  describe "##{method_a.to_s}" do
4
4
  it "is an alias of ##{method_b.to_s}" do
5
- cls.instance_method(method_a).should === cls.instance_method(method_b)
5
+ expect(cls.instance_method method_a).to eq(cls.instance_method(method_b))
6
6
  end
7
7
  end
8
8
  end
@@ -0,0 +1,20 @@
1
+ require "nutella/core_ext/module"
2
+
3
+ INIT_ARGS = %i[a b c]
4
+ INIT_INSTANCE_VARS = INIT_ARGS.map { |arg| arg.to_s.prepend("@").to_sym }
5
+
6
+ INIT_VALUES = [0] * INIT_ARGS.size
7
+
8
+ class InitTest
9
+ initializer *INIT_ARGS
10
+ end
11
+
12
+ class InitBlockTest
13
+ initializer *INIT_ARGS do
14
+ @block_run = true
15
+ end
16
+
17
+ def block_run?
18
+ @block_run
19
+ end
20
+ end
@@ -0,0 +1,17 @@
1
+ RSpec::Matchers.define :have_instance_variables do |*vars|
2
+ match do |target|
3
+ (vars - target.instance_variables).empty?
4
+ end
5
+
6
+ failure_message do |target|
7
+ "expected #{target.inspect} to have all of the following instance variables: " +
8
+ "\n #{vars.inspect}" +
9
+ "\nInstead it contains:\n #{target.instance_variables.inspect}"
10
+ end
11
+
12
+ failure_message_when_negated do |target|
13
+ "expected #{target.inspect} to not have any of the following instance variables: " +
14
+ "\n #{vars.inspect}" +
15
+ "\nIt contains:\n #{target.instance_variables.inspect}"
16
+ end
17
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nutella
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.1
4
+ version: '0.12'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vinny Diehl
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-15 00:00:00.000000000 Z
11
+ date: 2014-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fuubar
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: '1.1'
19
+ version: '2.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
- version: '1.1'
26
+ version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - ~>
74
74
  - !ruby/object:Gem::Version
75
- version: '2.11'
75
+ version: '3.1'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - ~>
81
81
  - !ruby/object:Gem::Version
82
- version: '2.11'
82
+ version: '3.1'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: yard
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -104,6 +104,7 @@ files:
104
104
  - lib/nutella/version.rb
105
105
  - lib/nutella/input.rb
106
106
  - lib/nutella/core_ext/enumerable.rb
107
+ - lib/nutella/core_ext/module.rb
107
108
  - lib/nutella/core_ext/string.rb
108
109
  - lib/nutella/core_ext/string/exclude.rb
109
110
  - lib/nutella/core_ext/string/colour.rb
@@ -130,6 +131,7 @@ files:
130
131
  - lib/nutella.rb
131
132
  - spec/nutella/core_ext/file_spec.rb
132
133
  - spec/nutella/core_ext/string_spec.rb
134
+ - spec/nutella/core_ext/module_spec.rb
133
135
  - spec/nutella/core_ext/enumerable_spec.rb
134
136
  - spec/nutella/core_ext/numeric_spec.rb
135
137
  - spec/nutella/core_ext/hash_spec.rb
@@ -138,6 +140,8 @@ files:
138
140
  - spec/support/alias.rb
139
141
  - spec/support/number_formats.rb
140
142
  - spec/support/apply_tester.rb
143
+ - spec/support/matchers.rb
144
+ - spec/support/initializer_testers.rb
141
145
  - spec/spec_helper.rb
142
146
  - .rspec
143
147
  - LICENSE
@@ -171,6 +175,7 @@ summary: Spread some Nutella on Ruby to sweeten up its functionality.
171
175
  test_files:
172
176
  - spec/nutella/core_ext/file_spec.rb
173
177
  - spec/nutella/core_ext/string_spec.rb
178
+ - spec/nutella/core_ext/module_spec.rb
174
179
  - spec/nutella/core_ext/enumerable_spec.rb
175
180
  - spec/nutella/core_ext/numeric_spec.rb
176
181
  - spec/nutella/core_ext/hash_spec.rb
@@ -179,5 +184,7 @@ test_files:
179
184
  - spec/support/alias.rb
180
185
  - spec/support/number_formats.rb
181
186
  - spec/support/apply_tester.rb
187
+ - spec/support/matchers.rb
188
+ - spec/support/initializer_testers.rb
182
189
  - spec/spec_helper.rb
183
190
  has_rdoc: