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 Rakshit
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 Rakshit
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
http://rubydoc.info/gems/rspec-expectations/frames
On Wed, May 7, 2014 at 8:44 AM, Arup Rakshit <aruprakshit@rocketmail.com> 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 Rakshit
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 Rakshitit "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 <tamouse.lists@gmail.com> wrote:
On Wed, May 7, 2014 at 8:44 AM, Arup Rakshit <aruprakshit@rocketmail.com> wrote:
end
File: README — Documentation for rspec-expectations (3.12.3)
Hello,
On 7 Μαϊ 2014, at 15:44 , Arup Rakshit <aruprakshit@rocketmail.com> wrote:
a = [1,2,43,54,6]
b = [6,77,11]
a.any? { |i| b.include i } # => true
Here is a simple example:
----
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: atma@convalesco.org
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 Rakshit
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 Rakshitit "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 Wednesday, 7 May 2014 7:43 PM, tamouse pontiki <tamouse.lists@gmail.com> wrote:
On Wed, May 7, 2014 at 9:12 AM, tamouse pontiki <tamouse.lists@gmail.com> wrote:
On Wed, May 7, 2014 at 8:44 AM, Arup Rakshit <aruprakshit@rocketmail.com> wrote:
end
File: README — Documentation for rspec-expectations (3.12.3)
Hi Arup,
From:
- File: README — Documentation for rspec-expectations (3.12.3)
- 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.
On Thu, May 8, 2014 at 2:52 AM, Arup Rakshit <aruprakshit@rocketmail.com> wrote:
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 Rakshit
On Wednesday, 7 May 2014 7:43 PM, tamouse pontiki <tamouse.lists@gmail.com> > wrote:
On Wed, May 7, 2014 at 9:12 AM, tamouse pontiki <tamouse.lists@gmail.com> > wrote:On Wed, May 7, 2014 at 8:44 AM, Arup Rakshit <aruprakshit@rocketmail.com> >> 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 Rakshitit "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_trueSorry, typo:
expect(a.any?{|i| b.include i}).to be_true
(missed closing paren)
end
File: README — Documentation for rspec-expectations (3.12.3)