1

我想在 Rails 4 中通过 Rake 使用 Cucumber 进行 BDD。我已经安装并连接了它spring以加快测试速度,但它们运行的​​时间比预期的要长得多。当 Spring 处于活动状态时,测试肯定会运行得更快,但 Cucumber 总是有大约 2 秒的启动时间,即使没有要运行的功能/场景。例如:

$ bin/spring status
Spring is not running.

$ time bin/rake cucumber
/Users/alans/.rvm/rubies/ruby-2.1.1/bin/ruby -S bundle exec cucumber  --profile default
Using the default profile...
0 scenarios
0 steps
0m0.000s
bin/rake cucumber  0.08s user 0.02s system 3% cpu 3.463 total

$ bin/spring status
Spring is running:
64383 spring server | cucumber_test | started 48 secs ago
64384 spring app    | cucumber_test | started 48 secs ago | test mode    

$ time bin/rake cucumber
/Users/alans/.rvm/rubies/ruby-2.1.1/bin/ruby -S bundle exec cucumber  --profile default
Using the default profile...
0 scenarios
0 steps
0m0.000s
bin/rake cucumber  0.08s user 0.02s system 4% cpu 2.098 total

bin/rake用于运行是Spring Readme中定义的。在没有耙子的情况下运行 spring 会产生更快的预期时间。

$ time spring cucumber
Using the default profile...
0 scenarios
0 steps
0m0.000s
spring cucumber  0.06s user 0.01s system 13% cpu 0.537 total

问题

如何设置 Cucumber、Spring 和 Rake,以便使用 Rake 和不使用 Rake 一样快速运行测试?



更多详细信息

我的环境是在运行 10.9.3 的 SSD 的 Mac 上安装 ruby​​-2.1.1 和 rails 4.1.1 的 RVM。

这就是我正在做的事情:

  1. 创建一个应用程序

    rails new cucumber_test -T
    
  2. 使用以下内容更新 gem 文件:

    group :development, :test do
    
      gem 'cucumber-rails', :require => false
      gem 'database_cleaner'
      gem 'rspec-rails'
      gem 'spring'
      gem 'spring-commands-cucumber'
    
    end
    

    然后运行:

    bundle install
    

    我也尝试在 :development 环境中保留默认列表,spring但这也没有加快速度。

  3. 运行黄瓜生成器:

    rails g cucumber:install
    
  4. 更新 Spring binstubs:

    bundle exec spring binstub --all
    

    返回:

    * bin/rake: spring already present
    * bin/cucumber: generated with spring 
    * bin/rails: spring already present
    

这是我运行时间测试的地方。当 Spring 停止时,Cucumber 始终需要更长的时间才能运行。即使在运行 Spring 的情况下,使用 Rake 时,在测试套件实际启动之前似乎总是有 2 秒的开销。这就是我要消除的。

4

0 回答 0