【问题标题】:RSpec can't find nested formatterRSpec 找不到嵌套格式化程序
【发布时间】:2014-07-11 00:54:41
【问题描述】:

我正在尝试仅为 Ruby(而不是 Rails)运行 rspec,以获取一个简单的 Ruby 文件。我正在使用 Ruby 进行 Tut+ TDD 测试。

我有一个competition 目录,其中有一个lib 文件夹和spec 文件夹。

├── lib  
│   ├── competition.rb  
│   └── team.rb  
└── spec  
    └── competition_spec.rb  

当我运行rspec 时,我得到了这个错误。我以前可以发誓从事 rspec 工作。我不知道发生了什么。

competition :> rspec spec
/Users/akh88/.rvm/gems/ruby-1.9.3-p547/gems/rspec-core-> 3.0.2/lib/rspec/core/formatters.rb:167:in `find_formatter': Formatter 'nested' unknown - maybe you meant 'documentation' or 'progress'?. (ArgumentError)

我的competition_spec.rb

require_relative "../lib/competiiton.rb"  
require_relative "../lib/team.rb"  

describe Competition do
  let(:competition) {Competition.new}
  let(:team) {Team.new}

  context "having no questions" do
    before { competition.questions = [] }

    it "doesn't accept any teams" do
      expect do
        team.enter_competition(competition)
      end.to raise_error Competition::Closed
    end
  end
end

我的rvm 默认 Ruby 版本在 Mac OSX 10.9.4 上是 1.9.1。

【问题讨论】:

  • 您在主文件夹中有.rspec 文件吗?它可能包含错误的格式化程序。
  • competition_spec.rb/spec dir..right 下?
  • 是的,competition_spec 在 /spec 中

标签: ruby testing rspec tdd


【解决方案1】:

nested 格式化程序在 RSpec 1 中使用。它在 RSpec 2 中重命名为 documentation

也许您在命令行或.rspec 文件中指定了nested?然后您需要指定--format documentation

您是否在某处设置了config.formatter = nested,可能是您的spec_helper.rb 文件?删除它。

您本可以从 v1 更新 RSpec gem(运行测试的命令从 spec 更改为 rspec,但很难错过)。您可以使用gem list rspec 查看版本。

或者,您可能会错过您碰巧调用nestedcustom formatter 的负载。

【讨论】:

  • 谢谢,这正是问题所在。我 cd 进入我的根目录,打开 .rspec 文件,然后将“--format nested --color”更改为“--format documentation --color”,这似乎可以解决问题。我的 rspec 命令现在可以工作了。
【解决方案2】:

我的 .rspec 文件只有

--color

我仍然收到此错误。

我明确设置为

--format documentation --color

现在它可以工作了。

【讨论】:

    猜你喜欢
    • 2014-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多