RSpec 允许您通过执行以下操作在 before(:each) block 中获取当前运行的测试方法名称:
Spec::Runner.configure do |config|
config.before :each do |x|
x.method_name # returns 'should be cool'
end
end
这是为了这样的测试:
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe 'Hello world' do
it 'should be cool' do
# test code
end
end
是否有可能在 before block 中获得完整的测试名称及其所描述的内容(又名“Hello World should be cool”)?
最佳答案
在 RSpec 2.0 中你可以使用(我不确定这是否是最好的方法但它有效)
x.example.metadata[:example_group][:full_description]
至于 RSpec 1.X 我不知道。这可能就是您要的...
关于ruby-on-rails - 从 before(:each) block) 中获取完整的 RSpec 测试名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3816322/