Skip to content
This repository

rake spec loads application twice #614

Closed
adamgotterer opened this Issue October 03, 2012 · 1 comment

2 participants

Adam Gotterer David Chelimsky
Adam Gotterer

During some debugging I realized that the application environment needs to get loaded twice when running rspec. The first time to load up rake itself and the second time when it calls off to rspec. Calling direct via /usr/local/rvm/rubies/ruby-1.9.3-p194/bin/ruby -S rspec spec/ is about twice as fast since it doesn't need to load rake first.

vagrant@lucid32:/vagrant/app$ rake spec 
                                               set_load_path: 0.002 sec
                                               set_load_path: 0.002 sec
                                               set_load_path: 0.001 sec
                                               set_load_path: 0.001 sec
                                               set_load_path: 0.001 sec
                                               set_load_path: 0.028 sec
                                          set_autoload_paths: 0.000 sec
                                          set_autoload_paths: 0.000 sec
                                          set_autoload_paths: 0.000 sec
                                          set_autoload_paths: 0.000 sec
                                          set_autoload_paths: 0.000 sec
                                          set_autoload_paths: 0.000 sec
                                           add_routing_paths: 0.000 sec
                                           add_routing_paths: 0.016 sec
                                           add_routing_paths: 0.000 sec
                                           add_routing_paths: 0.000 sec
                                           add_routing_paths: 0.000 sec
                                           add_routing_paths: 0.001 sec
                                                 add_locales: 0.000 sec
                                                 add_locales: 0.000 sec
                                                 add_locales: 0.000 sec
                                                 add_locales: 0.000 sec
                                                 add_locales: 0.000 sec
                                                 add_locales: 0.004 sec
                                              add_view_paths: 0.027 sec
                                              add_view_paths: 0.000 sec
                                              add_view_paths: 0.000 sec
                                              add_view_paths: 0.000 sec
                                              add_view_paths: 0.000 sec
                                              add_view_paths: 0.001 sec
                                     load_environment_config: 0.002 sec
                                     load_environment_config: 0.000 sec
                                     load_environment_config: 0.000 sec
                                     load_environment_config: 0.000 sec
                                     load_environment_config: 0.000 sec
                                     load_environment_config: 0.008 sec
                                       load_environment_hook: 0.000 sec
                                         load_active_support: 0.010 sec
                                          preload_frameworks: 0.000 sec
                                           initialize_logger: 0.031 sec
                                            initialize_cache: 0.001 sec
                             initialize_dependency_mechanism: 0.000 sec
                                              bootstrap_hook: 1.381 sec
                                              i18n.callbacks: 0.021 sec
                        active_support.initialize_whiny_nils: 0.011 sec
                         active_support.deprecation_behavior: 0.000 sec
                         active_support.initialize_time_zone: 0.206 sec
                                   action_dispatch.configure: 0.013 sec
        action_view.embed_authenticity_token_in_remote_forms: 0.000 sec
                                 action_view.cache_asset_ids: 0.000 sec
                           action_view.javascript_expansions: 0.000 sec
                                     action_view.set_configs: 0.000 sec
                                         action_view.caching: 0.000 sec
                                    action_controller.logger: 0.000 sec
               action_controller.initialize_framework_caches: 0.000 sec
                             action_controller.assets_config: 0.000 sec
                               action_controller.set_configs: 0.000 sec
                    action_controller.compile_config_methods: 0.000 sec
                           active_record.initialize_timezone: 0.000 sec
                                        active_record.logger: 0.000 sec
                                  active_record.identity_map: 0.000 sec
                                   active_record.set_configs: 0.000 sec
                           active_record.initialize_database: 0.327 sec
                                   active_record.log_runtime: 0.010 sec
                            active_record.set_reloader_hooks: 0.000 sec
                           active_record.add_watchable_files: 0.000 sec
                                        action_mailer.logger: 0.000 sec
                                   action_mailer.set_configs: 0.000 sec
                        action_mailer.compile_config_methods: 0.000 sec
                                 active_resource.set_configs: 0.000 sec
                                       sprockets.environment: 0.568 sec
                                              setup database: 0.056 sec
                          warn when configuration is missing: 0.000 sec
                                            load http errors: 0.000 sec
                              preload all application models: 0.000 sec
                                    include the identity map: 0.000 sec
                                       instantiate observers: 0.000 sec
                                                  setup_sass: 0.000 sec
                                           setup_compression: 0.000 sec
                                          append_assets_path: 0.000 sec
                                          append_assets_path: 0.000 sec
                                          append_assets_path: 0.001 sec
                                          append_assets_path: 0.001 sec
                                          append_assets_path: 0.000 sec
                                          append_assets_path: 0.011 sec
                                        prepend_helpers_path: 0.000 sec
                                        prepend_helpers_path: 0.000 sec
                                        prepend_helpers_path: 0.000 sec
                                        prepend_helpers_path: 0.000 sec
                                        prepend_helpers_path: 0.000 sec
                                        prepend_helpers_path: 0.001 sec
                                    load_config_initializers: 0.000 sec
                                    load_config_initializers: 0.000 sec
                                    load_config_initializers: 0.000 sec
                                    load_config_initializers: 0.000 sec
                                    load_config_initializers: 0.000 sec
                                    load_config_initializers: 0.234 sec
                                         engines_blank_point: 0.000 sec
                                          devise.url_helpers: 0.016 sec
                                             devise.omniauth: 0.000 sec
                              devise.mongoid_version_warning: 0.000 sec
              devise.fix_routes_proxy_missing_respond_to_bug: 0.012 sec
                                         engines_blank_point: 0.000 sec
                                         engines_blank_point: 0.000 sec
                                         engines_blank_point: 0.000 sec
                                         engines_blank_point: 0.000 sec
                                         engines_blank_point: 0.000 sec
                                     add_generator_templates: 0.001 sec
                        ensure_autoload_once_paths_as_subset: 0.000 sec
                                           add_builtin_route: 0.000 sec
                                      build_middleware_stack: 0.312 sec
                                      define_main_app_helper: 0.000 sec
                                       add_to_prepare_blocks: 0.000 sec
                                       run_prepare_callbacks: 0.535 sec
                                                 eager_load!: 0.000 sec
                                               finisher_hook: 0.185 sec
                                    set_routes_reloader_hook: 0.146 sec
                                 set_clear_dependencies_hook: 0.509 sec
                                  disable_dependency_loading: 0.000 sec
                                                     for all: 4.736 sec
