2

我已经阅读了有关如何在与 zeus 一起使用的轨道上获取 rspec 的所有建议。特别是,我在spec/spec_helper.rb中注释掉了“require 'rspec/autorun'” :

# require 'rspec/autorun'

我在一个终端启动 zeus:

宙斯开始

然后在另一个终端运行 rspec:

宙斯 rspec 规范/控制器/source_configs_controller_spec.rb

然后得到……什么都没有。没有输出,没有响应,nada - 只是把我转回命令行。但是,如果我在spec_helper.rb中取消注释require 'rspec/autorun'并再次运行它,我会得到:


Failure/Error: post :create, {:account_id => @account.id, :source_config => valid_attributes.except(:account_id)}, {}
NoMethodError:
  undefined method `post' for #<RSpec::Core::ExampleGroup::Nested_2::Nested_1::Nested_1:0x007fbdff3032d8>

有任何想法吗?我觉得我花了更多的时间试图弄清楚这一点,而不是通过更快的 rspec 运行来恢复......太令人沮丧了。

4

2 回答 2

1

经过更多的挖掘和实验,看起来spec_helper.rb中的 rr(模拟框架)是罪魁祸首。我有

RSpec.configure do |config|
  config.mock_with :rr
  #...
end

要解决这个问题:

  1. 升级 rr(“捆绑更新 rr”)。
  2. 以不同的方式初始化 rr:

Gemfile

group :development, :test do
  gem "rr", :require => false # important to specify ":require => false"
  gem "rspec-rails"
  # (any other appropriate gems)
end

spec_helper.rb

require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'

# vvvv NOTE: this is how you enable rr now
require 'rr'

#require 'rspec/autorun'

# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}

RSpec.configure do |config|
  # ## Mock Framework
  #
  # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
  #
  # config.mock_with :mocha
  # config.mock_with :flexmock

  # vvvv NOTE: Make sure this line is commented out
  # config.mock_with :rr

  # ... other rspec config
end

很想听听其他人的想法 - 有没有更好的方法?

于 2013-12-02T18:43:38.510 回答
0

所以我遇到了同样的问题并使用一些调试发现测试正在运行,但没有输出。

到目前为止有效的是放在块config.reset的顶部RSpec.configure。我从这里得到了这个想法:https ://github.com/burke/zeus/issues/461 从这里得到了这个想法:How can I configure rspec to show output with spork?

作为警告,第一个链接中的一条评论提到 putconfig.reset有不良的副作用,但我还没有遇到任何....

于 2014-06-25T17:32:31.030 回答