在 RSpec/Rails 验收测试中,有没有办法将消息推送到 RSpec 输出并保持良好的缩进? [英] In RSpec/Rails acceptance tests,is there any way to push messages to the RSpec output and maintain the nice indentation?

查看:33
本文介绍了在 RSpec/Rails 验收测试中,有没有办法将消息推送到 RSpec 输出并保持良好的缩进?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的验收测试 (RSpec/Capybara) 在一个 it...do 块下有一些很长的步骤序列,我想手动将每个步骤的一些附加文档添加到RSpec 文档输出.

My acceptance tests (RSpec/Capybara) have some long sequences of steps all under a single it...do block, and I'd like to manually add some additional documentation of each step into the RSpec documentation output.

RSpec 输出(以文档格式)目前的样子:

So where the RSpec output (in documentation format) currently looks like:

FooController
  New user creates account and creates profile
    it passes

在长长的步骤序列中,我想向输出推送一些额外的信息:

Within the long sequence of steps I'd like to push some additional info to the output:

FooController
  New user creates account and creates profile
    ... new user saw signup page!
    ... new user got email confirmation!
    ... confirmation link worked!
    ... new user saw empty profile!
    ... new user filled in profile
    it passes

就记录应用而言,这些额外的语句比带有单个通过"结果消息的大黑盒子要好.

In terms of documenting the app, those extra statements would be better than a large black box with a single 'it passed' result message.

由于显然没有办法使用多个 it...do 块来构建验收测试的长步骤序列,我希望有一种简单的方法来推送附加消息到 RSpec 输出流,理想情况下,它们被缩进和显示(红色/绿色),就好像它们是 pat 或单独的 it...do 示例.

Since there is apparently no way to use multiple it...do blocks to build the long sequence of steps for a acceptance test, I'm hoping there is a simple way to push additional messages to the RSpec output stream, ideally with them being indented and displayed (red/green) as if they were pat or separate it...do examples.

推荐答案

这就是我所做的...在我的规范中添加了 nextstep("message") 方法,使用 awesome_print gem 将message"输出到控制台,这样我就可以给它上色,也给记录器上色.

Here's what I did... added a nextstep("message") method to my specs that outputs "message" to the console using awesome_print gem so I can color it, and also to the logger.

  def nextstep(txt)
    $step += 1
    @speclog.debug ''
    @speclog.debug ''
    @speclog.debug "#{$scene}, step: #{$step}: " + txt
    ap (' ' * ($indent * 2 - 1)) + "step: #{$step}: " + txt, {:color => {:string => :blueish}}
  end

有点hackish,但它确实在运行rspec时为我们提供了非常好的描述性输出,例如如果我们有

A little hackish, but it does give us very nice descriptive output when running rspec, for example if we have

it "New user creates account and creates profile" do
   # some assertions
   nextstep "... new user saw signup page!"
   # some assertions
   nextstep " ... new user got email confirmation!"
   # some assertions
   nextstep " ... confirmation link worked!"
   # some assertions
   nextstep "... new user saw empty profile!"
   # some assertions
   nextstep "... new user filled in profile"
end

我们得到了问题中显示的更具描述性的规范输出(如果出现故障,我们会看到我们正在执行的步骤):

we get the more descriptive spec output as shown in the question (and if there's a failure we see the step we were on):

   step 1: ... new user saw signup page!
   step 2: ... new user got email confirmation!
   step 3: ... confirmation link worked!
   step 4: ... new user saw empty profile!
   step 5: ... new user filled in profile"

这篇关于在 RSpec/Rails 验收测试中,有没有办法将消息推送到 RSpec 输出并保持良好的缩进?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