How would you write Rspec code for Enumerable#any? ?
Like :
a = [1,2,43,54,6]
b = [6,77,11]
a.any? { |i| b.include i } # => true
Regards,
Arup R.
How would you write Rspec code for Enumerable#any? ?
Like :
a = [1,2,43,54,6]
b = [6,77,11]
a.any? { |i| b.include i } # => true
Regards,
Arup R.
On Wed, May 7, 2014 at 8:44 AM, Arup R.
[email protected] wrote:
How would you write Rspec code for Enumerable#any? ?
Like :
a = [1,2,43,54,6]
b = [6,77,11]
a.any? { |i| b.include i } # => trueRegards,
Arup R.
it “checks if any a are included in b” do
a = [1,2,43,54,6]
b = [6,77,11]
expect(a.any?{|i| b.include i}.to be_true
end
Hello,
On 7 Μαϊ 2014, at 15:44 , Arup R. [email protected]
wrote:
a = [1,2,43,54,6]
b = [6,77,11]
a.any? { |i| b.include i } # => true
cat enum_spec.rb
require ‘rspec’
RSpec.describe “Test enumerable” do
it “returns ‘true’” do
a = [1,2,43,54,6]
b = [6,77,11]
expect(a.any? { |i| b.include? i}).to eq(true)
end
it “returns ‘false’” do
a = [1,2,43,54]
b = [6,77,11]
expect(a.any? { |i| b.include? i}).to eq(false)
end
end
rspec enum_spec.rb
…
Finished in 0.0009 seconds
2 examples, 0 failures
However, ‘minitest’[1] is also very good testing framework with the
additional ‘+’ that it comes with ruby by default. I’ve used both
minitest and rspec. I didn’t notice any differences between the two at
core level. Rspec has a wide variety of additional gems and strong
community. Maybe more advanced users would like to point out some
differences between the two and when to use one over the other.
Regards
Panagiotis (atmosx) Atmatzidis
email: [email protected]
URL: http://www.convalesco.org
GnuPG ID: 0x1A7BFEC5
gpg --keyserver pgp.mit.edu --recv-keys 1A7BFEC5
“As you set out for Ithaca, hope the voyage is a long one, full of
adventure, full of discovery […]” - C. P. Cavafy
Hi All,
Thanks for your help. It works. But I though Rspec have some inbuilt
method like match_array kind of. Anyway it works.
Regards,
Arup R.
On Wednesday, 7 May 2014 7:43 PM, tamouse pontiki
[email protected] wrote:
On Wed, May 7, 2014 at 9:12 AM, tamouse pontiki
[email protected] wrote:
Arup R.
it “checks if any a are included in b” do
a = [1,2,43,54,6]
b = [6,77,11]
expect(a.any?{|i| b.include i}.to be_true
Sorry, typo:
expect(a.any?{|i| b.include i}).to be_true
(missed closing paren)
On Wed, May 7, 2014 at 9:12 AM, tamouse pontiki
[email protected] wrote:
Arup R.
it “checks if any a are included in b” do
a = [1,2,43,54,6]
b = [6,77,11]
expect(a.any?{|i| b.include i}.to be_true
Sorry, typo:
expect(a.any?{|i| b.include i}).to be_true
(missed closing paren)
Hi Arup,
From:
https://www.relishapp.com/rspec/rspec-expectations/v/3-0/docs/built-in-matchers
Collection membership
expect(actual).to include(expected)
expect(actual).to start_with(expected)
expect(actual).to end_with(expected)
Match Array
expect(actual).to match_array(expected)
Look at “contain_exactly” also…
Abinoam Jr.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs