【问题标题】:Class methods: describe "#my_class_method" or describe "#self.my_class_method"?类方法:描述“#my_class_method”还是描述“#self.my_class_method”?
【发布时间】:2012-07-18 09:01:07
【问题描述】:

我尝试进行符合最佳实践的 RSpec 测试,并且我知道在测试实例方法时,可以这样做

describe "#my_instance_method" do ... end

但是类方法呢?我应该在描述字符串中添加self. 吗?

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

感谢您的意见!

【问题讨论】:

    标签: ruby testing rspec


    【解决方案1】:

    来自“How to name RSpec describe blocks for methods”:

    • 使用磅#method 作为实例方法
    • 类方法使用点.method

    在你的例子中:

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

    【讨论】:

    猜你喜欢
    • 2011-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-18
    • 2014-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多