【问题标题】:using the --format documentation option with Rspec and Rake将 --format 文档选项与 Rspec 和 Rake 一起使用
【发布时间】:2013-12-10 17:28:44
【问题描述】:

我正在学习 Ruby,最近我建立了一个小项目,我正在编写一个 API。

目前我有 2 个类,一个称为 API,它继承自 Grape

class API < Grape::API

(第一个快速问题,在这个类中我可以有普通的方法,比如 def say_hello 吗?还是只是 web 方法?)

还有一个我称之为 APIHelpers

我已经设置了 2 个规格文件

api_spec.rb APIHelpers_spec.rb

这是我的 Rakefile 的内容:

require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new do |t|
  t.rspec_opts = '--format documentation'
  t.pattern = ['spec/libs/*.rb']
end

task :default => :spec

当我运行 rake(我使用 Rubymine 6.0 作为我的 IDE)时,除了我添加的 2 个测试已通过之外,我没有从 Rspec 获得任何输出。

2 个示例,0 个失败,2 个通过 0.05642秒完成

使用 --format 文档,我本来希望从 describe 和 it 语句中看到整个结构。

有人知道如何使用 RubyMine 正确显示这些测试吗?

谢谢

【问题讨论】:

    标签: ruby-on-rails ruby rspec rubymine


    【解决方案1】:

    如果其他人遇到这个问题,这是我为解决这个问题所做的,

    我没有使用 Rake 来运行我的测试,而是使用了 Rspec 配置,添加到了 spec_helper 并在这段代码中添加

    RSpec.configure do |config|
      config.color_enabled = true
      config.tty = true
      config.formatter = :documentation
    
      config.expect_with :rspec do |c|
        c.syntax = :expect
      end
    end
    

    这解决了我的问题

    【讨论】:

    • 所有这些记录在哪里?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-01-08
    • 1970-01-01
    • 1970-01-01
    • 2020-07-26
    • 1970-01-01
    • 1970-01-01
    • 2013-04-24
    相关资源
    最近更新 更多