ShockwaveNN
ShockwaveNN

Reputation: 2268

Rspec - access describe name in describe context, not in `it`

I have such simplifyed rspec code:

require 'rspec'

describe 'DescribeTitle' do
  describe_name = self.class.description
  p describe_name
  it 'should do something' do
    expect(true).to be_truthy
  end
end

I want to access 'DescribeTitle' befor entering to it.

I found out I can use self.class.description to get it, but seems it works only inside it's.

How can I achieve that?

Upvotes: 1

Views: 441

Answers (1)

Andrey Deineko
Andrey Deineko

Reputation: 52357

In your case

self.class
#=> Class

Thus, because you are in the context of the DescribeTitle already, you need to just use self.description instead of self.class.description:

self.description
#=> DescribeTitle

Upvotes: 1

Related Questions