Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Class methods: describe "#my_class_method" or describe "#self.my_class_method"?

I try to have best-practice-conforming RSpec tests, and I know that when testing an instance method, one can do

describe "#my_instance_method" do ... end

But what about class methods? Should I add a self. to it in the description string?

describe "#self.my_class_method" do ... end

Thanks for your opinion!

like image 334
Joshua Muheim Avatar asked Dec 20 '22 18:12

Joshua Muheim


1 Answers

From "How to name RSpec describe blocks for methods":

  • use pound #method for instance methods
  • use dot .method for class methods

In your example:

describe "#my_instance_method" do
  # ...
end
describe ".my_class_method" do 
  # ...
end

A few examples from rspec-core: for class method, for instance method

like image 90
Stefan Avatar answered Dec 23 '22 06:12

Stefan