【问题标题】:Rspec Output Format: DocumentationRspec 输出格式:文档
【发布时间】:2011-07-02 07:30:08
【问题描述】:

当我运行 rspecrake rspec 并且我的测试不正常时,我收到一条错误消息。但是,当我的测试正常时,我只会得到“..”。没有其他输出。我怎样才能让它打印出类似的东西:

A User .... can only have one name
A User .... can ...

【问题讨论】:

    标签: ruby-on-rails ruby rspec


    【解决方案1】:

    来自rspec 帮助页面

    $ rspec --help
    Usage: rspec [options] [files or directories]
    
        -f, --format FORMATTER           Choose a formatter
                                           [p]rogress (default - dots)
                                           [d]ocumentation (group and example names)
                                           [h]tml
                                           [t]extmate
                                           custom formatter class name
    

    传递-f 参数。而不是

    $ rake rspec
    

    运行

    $ rspec spec --format d
    

    或短格式:

    $ rspec -fd
    

    如果您希望配置是永久的,请在项目的根目录中创建一个.rspec 文件并将配置写入那里。

    【讨论】:

    • rspec -fd 如果你想要它简短而甜美。 rspec -c -fd 如果您想在屏幕上看到彩色输出:)
    • 您也可以将此选项设为默认值,将它们放入您的.rspec 文件中。我有--color --tty --format documentation(每行一个--option)。
    【解决方案2】:

    在您的spec/spec_helper

    RSpec.configure do |config|
      config.formatter = :documentation
    end
    

    因此您不必每次都运行标志。

    【讨论】:

      【解决方案3】:

      用途:

      rspec spec --format documentation
      

      【讨论】:

      • 我认为它确实如此 - 有问题的命令完全符合问题的要求。尽管如此,已经有一个(接受的)答案说明了同样的事情,所以这个答案并没有增加任何实际价值。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-07-12
      • 1970-01-01
      • 1970-01-01
      • 2012-12-19
      • 2015-02-09
      • 1970-01-01
      • 2016-07-20
      相关资源
      最近更新 更多