ruby-on-rails - 从 before(:each) block) 中获取完整的 RSpec 测试名称

标签 ruby-on-rails ruby testing rspec

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/

相关文章:

ruby-on-rails - 每个 Controller 的 Rails 布局

ruby-on-rails - Gem install bundler && bundle 安装报错

android - 如何禁用/启用网络,在 Android 模拟器中切换到 Wifi?

testing - Netty SSL 处理程序单元测试

node.js - 在nodejs中测试后台进程(使用磁带)

ruby-on-rails - 如何在heroku上更新应用程序

ruby-on-rails - rails : For each Array giving Error?

ruby-on-rails - wkhtmltopdf 试图从 http 而不是文件加载

Ruby 字符串到类名

html - ruby on rails - 部分 CSS