/usr/local/rvm/rubies/ruby-1.9.3-p194/bin/ruby -S rspec spec/
                                               set_load_path: 0.001 sec
                                               set_load_path: 0.002 sec
                                               set_load_path: 0.001 sec
                                               set_load_path: 0.002 sec
                                               set_load_path: 0.001 sec
                                               set_load_path: 0.152 sec
                                          set_autoload_paths: 0.000 sec
                                          set_autoload_paths: 0.000 sec
                                          set_autoload_paths: 0.000 sec
                                          set_autoload_paths: 0.000 sec
                                          set_autoload_paths: 0.000 sec
                                          set_autoload_paths: 0.000 sec
                                           add_routing_paths: 0.000 sec
                                           add_routing_paths: 0.050 sec
                                           add_routing_paths: 0.000 sec
                                           add_routing_paths: 0.000 sec
                                           add_routing_paths: 0.000 sec
                                           add_routing_paths: 0.001 sec
                                                 add_locales: 0.000 sec
                                                 add_locales: 0.000 sec
                                                 add_locales: 0.000 sec
                                                 add_locales: 0.000 sec
                                                 add_locales: 0.000 sec
                                                 add_locales: 0.006 sec
                                              add_view_paths: 0.067 sec
                                              add_view_paths: 0.000 sec
                                              add_view_paths: 0.000 sec
                                              add_view_paths: 0.000 sec
                                              add_view_paths: 0.000 sec
                                              add_view_paths: 0.001 sec
                                     load_environment_config: 0.000 sec
                                     load_environment_config: 0.000 sec
                                     load_environment_config: 0.000 sec
                                     load_environment_config: 0.000 sec
                                     load_environment_config: 0.000 sec
                                     load_environment_config: 0.008 sec
                                       load_environment_hook: 0.000 sec
                                         load_active_support: 0.010 sec
                                          preload_frameworks: 0.000 sec
                                           initialize_logger: 0.064 sec
                                            initialize_cache: 0.001 sec
                             initialize_dependency_mechanism: 0.000 sec
                                              bootstrap_hook: 2.068 sec
                                              i18n.callbacks: 0.065 sec
                        active_support.initialize_whiny_nils: 0.009 sec
                         active_support.deprecation_behavior: 0.000 sec
                         active_support.initialize_time_zone: 0.291 sec
                                   action_dispatch.configure: 0.012 sec
        action_view.embed_authenticity_token_in_remote_forms: 0.000 sec
                                 action_view.cache_asset_ids: 0.000 sec
                           action_view.javascript_expansions: 0.000 sec
                                     action_view.set_configs: 0.000 sec
                                         action_view.caching: 0.000 sec
                                    action_controller.logger: 0.000 sec
               action_controller.initialize_framework_caches: 0.000 sec
                             action_controller.assets_config: 0.000 sec
                               action_controller.set_configs: 0.000 sec
                    action_controller.compile_config_methods: 0.001 sec
                           active_record.initialize_timezone: 0.000 sec
                                        active_record.logger: 0.000 sec
                                  active_record.identity_map: 0.000 sec
                                   active_record.set_configs: 0.000 sec
                           active_record.initialize_database: 0.289 sec
                                   active_record.log_runtime: 0.011 sec
                            active_record.set_reloader_hooks: 0.000 sec
                           active_record.add_watchable_files: 0.000 sec
                                        action_mailer.logger: 0.000 sec
                                   action_mailer.set_configs: 0.001 sec
                        action_mailer.compile_config_methods: 0.000 sec
                                 active_resource.set_configs: 0.000 sec
                                       sprockets.environment: 0.827 sec
                                              setup database: 0.054 sec
                          warn when configuration is missing: 0.000 sec
                                            load http errors: 0.000 sec
                              preload all application models: 0.000 sec
                                    include the identity map: 0.000 sec
                                       instantiate observers: 0.000 sec
                                                  setup_sass: 0.000 sec
                                           setup_compression: 0.000 sec
                                          append_assets_path: 0.000 sec
                                          append_assets_path: 0.000 sec
                                          append_assets_path: 0.000 sec
                                          append_assets_path: 0.000 sec
                                          append_assets_path: 0.000 sec
                                          append_assets_path: 0.067 sec
                                        prepend_helpers_path: 0.000 sec
                                        prepend_helpers_path: 0.000 sec
                                        prepend_helpers_path: 0.000 sec
                                        prepend_helpers_path: 0.000 sec
                                        prepend_helpers_path: 0.000 sec
                                        prepend_helpers_path: 0.001 sec
                                    load_config_initializers: 0.000 sec
                                    load_config_initializers: 0.000 sec
                                    load_config_initializers: 0.000 sec
                                    load_config_initializers: 0.000 sec
                                    load_config_initializers: 0.000 sec
                                    load_config_initializers: 0.156 sec
                                         engines_blank_point: 0.000 sec
                                          devise.url_helpers: 0.012 sec
                                             devise.omniauth: 0.000 sec
                              devise.mongoid_version_warning: 0.000 sec
              devise.fix_routes_proxy_missing_respond_to_bug: 0.055 sec
                                         engines_blank_point: 0.000 sec
                                         engines_blank_point: 0.000 sec
                                         engines_blank_point: 0.000 sec
                                         engines_blank_point: 0.000 sec
                                         engines_blank_point: 0.000 sec
                                     add_generator_templates: 0.001 sec
                        ensure_autoload_once_paths_as_subset: 0.000 sec
                                           add_builtin_route: 0.000 sec
                                      build_middleware_stack: 0.522 sec
                                      define_main_app_helper: 0.000 sec
                                       add_to_prepare_blocks: 0.000 sec
                                       run_prepare_callbacks: 0.038 sec
                                                 eager_load!: 3.754 sec
                                               finisher_hook: 0.014 sec
                                    set_routes_reloader_hook: 0.072 sec
                                 set_clear_dependencies_hook: 0.133 sec
                                  disable_dependency_loading: 0.000 sec
                                                     for all: 8.903 sec
David Chelimsky
Owner

This is a rails issue, not rspec, and is true for test/unit and minitest as well. The development environment is the default environment in rails, but we need to run rspec (or t/u or mt) in the "test" environment, so we have to shell out to a new process - thus the env gets loaded twice.

You can save time by using the rspec command directly.

HTH,
David

David Chelimsky dchelimsky closed this October 03, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.