Оба ответа выше верны, но в свете вопроса Картика, приведенного выше, я подумал, что опубликую тест, показывающий, как можно точно передать символ методу include
def test_you_create_a_new_symbol_in_the_test
array_of_symbols = []
array_of_symbols << Symbol.all_symbols
all_symbols = Symbol.all_symbols.map {|x| x}
assert_equal false, array_of_symbols.include?(:this_should_not_be_in_the_symbols_collection) #this works because we stored all symbols in an array before creating the symbol :this_should_not_be_in_the_symbols_collection in the test
assert_equal true, all_symbols.include?(:this_also_should_not_be_in_the_symbols_collection) #This is the case noted in previous answers...here we've created a new symbol (:this_also_should_not_be_in_the_symbols_collection) in the test and then mapped all the symbols for comparison. Since we created the symbol before querying all_symbols, this test passes.
end
Дополнительное примечание о коанах: используйте операторы puts
, а также пользовательские тесты, если вы ничего не понимаете. Например, если вы видите:
string = "the:rain:in:spain"
words = string.split(/:/)
и понятия не имею, что может быть words
, добавьте строку
puts words
и запустите rake
в командной строке. Аналогично, тесты, подобные тому, который я добавил выше, могут быть полезны с точки зрения понимания некоторых нюансов Ruby.