Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAntoine Boillot
10,466 PointsWhy is the assert_match method considered as 2 assertions ?
Hi all,
I was running some tests in Ruby and I noticed that the snippet of code below is considered as 2 assertions :
def test_assert_match
assert_match /world/, 'hello world'
end
How come ?
Thanks a lot!
1 Answer
David O' Rojo
11,051 PointsIt is because in its implementation, assert_match
uses two calls to assert: one to check that the given matcher (regepx) responds to =~
, and one to check that the matcher and the string do match.
def assert_match matcher, obj, msg = nil
msg = message(msg) { "Expected #{mu_pp matcher} to match #{mu_pp obj}" }
assert_respond_to matcher, :"=~"
matcher = Regexp.new Regexp.escape matcher if String === matcher
assert matcher =~ obj, msg
end
Antoine Boillot
10,466 PointsAntoine Boillot
10,466 Pointsthanks a lot!
Jim Withington
12,025 PointsJim Withington
12,025 PointsThanks! I wondered about this, too!