I'm new to RSpec and I'm trying to do testing but I have no idea how to handle nested if. I hope you can help me. Thank you!
array1 = %w[a b]
array2 = %w[aa b c]
@a = if (array1 & array2).any?
if !array2.include? 'c'
'yes'
else
'no'
end
else
'neither'
end
puts @a
I would like to develop a basic test for my code using RSpec. My code runs perfectly I just don't know how to write a test.
def m(arr1, arr2); return 'neither' if (arr1 & arr2).empty?; array2.include?('c') ? 'no' : 'yes'; end.return 'neither' if (arr1 & arr2).empty?is called a guard clause. Its use reduces by one the number of levels of nested conditional statements.array2.include?('c') ? 'no' : 'yes'uses the ternary operator.