类似于SimpleCov 计算用户模型的 0% 覆盖率,但没有乐趣。
我相信(/希望?)我正在遵循希望将 Spring 与 SimpleCov 一起使用中的建议?.
随着“加载并启动 simplecov”代码在spec/rails_helper.rb
Spring 下运行,我的User
类在加载devise_for
simplecovroutes.rb
之前被加载。
在没有 Spring 的情况下运行 -例如,$ rspec
- 一切都很好。
我缺少什么让它在 Spring 下工作?
- ruby 2.2.1p85(2015-02-26 修订版 49769)[x86_64-darwin15]
- simplecov 0.12.0
- 导轨 4.2.5
- 春天 1.6.3
- 设计 3.5.6
- factory_girl 4.5.0
- factory_girl_rails 4.6.0
spec/rails_helper.rb
:
ENV['RAILS_ENV'] ||= 'test'
if ENV['RAILS_ENV'] == 'test'
puts 'loading simplecov'
require 'simplecov'
SimpleCov.start 'rails'
end
require File.expand_path('../../config/environment', __FILE__)
[...]
app/models/user.rb
class User
puts 'loading User'
puts caller
[...]
config/routes.rb
:
Rails.application.routes.draw do
scope '(:locale)', locale: /en|es/ do
root to: 'home#index'
devise_for :users # this is line 6
输出:
$ spring stop; spring rspec
Spring is not running
loading User
<project-path>/app/models/user.rb:2:in `<top (required)>'
<gems-path>/activesupport-4.2.5/lib/active_support/dependencies.rb:457:in `load'
<gems-path>/activesupport-4.2.5/lib/active_support/dependencies.rb:457:in `block in load_file'
<gems-path>/activesupport-4.2.5/lib/active_support/dependencies.rb:647:in `new_constants_in'
<gems-path>/activesupport-4.2.5/lib/active_support/dependencies.rb:456:in `load_file'
<gems-path>/activesupport-4.2.5/lib/active_support/dependencies.rb:354:in `require_or_load'
<gems-path>/activesupport-4.2.5/lib/active_support/dependencies.rb:494:in `load_missing_constant'
<gems-path>/activesupport-4.2.5/lib/active_support/dependencies.rb:184:in `const_missing'
<gems-path>/activesupport-4.2.5/lib/active_support/inflector/methods.rb:261:in `const_get'
<gems-path>/activesupport-4.2.5/lib/active_support/inflector/methods.rb:261:in `block in constantize'
<gems-path>/activesupport-4.2.5/lib/active_support/inflector/methods.rb:259:in `each'
<gems-path>/activesupport-4.2.5/lib/active_support/inflector/methods.rb:259:in `inject'
<gems-path>/activesupport-4.2.5/lib/active_support/inflector/methods.rb:259:in `constantize'
<gems-path>/activesupport-4.2.5/lib/active_support/dependencies.rb:566:in `get'
<gems-path>/activesupport-4.2.5/lib/active_support/dependencies.rb:597:in `constantize'
<gems-path>/devise-3.5.6/lib/devise.rb:292:in `get'
<gems-path>/devise-3.5.6/lib/devise/mapping.rb:81:in `to'
<gems-path>/devise-3.5.6/lib/devise/mapping.rb:76:in `modules'
<gems-path>/devise-3.5.6/lib/devise/mapping.rb:93:in `routes'
<gems-path>/devise-3.5.6/lib/devise/mapping.rb:160:in `default_used_route'
<gems-path>/devise-3.5.6/lib/devise/mapping.rb:70:in `initialize'
<gems-path>/devise-3.5.6/lib/devise.rb:326:in `new'
<gems-path>/devise-3.5.6/lib/devise.rb:326:in `add_mapping'
<gems-path>/devise-3.5.6/lib/devise/rails/routes.rb:238:in `block in devise_for'
<gems-path>/devise-3.5.6/lib/devise/rails/routes.rb:237:in `each'
<gems-path>/devise-3.5.6/lib/devise/rails/routes.rb:237:in `devise_for'
<project-path>/config/routes.rb:6:in `block (2 levels) in <top (required)>'
<gems-path>/actionpack-4.2.5/lib/action_dispatch/routing/mapper.rb:817:in `scope'
<project-path>/config/routes.rb:3:in `block in <top (required)>'
<gems-path>/actionpack-4.2.5/lib/action_dispatch/routing/route_set.rb:434:in `instance_exec'
<gems-path>/actionpack-4.2.5/lib/action_dispatch/routing/route_set.rb:434:in `eval_block'
<gems-path>/actionpack-4.2.5/lib/action_dispatch/routing/route_set.rb:412:in `draw'
<project-path>/config/routes.rb:1:in `<top (required)>'
<gems-path>/activesupport-4.2.5/lib/active_support/dependencies.rb:268:in `load'
<gems-path>/activesupport-4.2.5/lib/active_support/dependencies.rb:268:in `block in load'
<gems-path>/activesupport-4.2.5/lib/active_support/dependencies.rb:240:in `load_dependency'
<gems-path>/activesupport-4.2.5/lib/active_support/dependencies.rb:268:in `load'
<gems-path>/railties-4.2.5/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'
<gems-path>/railties-4.2.5/lib/rails/application/routes_reloader.rb:40:in `each'
<gems-path>/railties-4.2.5/lib/rails/application/routes_reloader.rb:40:in `load_paths'
<gems-path>/railties-4.2.5/lib/rails/application/routes_reloader.rb:16:in `reload!'
<gems-path>/railties-4.2.5/lib/rails/application/routes_reloader.rb:26:in `block in updater'
<gems-path>/activesupport-4.2.5/lib/active_support/file_update_checker.rb:75:in `call'
<gems-path>/activesupport-4.2.5/lib/active_support/file_update_checker.rb:75:in `execute'
<gems-path>/railties-4.2.5/lib/rails/application/routes_reloader.rb:27:in `updater'
<gems-path>/railties-4.2.5/lib/rails/application/routes_reloader.rb:7:in `execute_if_updated'
<gems-path>/railties-4.2.5/lib/rails/application/finisher.rb:69:in `block in <module:Finisher>'
<gems-path>/railties-4.2.5/lib/rails/initializable.rb:30:in `instance_exec'
<gems-path>/railties-4.2.5/lib/rails/initializable.rb:30:in `run'
<gems-path>/railties-4.2.5/lib/rails/initializable.rb:55:in `block in run_initializers'
<ruby-path>/lib/ruby/2.2.0/tsort.rb:226:in `block in tsort_each'
<ruby-path>/lib/ruby/2.2.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
<ruby-path>/lib/ruby/2.2.0/tsort.rb:429:in `each_strongly_connected_component_from'
<ruby-path>/lib/ruby/2.2.0/tsort.rb:347:in `block in each_strongly_connected_component'
<ruby-path>/lib/ruby/2.2.0/tsort.rb:345:in `each'
<ruby-path>/lib/ruby/2.2.0/tsort.rb:345:in `call'
<ruby-path>/lib/ruby/2.2.0/tsort.rb:345:in `each_strongly_connected_component'
<ruby-path>/lib/ruby/2.2.0/tsort.rb:224:in `tsort_each'
<ruby-path>/lib/ruby/2.2.0/tsort.rb:203:in `tsort_each'
<gems-path>/railties-4.2.5/lib/rails/initializable.rb:54:in `run_initializers'
<gems-path>/railties-4.2.5/lib/rails/application.rb:352:in `initialize!'
<project-path>/config/environment.rb:5:in `<top (required)>'
<gems-path>/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `require'
<gems-path>/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `block in require'
<gems-path>/activesupport-4.2.5/lib/active_support/dependencies.rb:240:in `load_dependency'
<gems-path>/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `require'
<gems-path>/spring-1.6.3/lib/spring/application.rb:92:in `preload'
<gems-path>/spring-1.6.3/lib/spring/application.rb:143:in `serve'
<gems-path>/spring-1.6.3/lib/spring/application.rb:131:in `block in run'
<gems-path>/spring-1.6.3/lib/spring/application.rb:125:in `loop'
<gems-path>/spring-1.6.3/lib/spring/application.rb:125:in `run'
<gems-path>/spring-1.6.3/lib/spring/application/boot.rb:18:in `<top (required)>'
<ruby-path>/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
<ruby-path>/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
-e:1:in `<main>'
Running via Spring preloader in process 25001
loading simplecov
[...]
Coverage report generated for RSpec to <project-path>/coverage. 212 / 368 LOC (57.61%) covered.
蒂亚!