将额外的文档添加到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

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

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

我还联系了RSPEC开发团队,那里有人发布了此附加组件,称为Rspec-Longrun,可以为此重新使用。我还没有机会尝试一下,但是看起来很有希望。作为奖励,它包括定时信息。

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

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

您可以尝试牛排,但是区别不大。或者,您可以尝试使用RSPEC匹配器的黄瓜。在最后情况下,您可以分叉RSPEC并添加新的格式

最新更新