【问题标题】:Can't get rspec working with Zeus无法让 rspec 与 Zeus 一起工作
【发布时间】:2017-07-23 20:56:48
【问题描述】:

我已阅读所有关于如何使用 zeus 在 Rails 上获取 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 运行来恢复......太令人沮丧了。

【问题讨论】:

    标签: ruby-on-rails rspec zeus


    【解决方案1】:

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

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

    修复它:

    1. 升级 rr(“bundle update 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
    

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

    【讨论】:

      【解决方案2】:

      所以我遇到了同样的问题,通过调试发现测试正在运行,但没有输出。

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

      作为警告,第一个链接中的一个 cmets 提到放置 config.reset 会产生不良副作用,但我还没有遇到任何...。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-02-29
        • 2011-04-25
        • 2014-11-22
        • 2014-05-15
        • 2010-10-16
        • 2019-11-27
        • 2017-02-12
        相关资源
        最近更新 更多