Method: RSpec::ApiGen#static_methods

Defined in:
lib/rspec-apigen/apigen.rb

#static_methods(&block) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/rspec-apigen/apigen.rb', line 69

def static_methods(&block)
  clazz = describes
  describe "Public Static Methods" do
    static_context = Method.new

    # TODO - how do I find which methods was defined on the clazz and not inherited ?
    def_methods = clazz.public_methods - Object.methods + %w[new]
    current_context = self

    # add methods on the context - one for each public static method
    def_methods.each do |meth_name|
      MetaHelper.create_singleton_method(static_context, meth_name) do |*args, &example_group|
        current_context.subject { clazz }
        current_context.create_scenarios_for(meth_name, :args => args, &example_group)
      end
    end
    static_context.instance_eval(&block)
  end
end