You can use self.class.description to get this information:
it "has page title Admin" do layout = self.class.description # => "admin_layout.html.erb" end
However, keep in mind that this will only issue the first parent description. Therefore, if you have contexts in your describe block, then the examples in the contexts will give the context name for self.class instead of the name of the describe block. In this case, you can use metadata:
describe "admin_layout.html.erb", :layout => "admin_layout.html.erb" context "foo" do it "has page title Admin" do layout = example.metadata[:layout] end end end
If you need a top-level description, you can use self.class.top_level_description :
RSpec.describe "Foo", type: :model do context "bar" do it "is part of Foo" do self.class.top_level_description
source share