Created
December 20, 2017 03:17
-
-
Save vglebov/76ca216f16c9a24ce716f181a1a710de to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Какую операцию нужно поставить вместо <<operation>>, чтобы тест прошел? | |
def call_unless(a, b) | |
unless a.nil? <<operation>> b.nil? | |
:then | |
else | |
:else | |
end | |
end | |
describe 'Человеку легко ошибиться с выбором операции в "unless a.nil? operation b.nil? then ... else ... end", ' do | |
[ | |
[:not_nil, :not_nil, :then], | |
[nil, :not_nil, :else], | |
[:not_nil, nil, :else], | |
[nil, nil, :else], | |
].each do |a, b, expected| | |
it "когда a=#{a.inspect} и b=#{b.inspect}, то ожидаем переход по ветке #{expected.inspect}" do | |
expect(call_unless(a, b)).to eql(expected) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
а лучше вообще не пользоваться unless в сложных условиях. Чем меньше инверсий в условиях тем проще.