我正在编写一些规范来测试具有Rails生成器的gem中的模板文件。我想在下面的rspec规范中访问“admin_layout.html.erb”:
require 'spec_helper'
describe "admin_layout.html.erb" do
it "has page title Admin" do
HERES WHERE I WOULD LOVE TO HAVE ACCESS TO "admin_layout.html.erb" AS A VARIABLE
end
end
答案 0 :(得分:13)
您可以使用self.class.description
获取此信息:
it "has page title Admin" do
layout = self.class.description
# => "admin_layout.html.erb"
end
但是,请记住,这只会显示第一个父母的描述。因此,如果您的describe
块中有上下文,则上下文中的示例将为self.class
而不是describe
块的名称提供上下文名称。在这种情况下,您可以使用元数据:
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