ruby-on-rails - 向 rspec 输出添加额外的文档

标签 ruby-on-rails rspec

因此,虽然我喜欢 Cucumber 的集成测试可读性以及为我们提供可以轻松与客户共享的文档的能力,但从开发和测试速度的角度来看,我也发现它很麻烦。

我今天想到,如果我可以将消息打印为记录“步骤”的 RSpec 文档格式,那么我可以轻松地复制 Gherkin 的业务功能,但具有 RSpec 的简单性。但我想不出办法来做到这一点。

我想要的是这样的:

describe "Login and Authorization Tests" do
  before (:each) do
    docs "Given I have a user"
    @user = FactoryGirl.create(:user)
  end

  it "A user can belong to one or more user roles" do
    docs "And the user has no roles assigned"
    @user.roles.length.should eq 0
    docs "When I add two roles"
    @user.roles << FactoryGirl.create(:role)
    @user.roles << FactoryGirl.create(:role)

    @user.reload
    docs "Then the user should have two roles assigned"
    @user.roles.length.should eq 2        
  end
end

并在文档中获取它

User
  Login and Authorization Tests
    A user can belong to one or more user roles
      Given I have a user
      And the user has no roles assigned"
      When I add two roles
      Then the user should have two roles assigned

请注意,来自“之前”的消息也显示在文档中,并且会在其下方的每个测试中显示该行。

我正在考虑 fork ,看看我是否可以添加类似这样的东西,但在我这样做之前,有人知道这样的东西是否已经可行了吗?

最佳答案

我还联系了 RSpec 开发团队,那里有人发布了这个名为 rspec-longrun 的附加组件,它可以重新用于此目的。我还没有机会尝试,但看起来很有前途。作为奖励,它包括计时信息。

rspec-longrun:https://github.com/mdub/rspec-longrun

rspec-dev 上的线程:https://github.com/rspec/rspec-dev/issues/34

关于ruby-on-rails - 向 rspec 输出添加额外的文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13049841/

相关文章:

ruby-on-rails - 测试委托(delegate)给另一个对象的方法

ruby-on-rails - Rspec, shoulda, validate_uniqueness_of 与范围和错误的错误信息

ruby-on-rails - rails : how to set json format for redirect_to

ruby-on-rails - Excel 链接不会加载页面,但当链接粘贴到浏览器中时它可以工作。

mysql - Rails 测试数据库比开发数据库快 10 倍

ruby - Rspec 多个规范文件夹

ruby-on-rails - 我如何将 rspec 与已清理的 YAML 固定装置一起使用?

ruby-on-rails - 我是否正确地在 Heroku + Unicorn 中预加载了应用程序?

ruby-on-rails - 如何获取 rails 表单构建器将为某个字段生成的 HTML 'name' 属性?

ruby-on-rails - 造型 'collection_radio_buttons'