Log In
Log In
Places
All Projects
Status Monitor
Collapse sidebar
obs:server:fedora:2.8
rubygem-powerpack
rubygem-powerpack-0002-Fixing-the-tests-and-the...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File rubygem-powerpack-0002-Fixing-the-tests-and-the-definition-of-sum.patch of Package rubygem-powerpack
From 649d4553f5752928c7c2ae36c42ff176c93b2940 Mon Sep 17 00:00:00 2001 From: Joshua Cavin <jcavin9@gmail.com> Date: Tue, 18 Jul 2017 06:58:59 -0700 Subject: [PATCH] Fixing the tests and the definition of sum --- lib/powerpack/enumerable/sum.rb | 7 +- spec/powerpack/array/butfirst_spec.rb | 14 +- spec/powerpack/array/butlast_spec.rb | 14 +- spec/powerpack/enumerable/average_spec.rb | 26 +-- spec/powerpack/enumerable/drop_last_spec.rb | 20 ++- spec/powerpack/enumerable/drop_last_while_spec.rb | 8 +- spec/powerpack/enumerable/exactly_spec.rb | 70 ++++---- spec/powerpack/enumerable/frequencies_spec.rb | 28 +-- spec/powerpack/enumerable/several_spec.rb | 36 ++-- spec/powerpack/enumerable/sum_spec.rb | 12 +- spec/powerpack/enumerable/take_last_spec.rb | 20 ++- spec/powerpack/enumerable/take_last_while_spec.rb | 8 +- spec/powerpack/hash/symbolize_keys_spec.rb | 18 +- spec/powerpack/numeric/neg_spec.rb | 34 ++-- spec/powerpack/numeric/pos_spec.rb | 34 ++-- spec/powerpack/numeric/scale_spec.rb | 204 +++++++++++----------- spec/powerpack/string/ascii_only_spec.rb | 2 +- spec/powerpack/string/blank_spec.rb | 20 ++- spec/powerpack/string/format_spec.rb | 16 +- spec/powerpack/string/remove_prefix_spec.rb | 16 +- spec/powerpack/string/remove_spec.rb | 16 +- spec/powerpack/string/remove_suffix_spec.rb | 16 +- spec/powerpack/string/squish_spec.rb | 28 +-- spec/powerpack/string/strip_indent_spec.rb | 16 +- spec/powerpack/string/strip_margin_spec.rb | 40 +++-- 25 files changed, 385 insertions(+), 338 deletions(-) diff --git a/lib/powerpack/enumerable/sum.rb b/lib/powerpack/enumerable/sum.rb index d8b6814..72f9087 100644 --- a/lib/powerpack/enumerable/sum.rb +++ b/lib/powerpack/enumerable/sum.rb @@ -12,10 +12,9 @@ unless Enumerable.method_defined? :sum # [1, 2, 3].sum #=> 6 # ["a", "b", "c"].sum #=> "abc" # [[1], [2], [3]].sum #=> [1, 2, 3] - # [].sum #=> nil - # [].sum(0) #=> 0 - def sum(default = nil) - reduce(&:+) || default + # [].sum #=> 0 + def sum + reduce(&:+) || 0 end end end diff --git a/spec/powerpack/array/butfirst_spec.rb b/spec/powerpack/array/butfirst_spec.rb index 2bc9ea5..f4547bc 100644 --- a/spec/powerpack/array/butfirst_spec.rb +++ b/spec/powerpack/array/butfirst_spec.rb @@ -1,11 +1,13 @@ require 'spec_helper' -describe 'Array#butfirst' do - it 'returns an array without the first element' do - expect([1, 2, 3].butfirst).to eq([2, 3]) - end +unless Array.method_defined? :butfirst + describe 'Array#butfirst' do + it 'returns an array without the first element' do + expect([1, 2, 3].butfirst).to eq([2, 3]) + end - it 'returns nil for empty lists' do - expect([].butfirst).to be_nil + it 'returns nil for empty lists' do + expect([].butfirst).to be_nil + end end end diff --git a/spec/powerpack/array/butlast_spec.rb b/spec/powerpack/array/butlast_spec.rb index 5271ecb..2f64332 100644 --- a/spec/powerpack/array/butlast_spec.rb +++ b/spec/powerpack/array/butlast_spec.rb @@ -1,11 +1,13 @@ require 'spec_helper' -describe 'Array#butlast' do - it 'returns an array without the last element' do - expect([1, 2, 3].butlast).to eq([1, 2]) - end +unless Array.method_defined? :butlast + describe 'Array#butlast' do + it 'returns an array without the last element' do + expect([1, 2, 3].butlast).to eq([1, 2]) + end - it 'returns [] for empty lists' do - expect([].butlast).to be_empty + it 'returns [] for empty lists' do + expect([].butlast).to be_empty + end end end diff --git a/spec/powerpack/enumerable/average_spec.rb b/spec/powerpack/enumerable/average_spec.rb index dd651bb..003d2b5 100644 --- a/spec/powerpack/enumerable/average_spec.rb +++ b/spec/powerpack/enumerable/average_spec.rb @@ -1,19 +1,21 @@ require 'spec_helper' -describe 'Enumerable#average' do - it 'calculates the average of an enum' do - expect((1..3).average).to eq(2) - end +unless Enumerable.method_defined? :average + describe 'Enumerable#average' do + it 'calculates the average of an enum' do + expect((1..3).average).to eq(2) + end - it 'calculates the average of an array' do - expect([1, 2, 3, 4].average).to eq(2.5) - end + it 'calculates the average of an array' do + expect([1, 2, 3, 4].average).to eq(2.5) + end - it 'returns nil when invoked on an empty collection' do - expect([].average).to be_nil - end + it 'returns nil when invoked on an empty collection' do + expect([].average).to be_nil + end - it 'returns default value when invoked on an empty collection' do - expect([].average(0)).to be_zero + it 'returns default value when invoked on an empty collection' do + expect([].average(0)).to be_zero + end end end diff --git a/spec/powerpack/enumerable/drop_last_spec.rb b/spec/powerpack/enumerable/drop_last_spec.rb index 89367fb..9995fdb 100644 --- a/spec/powerpack/enumerable/drop_last_spec.rb +++ b/spec/powerpack/enumerable/drop_last_spec.rb @@ -1,15 +1,17 @@ require 'spec_helper' -describe 'Enumerable#drop_last' do - it 'drops the last n elements' do - expect([1, 2, 3, 4].drop_last(2)).to eq([1, 2]) - end +unless Enumerable.method_defined? :drop_last + describe 'Enumerable#drop_last' do + it 'drops the last n elements' do + expect([1, 2, 3, 4].drop_last(2)).to eq([1, 2]) + end - it 'returns an empty array if you request to drop too many elems' do - expect((1..10).drop_last(100)).to eq([]) - end + it 'returns an empty array if you request to drop too many elems' do + expect((1..10).drop_last(100)).to eq([]) + end - it 'does not accept negative argument' do - expect { [1, 2, 3, 4].drop_last(-1) }.to raise_error(ArgumentError) + it 'does not accept negative argument' do + expect { [1, 2, 3, 4].drop_last(-1) }.to raise_error(ArgumentError) + end end end diff --git a/spec/powerpack/enumerable/drop_last_while_spec.rb b/spec/powerpack/enumerable/drop_last_while_spec.rb index b43473f..0d37fb5 100644 --- a/spec/powerpack/enumerable/drop_last_while_spec.rb +++ b/spec/powerpack/enumerable/drop_last_while_spec.rb @@ -1,7 +1,9 @@ require 'spec_helper' -describe 'Enumerable#drop_last_while' do - it 'drops the last elements while a pred is true' do - expect([1, 2, 3, 4, 6].drop_last_while(&:even?)).to eq([1, 2, 3]) +unless Enumerable.method_defined? :drop_last_while + describe 'Enumerable#drop_last_while' do + it 'drops the last elements while a pred is true' do + expect([1, 2, 3, 4, 6].drop_last_while(&:even?)).to eq([1, 2, 3]) + end end end diff --git a/spec/powerpack/enumerable/exactly_spec.rb b/spec/powerpack/enumerable/exactly_spec.rb index 8aa011a..04faa03 100644 --- a/spec/powerpack/enumerable/exactly_spec.rb +++ b/spec/powerpack/enumerable/exactly_spec.rb @@ -1,39 +1,41 @@ require 'spec_helper' -describe 'Enumerable#exactly' do - context 'with block' do - it 'returns true for exact number of matches' do - expect([1, 2, 3, 4].exactly?(2, &:even?)).to be_truthy - end - - it 'returns false for less matches' do - expect([1, 3, 4].exactly?(2, &:even?)).to be_falsey - end - - it 'returns false for more matches' do - expect([1, 3, 4, 6, 8].exactly?(2, &:even?)).to be_falsey - end - end - - context 'without block' do - it 'returns true for exact number of non nil/false elements in absence of nil/false elements' do - expect([1, 2, 3, 4].exactly?(4)).to be_truthy - end - - it 'returns true for exact number of non nil/false elements in presence of nil/false elements' do - expect([1, 2, nil, false].exactly?(2)).to be_truthy - end - - it 'returns true for exact number of nil/false elements' do - expect([nil, false].exactly?(0)).to be_truthy - end - - it 'returns false if there are less non nil/false elements in absence of nil/false elements' do - expect([1, 2, 3].exactly?(4)).to be_falsey - end - - it 'returns false if there are less non nil/false elements in presence of nil/false elements' do - expect([1, nil, false].exactly?(4)).to be_falsey +unless Enumerable.method_defined? :exactly + describe 'Enumerable#exactly' do + context 'with block' do + it 'returns true for exact number of matches' do + expect([1, 2, 3, 4].exactly?(2, &:even?)).to be_truthy + end + + it 'returns false for less matches' do + expect([1, 3, 4].exactly?(2, &:even?)).to be_falsey + end + + it 'returns false for more matches' do + expect([1, 3, 4, 6, 8].exactly?(2, &:even?)).to be_falsey + end + end + + context 'without block' do + it 'returns true for exact number of non nil/false elements in absence of nil/false elements' do + expect([1, 2, 3, 4].exactly?(4)).to be_truthy + end + + it 'returns true for exact number of non nil/false elements in presence of nil/false elements' do + expect([1, 2, nil, false].exactly?(2)).to be_truthy + end + + it 'returns true for exact number of nil/false elements' do + expect([nil, false].exactly?(0)).to be_truthy + end + + it 'returns false if there are less non nil/false elements in absence of nil/false elements' do + expect([1, 2, 3].exactly?(4)).to be_falsey + end + + it 'returns false if there are less non nil/false elements in presence of nil/false elements' do + expect([1, nil, false].exactly?(4)).to be_falsey + end end end end diff --git a/spec/powerpack/enumerable/frequencies_spec.rb b/spec/powerpack/enumerable/frequencies_spec.rb index 7c4ad87..0af18d3 100644 --- a/spec/powerpack/enumerable/frequencies_spec.rb +++ b/spec/powerpack/enumerable/frequencies_spec.rb @@ -1,20 +1,22 @@ require 'spec_helper' -describe 'Enumerable#frequencies' do - context 'empty collection' do - it 'evaluates to an empty hash' do - expect([].frequencies).to eql({}) +unless Enumerable.method_defined? :frequencies + describe 'Enumerable#frequencies' do + context 'empty collection' do + it 'evaluates to an empty hash' do + expect([].frequencies).to eql({}) + end end - end - context 'populated collection' do - it 'counts the number of ocurrences and returns a hash in the form value => count' do - expect([1, 1, :symbol, 3, 1, :symbol, 'string'].frequencies).to eql( - 1 => 3, - 3 => 1, - 'string' => 1, - :symbol => 2 - ) + context 'populated collection' do + it 'counts the number of ocurrences and returns a hash in the form value => count' do + expect([1, 1, :symbol, 3, 1, :symbol, 'string'].frequencies).to eql( + 1 => 3, + 3 => 1, + 'string' => 1, + :symbol => 2 + ) + end end end end diff --git a/spec/powerpack/enumerable/several_spec.rb b/spec/powerpack/enumerable/several_spec.rb index 85d053f..52fbfc8 100644 --- a/spec/powerpack/enumerable/several_spec.rb +++ b/spec/powerpack/enumerable/several_spec.rb @@ -1,27 +1,29 @@ require 'spec_helper' -describe 'Enumerable#several' do - context 'with block' do - it 'returns true if more than 1 element matches the predicate' do - expect([1, 2, 3, 4].several?(&:even?)).to be_truthy - end +unless Enumerable.method_defined? :several + describe 'Enumerable#several' do + context 'with block' do + it 'returns true if more than 1 element matches the predicate' do + expect([1, 2, 3, 4].several?(&:even?)).to be_truthy + end - it 'returns false if just 1 element matches the predicate' do - expect([1, 3, 4].several?(&:even?)).to be_falsey - end + it 'returns false if just 1 element matches the predicate' do + expect([1, 3, 4].several?(&:even?)).to be_falsey + end - it 'returns false if no elements match the predicate' do - expect([1, 3, 4].several?(&:even?)).to be_falsey + it 'returns false if no elements match the predicate' do + expect([1, 3, 4].several?(&:even?)).to be_falsey + end end - end - context 'without block' do - it 'returns true if there are 2 or more non nil/false elements' do - expect([1, 2, 3, 4].several?).to be_truthy - end + context 'without block' do + it 'returns true if there are 2 or more non nil/false elements' do + expect([1, 2, 3, 4].several?).to be_truthy + end - it 'returns false if there are less than 2 non nil/false elements' do - expect([1, nil, false].several?).to be_falsey + it 'returns false if there are less than 2 non nil/false elements' do + expect([1, nil, false].several?).to be_falsey + end end end end diff --git a/spec/powerpack/enumerable/sum_spec.rb b/spec/powerpack/enumerable/sum_spec.rb index 4f51db5..a0e36db 100644 --- a/spec/powerpack/enumerable/sum_spec.rb +++ b/spec/powerpack/enumerable/sum_spec.rb @@ -6,12 +6,16 @@ unless Enumerable.method_defined? :sum expect((1..3).sum).to eq(6) end - it 'returns nil when invoked on an empty collection' do - expect([].sum).to be_nil + it 'returns zero when invoked on an empty collection' do + expect([].sum).to be_zero end - it 'returns default value when invoked on an empty collection' do - expect([].sum(0)).to be_zero + it 'returns combined string' do + expect(['a', 'b', 'c'].sum).to eq('abc') + end + + it 'returns flatten array' do + expect([[1], [2], [3]].sum).to eq([1, 2, 3]) end end end diff --git a/spec/powerpack/enumerable/take_last_spec.rb b/spec/powerpack/enumerable/take_last_spec.rb index 05d4677..ec5d6d7 100644 --- a/spec/powerpack/enumerable/take_last_spec.rb +++ b/spec/powerpack/enumerable/take_last_spec.rb @@ -1,15 +1,17 @@ require 'spec_helper' -describe 'Enumerable#take_last' do - it 'takes the last n elements' do - expect([1, 2, 3, 4].take_last(2)).to eq([3, 4]) - end +unless Enumerable.method_defined? :take_last + describe 'Enumerable#take_last' do + it 'takes the last n elements' do + expect([1, 2, 3, 4].take_last(2)).to eq([3, 4]) + end - it 'returns everything if you request to drop too many elems' do - expect((1..10).take_last(100)).to eq((1..10).to_a) - end + it 'returns everything if you request to drop too many elems' do + expect((1..10).take_last(100)).to eq((1..10).to_a) + end - it 'does not accept negative argument' do - expect { [1, 2, 3, 4].take_last(-1) }.to raise_error(ArgumentError) + it 'does not accept negative argument' do + expect { [1, 2, 3, 4].take_last(-1) }.to raise_error(ArgumentError) + end end end diff --git a/spec/powerpack/enumerable/take_last_while_spec.rb b/spec/powerpack/enumerable/take_last_while_spec.rb index 5c3fe1a..e9462b1 100644 --- a/spec/powerpack/enumerable/take_last_while_spec.rb +++ b/spec/powerpack/enumerable/take_last_while_spec.rb @@ -1,7 +1,9 @@ require 'spec_helper' -describe 'Enumerable#take_last_while' do - it 'takes the last elements while a pred is true' do - expect([1, 2, 3, 4, 6].take_last_while(&:even?)).to eq([4, 6]) +unless Enumerable.method_defined? :take_last_while + describe 'Enumerable#take_last_while' do + it 'takes the last elements while a pred is true' do + expect([1, 2, 3, 4, 6].take_last_while(&:even?)).to eq([4, 6]) + end end end diff --git a/spec/powerpack/hash/symbolize_keys_spec.rb b/spec/powerpack/hash/symbolize_keys_spec.rb index d4437ab..ee3cc2d 100644 --- a/spec/powerpack/hash/symbolize_keys_spec.rb +++ b/spec/powerpack/hash/symbolize_keys_spec.rb @@ -1,15 +1,17 @@ require 'spec_helper' -describe 'Hash#symbolize_keys' do - it 'turn the hash keys into symbols' do - hash = { 'one' => 1, 'two' => 2 } +unless Hash.method_defined? :symbolize_keys + describe 'Hash#symbolize_keys' do + it 'turn the hash keys into symbols' do + hash = { 'one' => 1, 'two' => 2 } - expect(hash.symbolize_keys).to eq({ one: 1, two: 2 }) - end + expect(hash.symbolize_keys).to eq({ one: 1, two: 2 }) + end - it 'leaves nonconvertible keys untouched' do - hash = { 1 => 'one', [1, 1] => 'ones' } + it 'leaves nonconvertible keys untouched' do + hash = { 1 => 'one', [1, 1] => 'ones' } - expect(hash.symbolize_keys).to eq({ 1 => 'one', [1, 1] => 'ones' }) + expect(hash.symbolize_keys).to eq({ 1 => 'one', [1, 1] => 'ones' }) + end end end diff --git a/spec/powerpack/numeric/neg_spec.rb b/spec/powerpack/numeric/neg_spec.rb index af586da..689baa4 100644 --- a/spec/powerpack/numeric/neg_spec.rb +++ b/spec/powerpack/numeric/neg_spec.rb @@ -1,24 +1,26 @@ require 'spec_helper' -describe 'Numeric#neg?' do - it 'returns false for positive integer' do - expect(1.neg?).to be_falsey - end +unless Numeric.method_defined? :neg? + describe 'Numeric#neg?' do + it 'returns false for positive integer' do + expect(1.neg?).to be_falsey + end - it 'returns false for positive float' do - expect(0.1.neg?).to be_falsey - end + it 'returns false for positive float' do + expect(0.1.neg?).to be_falsey + end - it 'returns true for negative integer' do - expect(-1.neg?).to be_truthy - end + it 'returns true for negative integer' do + expect(-1.neg?).to be_truthy + end - it 'returns true for negative float' do - expect(-0.01.neg?).to be_truthy - end + it 'returns true for negative float' do + expect(-0.01.neg?).to be_truthy + end - it 'returns false for 0' do - expect(0.neg?).to be_falsey - expect(0.0.neg?).to be_falsey + it 'returns false for 0' do + expect(0.neg?).to be_falsey + expect(0.0.neg?).to be_falsey + end end end diff --git a/spec/powerpack/numeric/pos_spec.rb b/spec/powerpack/numeric/pos_spec.rb index b7d92cc..7ee2ba8 100644 --- a/spec/powerpack/numeric/pos_spec.rb +++ b/spec/powerpack/numeric/pos_spec.rb @@ -1,24 +1,26 @@ require 'spec_helper' -describe 'Numeric#pos?' do - it 'returns true for positive integer' do - expect(1.pos?).to be_truthy - end +unless Numeric.method_defined? :pos? + describe 'Numeric#pos?' do + it 'returns true for positive integer' do + expect(1.pos?).to be_truthy + end - it 'returns true for positive float' do - expect(0.1.pos?).to be_truthy - end + it 'returns true for positive float' do + expect(0.1.pos?).to be_truthy + end - it 'returns false for negative integer' do - expect(-1.pos?).to be_falsey - end + it 'returns false for negative integer' do + expect(-1.pos?).to be_falsey + end - it 'returns false for negative float' do - expect(-0.01.pos?).to be_falsey - end + it 'returns false for negative float' do + expect(-0.01.pos?).to be_falsey + end - it 'returns false for 0' do - expect(0.pos?).to be_falsey - expect(0.0.pos?).to be_falsey + it 'returns false for 0' do + expect(0.pos?).to be_falsey + expect(0.0.pos?).to be_falsey + end end end diff --git a/spec/powerpack/numeric/scale_spec.rb b/spec/powerpack/numeric/scale_spec.rb index 070705e..5eb1dc3 100644 --- a/spec/powerpack/numeric/scale_spec.rb +++ b/spec/powerpack/numeric/scale_spec.rb @@ -1,139 +1,141 @@ require 'spec_helper' -describe 'Numeric#hundred' do - it 'returns positive integer for positive integer' do - expect(1.hundred).to eql 100 - end +unless Numeric.method_defined? :hundred + describe 'Numeric#hundred' do + it 'returns positive integer for positive integer' do + expect(1.hundred).to eql 100 + end - it 'returns positive float for positive float' do - expect(0.1.hundred).to eql 10.0 - end + it 'returns positive float for positive float' do + expect(0.1.hundred).to eql 10.0 + end - it 'returns false for negative integer' do - expect(-1.hundred).to eql -100 - end + it 'returns false for negative integer' do + expect(-1.hundred).to eql -100 + end - it 'returns false for negative float' do - expect(-0.1.hundred).to eql -10.0 - end + it 'returns false for negative float' do + expect(-0.1.hundred).to eql -10.0 + end - it 'returns 0 for 0' do - expect(0.hundred).to eql 0 - expect(0.0.hundred).to eql 0.0 + it 'returns 0 for 0' do + expect(0.hundred).to eql 0 + expect(0.0.hundred).to eql 0.0 + end end -end -describe 'Numeric#thousand' do - it 'returns positive integer for positive integer' do - expect(1.thousand).to eql 1000 - end + describe 'Numeric#thousand' do + it 'returns positive integer for positive integer' do + expect(1.thousand).to eql 1000 + end - it 'returns positive float for positive float' do - expect(0.1.thousand).to eql 100.0 - end + it 'returns positive float for positive float' do + expect(0.1.thousand).to eql 100.0 + end - it 'returns false for negative integer' do - expect(-1.thousand).to eql -1000 - end + it 'returns false for negative integer' do + expect(-1.thousand).to eql -1000 + end - it 'returns false for negative float' do - expect(-0.1.thousand).to eql -100.0 - end + it 'returns false for negative float' do + expect(-0.1.thousand).to eql -100.0 + end - it 'returns 0 for 0' do - expect(0.thousand).to eql 0 - expect(0.0.thousand).to eql 0.0 + it 'returns 0 for 0' do + expect(0.thousand).to eql 0 + expect(0.0.thousand).to eql 0.0 + end end -end -describe 'Numeric#million' do - it 'returns positive integer for positive integer' do - expect(1.million).to eql 1000000 - end + describe 'Numeric#million' do + it 'returns positive integer for positive integer' do + expect(1.million).to eql 1000000 + end - it 'returns positive float for positive float' do - expect(0.1.million).to eql 100000.0 - end + it 'returns positive float for positive float' do + expect(0.1.million).to eql 100000.0 + end - it 'returns false for negative integer' do - expect(-1.million).to eql -1000000 - end + it 'returns false for negative integer' do + expect(-1.million).to eql -1000000 + end - it 'returns false for negative float' do - expect(-0.1.million).to eql -100000.0 - end + it 'returns false for negative float' do + expect(-0.1.million).to eql -100000.0 + end - it 'returns 0 for 0' do - expect(0.million).to eql 0 - expect(0.0.million).to eql 0.0 + it 'returns 0 for 0' do + expect(0.million).to eql 0 + expect(0.0.million).to eql 0.0 + end end -end -describe 'Numeric#billion' do - it 'returns positive integer for positive integer' do - expect(1.billion).to eql 1000000000 - end + describe 'Numeric#billion' do + it 'returns positive integer for positive integer' do + expect(1.billion).to eql 1000000000 + end - it 'returns positive float for positive float' do - expect(0.1.billion).to eql 100000000.0 - end + it 'returns positive float for positive float' do + expect(0.1.billion).to eql 100000000.0 + end - it 'returns false for negative integer' do - expect(-1.billion).to eql -1000000000 - end + it 'returns false for negative integer' do + expect(-1.billion).to eql -1000000000 + end - it 'returns false for negative float' do - expect(-0.1.billion).to eql -100000000.0 - end + it 'returns false for negative float' do + expect(-0.1.billion).to eql -100000000.0 + end - it 'returns 0 for 0' do - expect(0.billion).to eql 0 - expect(0.0.billion).to eql 0.0 + it 'returns 0 for 0' do + expect(0.billion).to eql 0 + expect(0.0.billion).to eql 0.0 + end end -end -describe 'Numeric#trillion' do - it 'returns positive integer for positive integer' do - expect(1.trillion).to eql 1000000000000 - end + describe 'Numeric#trillion' do + it 'returns positive integer for positive integer' do + expect(1.trillion).to eql 1000000000000 + end - it 'returns positive float for positive float' do - expect(0.1.trillion).to eql 100000000000.0 - end + it 'returns positive float for positive float' do + expect(0.1.trillion).to eql 100000000000.0 + end - it 'returns false for negative integer' do - expect(-1.trillion).to eql -1000000000000 - end + it 'returns false for negative integer' do + expect(-1.trillion).to eql -1000000000000 + end - it 'returns false for negative float' do - expect(-0.1.trillion).to eql -100000000000.0 - end + it 'returns false for negative float' do + expect(-0.1.trillion).to eql -100000000000.0 + end - it 'returns 0 for 0' do - expect(0.trillion).to eql 0 - expect(0.0.trillion).to eql 0.0 + it 'returns 0 for 0' do + expect(0.trillion).to eql 0 + expect(0.0.trillion).to eql 0.0 + end end -end -describe 'Numeric#quadrillion' do - it 'returns positive integer for positive integer' do - expect(1.quadrillion).to eql 1000000000000000 - end + describe 'Numeric#quadrillion' do + it 'returns positive integer for positive integer' do + expect(1.quadrillion).to eql 1000000000000000 + end - it 'returns positive float for positive float' do - expect(0.1.quadrillion).to eql 100000000000000.0 - end + it 'returns positive float for positive float' do + expect(0.1.quadrillion).to eql 100000000000000.0 + end - it 'returns false for negative integer' do - expect(-1.quadrillion).to eql -1000000000000000 - end + it 'returns false for negative integer' do + expect(-1.quadrillion).to eql -1000000000000000 + end - it 'returns false for negative float' do - expect(-0.1.quadrillion).to eql -100000000000000.0 - end + it 'returns false for negative float' do + expect(-0.1.quadrillion).to eql -100000000000000.0 + end - it 'returns 0 for 0' do - expect(0.quadrillion).to eql 0 - expect(0.0.quadrillion).to eql 0.0 + it 'returns 0 for 0' do + expect(0.quadrillion).to eql 0 + expect(0.0.quadrillion).to eql 0.0 + end end end diff --git a/spec/powerpack/string/ascii_only_spec.rb b/spec/powerpack/string/ascii_only_spec.rb index 89437ad..49c6d8f 100644 --- a/spec/powerpack/string/ascii_only_spec.rb +++ b/spec/powerpack/string/ascii_only_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -unless defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby' +unless String.method_defined? :ascii_only || defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby' describe 'String#ascii_only' do it 'returns same value for string with ASCII chars only' do expect('abc'.ascii_only).to eq 'abc' diff --git a/spec/powerpack/string/blank_spec.rb b/spec/powerpack/string/blank_spec.rb index f311fc4..48008d0 100644 --- a/spec/powerpack/string/blank_spec.rb +++ b/spec/powerpack/string/blank_spec.rb @@ -1,15 +1,17 @@ require 'spec_helper' -describe 'String#blank?' do - it 'returns true for an empty string' do - expect(''.blank?).to be_truthy - end +unless String.method_defined? :blank? + describe 'String#blank?' do + it 'returns true for an empty string' do + expect(''.blank?).to be_truthy + end - it 'returns true for a string with only whitespace in it' do - expect(' '.blank?).to be_truthy - end + it 'returns true for a string with only whitespace in it' do + expect(' '.blank?).to be_truthy + end - it 'returns false for a string with non-whitespace chars in it' do - expect(' test'.blank?).to be_falsey + it 'returns false for a string with non-whitespace chars in it' do + expect(' test'.blank?).to be_falsey + end end end diff --git a/spec/powerpack/string/format_spec.rb b/spec/powerpack/string/format_spec.rb index aa0dd7a..35a7f08 100644 --- a/spec/powerpack/string/format_spec.rb +++ b/spec/powerpack/string/format_spec.rb @@ -1,12 +1,14 @@ require 'spec_helper' -describe 'String#format' do - it 'behaves like String#%' do - expect('%s %s'.format %w(James Bond)).to eq('%s %s' % %w(James Bond)) - end +unless String.method_defined? :format + describe 'String#format' do + it 'behaves like String#%' do + expect('%s %s'.format %w(James Bond)).to eq('%s %s' % %w(James Bond)) + end - it 'behaves like Kernel#sprintf' do - expect('%s %s'.format %w(James Bond)) - .to eq(sprintf('%s %s', 'James', 'Bond')) + it 'behaves like Kernel#sprintf' do + expect('%s %s'.format %w(James Bond)) + .to eq(sprintf('%s %s', 'James', 'Bond')) + end end end diff --git a/spec/powerpack/string/remove_prefix_spec.rb b/spec/powerpack/string/remove_prefix_spec.rb index fd61e6a..fa2778d 100644 --- a/spec/powerpack/string/remove_prefix_spec.rb +++ b/spec/powerpack/string/remove_prefix_spec.rb @@ -1,13 +1,15 @@ require 'spec_helper' -describe 'String#remove_prefix' do - it 'removes a prefix in a string' do - expect('Ladies Night'.remove_prefix('Ladies ')).to eq('Night') +unless String.method_defined? :remove_prefix + describe 'String#remove_prefix' do + it 'removes a prefix in a string' do + expect('Ladies Night'.remove_prefix('Ladies ')).to eq('Night') + end end -end -describe 'String#remove_prefix!' do - it 'removes a prefix in a string' do - expect('Ladies Night'.remove_prefix!('Ladies ')).to eq('Night') + describe 'String#remove_prefix!' do + it 'removes a prefix in a string' do + expect('Ladies Night'.remove_prefix!('Ladies ')).to eq('Night') + end end end diff --git a/spec/powerpack/string/remove_spec.rb b/spec/powerpack/string/remove_spec.rb index 092af0e..924e0bc 100644 --- a/spec/powerpack/string/remove_spec.rb +++ b/spec/powerpack/string/remove_spec.rb @@ -1,13 +1,15 @@ require 'spec_helper' -describe 'String#remove' do - it 'removes all occurrences of a pattern' do - expect('Ladies Night'.remove(/Ladies /)).to eq('Night') +unless String.method_defined? :remove + describe 'String#remove' do + it 'removes all occurrences of a pattern' do + expect('Ladies Night'.remove(/Ladies /)).to eq('Night') + end end -end -describe 'String#remove!' do - it 'removes all occurrences of a pattern' do - expect('Ladies Night'.remove(/Ladies /)).to eq('Night') + describe 'String#remove!' do + it 'removes all occurrences of a pattern' do + expect('Ladies Night'.remove(/Ladies /)).to eq('Night') + end end end diff --git a/spec/powerpack/string/remove_suffix_spec.rb b/spec/powerpack/string/remove_suffix_spec.rb index 901c407..c910494 100644 --- a/spec/powerpack/string/remove_suffix_spec.rb +++ b/spec/powerpack/string/remove_suffix_spec.rb @@ -1,13 +1,15 @@ require 'spec_helper' -describe 'String#remove_suffix' do - it 'removes a suffix in a string' do - expect('Ladies Night'.remove_suffix(' Night')).to eq('Ladies') +unless String.method_defined? :remove_suffix + describe 'String#remove_suffix' do + it 'removes a suffix in a string' do + expect('Ladies Night'.remove_suffix(' Night')).to eq('Ladies') + end end -end -describe 'String#remove_suffix!' do - it 'removes a suffix in a string' do - expect('Ladies Night'.remove_suffix!(' Night')).to eq('Ladies') + describe 'String#remove_suffix!' do + it 'removes a suffix in a string' do + expect('Ladies Night'.remove_suffix!(' Night')).to eq('Ladies') + end end end diff --git a/spec/powerpack/string/squish_spec.rb b/spec/powerpack/string/squish_spec.rb index 6de7d09..0bc3bbd 100644 --- a/spec/powerpack/string/squish_spec.rb +++ b/spec/powerpack/string/squish_spec.rb @@ -1,21 +1,23 @@ require 'spec_helper' -describe 'String#squish' do - it 'strips leading and trailing whitespace' do - expect(' Peter '.squish).to eq('Peter') - end +unless String.method_defined? :squish + describe 'String#squish' do + it 'strips leading and trailing whitespace' do + expect(' Peter '.squish).to eq('Peter') + end - it 'compacts internal whitespace' do - expect("Peter\r\n \t Parker".squish).to eq('Peter Parker') + it 'compacts internal whitespace' do + expect("Peter\r\n \t Parker".squish).to eq('Peter Parker') + end end -end -describe 'String#squish!' do - it 'strips leading and trailing whitespace' do - expect(' Peter '.squish!).to eq('Peter') - end + describe 'String#squish!' do + it 'strips leading and trailing whitespace' do + expect(' Peter '.squish!).to eq('Peter') + end - it 'compacts internal whitespace' do - expect("Peter\r\n \t Parker".squish!).to eq('Peter Parker') + it 'compacts internal whitespace' do + expect("Peter\r\n \t Parker".squish!).to eq('Peter Parker') + end end end diff --git a/spec/powerpack/string/strip_indent_spec.rb b/spec/powerpack/string/strip_indent_spec.rb index cca4a6d..a55dc18 100644 --- a/spec/powerpack/string/strip_indent_spec.rb +++ b/spec/powerpack/string/strip_indent_spec.rb @@ -1,13 +1,15 @@ require 'spec_helper' -describe 'String#strip_indent' do - it 'strips leading indent on every line of string' do - test = <<-END - test - test +unless String.method_defined? :strip_indent + describe 'String#strip_indent' do + it 'strips leading indent on every line of string' do + test = <<-END test - END + test + test + END - expect(test.strip_indent).to eq("test\n test\n test\n") + expect(test.strip_indent).to eq("test\n test\n test\n") + end end end diff --git a/spec/powerpack/string/strip_margin_spec.rb b/spec/powerpack/string/strip_margin_spec.rb index 978b949..4b91670 100644 --- a/spec/powerpack/string/strip_margin_spec.rb +++ b/spec/powerpack/string/strip_margin_spec.rb @@ -1,26 +1,28 @@ require 'spec_helper' -describe 'String#strip_margin' do - it 'strips margin on every line of string' do - code = <<-END - |def test - | some_method - | other_method - |end - END +unless String.method_defined? :strip_margin + describe 'String#strip_margin' do + it 'strips margin on every line of string' do + code = <<-END + |def test + | some_method + | other_method + |end + END - expect(code.strip_margin('|')) - .to eq("def test\n some_method\n other_method\nend\n") - end + expect(code.strip_margin('|')) + .to eq("def test\n some_method\n other_method\nend\n") + end - it 'strips special characters margin from every line' do - code = <<-END - {{1}}def test - {{1}} some_method - {{1}}end - END + it 'strips special characters margin from every line' do + code = <<-END + {{1}}def test + {{1}} some_method + {{1}}end + END - expect(code.strip_margin('{{1}}')) - .to eq("def test\n some_method\nend\n") + expect(code.strip_margin('{{1}}')) + .to eq("def test\n some_method\nend\n") + end end end -- 2.13.6
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Contact
Support
@OBShq
The Open Build Service is an
openSUSE project
.
Log In
Places
Places
All Projects
Status Monitor