假设我有一个测试套件,我首先给describe
一个常量:
describe SomeExcessivelyLong::And::Maybe::Namespaced::Classname do
# Convenience reference for tests
let(:klass) { SomeExcessivelyLong::And::Maybe::Namespaced::Classname }
end
是否存在使subject
多余的现有方法,例如let(:klass)
或类似的方法?如何访问传递给describe
的第一个值?
答案 0 :(得分:5)
默认情况下,subject
将是describe块中类的新实例,因此您应该可以调用subject.class
来获取类本身。
describe SomeExcessivelyLong::And::Maybe::Namespaced::Classname do
it "should do something" do
subject.class.should be_a SomeExcessivelyLong::And::Maybe::Namespaced::Classname
end
end
答案 1 :(得分:2)
在您的示例中调用described_class
:
describe SomeExcessivelyLong::And::Maybe::Namespaced::Classname do
it "should do something" do
described_class.should be SomeExcessivelyLong::And::Maybe::Namespaced::Classname
end
end