【问题标题】:Rspec + Spring not workingRspec + Spring 不工作
【发布时间】:2015-06-01 15:06:39
【问题描述】:

我最近开始使用 Rails 进行开发。我遇到了 Spring 的问题。

我正在使用带有 Rspec 的 Spring 来加速我的测试。尽管测试运行良好,但它似乎并没有像通常那样给我带来巨大的速度提升。我怀疑它工作不正常。

我正在使用 ruby​​ 2.2.0 和 Rails 4.2

我在安装过程中遵循了以下步骤:

  • 将 gem 'spring' 添加到 gem 文件中
  • 捆绑安装
  • 我使用 bundle exec spring binstub --all 'springified' 可执行文件

使用 bin/spring 状态显示 spring 正在运行:

Spring is running:

16641 spring server | autoclave | started 12 mins ago
16899 spring app    | autoclave | started 10 mins ago | test mode

在使用 rspec 时,我尝试了以下命令来运行测试:

bundle exec bin/rspec , bundle exec rspec

spring 的 github 文档建议使用“spring-commands-rspec”gem 将 Spring 与 rspec 结合使用。

我尝试安装那个 gem 并生成 bin/rspec,但没有任何区别。

请帮忙

【问题讨论】:

    标签: ruby-on-rails ruby spring ruby-on-rails-4 rspec


    【解决方案1】:

    我的错

    原来我在每次测试之前使用Rails.application.load_seed 为我的集成测试加载种子。这些导致我的单元测试变慢。

    我从以下位置删除了Rails.application.load_seed

    config.before(:each) do
        DatabaseCleaner.clean
        Rails.application.load_seed
    end
    

    现在测试运行正常。

    【讨论】:

      【解决方案2】:

      您也可以将 Rails.application.load_seed 放入 config.before(:suite) 块中。

      【讨论】:

        猜你喜欢
        • 2020-02-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-10-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-04-23
        相关资源
        最近更新 更多