Method: RSpec::ApiGen#instance_methods

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

#instance_methods(&block) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/rspec-apigen/apigen.rb', line 89

def instance_methods(&block)
  clazz = describes
  describe "Public Instance Methods" do
    # Check if we are testing a module - in that case construct a new class that includes that Module
    # so that we can test this Module
    subject do
      x = Class.new
      x.send(:include, clazz)
      x.new
    end if clazz.class == Module

    meth_ctx = Method.new

    # TODO - how do I find which methods was defined on the clazz and not inherited ?
    def_methods = clazz.public_instance_methods - Object.public_instance_methods
    current_context = self
    def_methods.each do |meth_name|
      MetaHelper.create_singleton_method(meth_ctx, meth_name) do |*args, &example_group|
        current_context.create_scenarios_for(meth_name, :args => args, &example_group)
      end
    end
    meth_ctx.instance_eval(&block)
  end
end