It's an exercise from a RSpec-course, which I'm currently doing.
Task:
Create a compound expectation, which asserts the string sportscar starts with the substring "sports" and ends with the substring "car".
Create a compound expectation, which asserts that the number 30 is even and that it responds to the times method.
Create a compound expectation, which asserts that the array [2, 4, 8, 16, 32, 64] includes the element 32 and starts with the elements 2, 4, and 8.
My solution:
RSpec.describe "sportscar" do
it "should start with 'sports' and end with 'car'" do
expect(subject).to start_with("sports").and end_with("car")
end
it "30 is even and responds to the times-method" do
numb = 30
expect(numb.even?).to be true and numb.respond_to? :times
end
it "shall include 32 and start with the values 2, 4, 8" do
arr = [2, 4, 8, 16, 32, 64]
expect(arr).to include(32) and start_with(2, 4, 8)
end
end
Could it become improved? Perhaps more written in a Ruby-Idiomatic way?
Are my message-strings (it "should start with ..." etc.) done in a good way? Or should it be written in a different way and if so: How?
.and
(dot and) or&
(single ampersand) cf relishapp.com/rspec/rspec-expectations/docs/… \$\endgroup\$