Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of the pound (#) symbol in front of method names in unit tests?

I see many test descriptions such as in Mocha using the # symbol in front of methods. What is the purpose and origin of this? I've been doing it for years like a lemming so I figured it was time to ask why :)

describe('#myMethod()', function() { ... })
like image 527
cyberwombat Avatar asked May 03 '16 18:05

cyberwombat


1 Answers

I first saw this convention in Ruby, where class methods are referred to in text as Class.method (or, less frequently, Class::method) and instance methods as Class#method. The difference in punctuation is needed both to tell the reader what kind the method is and to disambiguate class and instance methods with the same name (not that having those is usually a good idea).

The test naming convention probably came to Javascript along with RSpec syntax (describe, it, etc.).

like image 77
Dave Schweisguth Avatar answered Sep 21 '22 20:09

Dave Schweisguth