Rcov doesn't play nicely with Rspec and namespaced classes #82

Closed
hahuang65 opened this Issue Sep 9, 2011 · 4 comments

Comments

Projects
None yet
3 participants

Using Rspec with Rcov, more specifically the RakeTask in Rspec, doesn't play nicely with Rcov.

Here is my RakeTask

    require 'rspec/core/rake_task'
    require 'cucumber/rake/task'

    namespace :rcov do

      rcov_options = %w{
        --rails
        --exclude osx\/objc,gems\/,spec\/,features\/,seeds\/
        --aggregate coverage/coverage.data
      }

      Cucumber::Rake::Task.new(:cucumber) do |t|
        t.cucumber_opts = "--format pretty"

        t.rcov = true
        t.rcov_opts = rcov_options
      end

      RSpec::Core::RakeTask.new(:rspec) do |t|
        t.spec_opts = ["--color"]
        t.pattern   = 'spec/**/*_spec.rb'
        t.rcov = true
        t.verbose = true
        t.rcov_opts = rcov_options
        t.rcov_opts += %w{--include views -Ispec}
      end

      desc "Run cucumber & rspec to generate aggregated coverage"
      task :all do |t|
        rm "coverage/coverage.data" if File.exist?("coverage/coverage.data")
        Rake::Task["rcov:cucumber"].invoke
        Rake::Task['rcov:rspec'].invoke
      end
    end

and the output when the Rspec section is run:

/Users/Hao/.rvm/rubies/ruby-1.8.7-p174/bin/ruby -S bundle exec rcov -Ispec:lib --rails --exclude osx\/objc,gems\/,spec\/,features\/,seeds\/ --aggregate coverage/coverage.data --include views -Ispec spec/controllers/api_base_controller_spec.rb spec/controllers/application_controller_spec.rb spec/controllers/players_controller_spec.rb spec/controllers/routes_spec.rb spec/controllers/sessions_controller_spec.rb spec/helpers/cucumber_helper_spec.rb spec/helpers/form_helper_spec.rb spec/helpers/front_end_helper_spec.rb spec/helpers/players_helper_spec.rb spec/helpers/sessions_helper_spec.rb spec/lib/adjustment_spec.rb spec/lib/project/caching_spec.rb spec/lib/project/locking_spec.rb spec/lib/hash_spec.rb spec/lib/importer_spec.rb spec/lib/interpolator_spec.rb spec/lib/selector/clause_spec.rb spec/lib/selector/complement_spec.rb spec/lib/selector/core_extensions_spec.rb spec/lib/selector/object_id_spec.rb spec/lib/selector/predicate_spec.rb spec/lib/selector/presentation_spec.rb spec/lib/selector_spec.rb spec/lib/simple_cache_spec.rb spec/lib/typecaster_spec.rb spec/lib/walker_spec.rb spec/models/achievement_ladder_spec.rb spec/models/achievement_spec.rb spec/models/activity_definition_spec.rb spec/models/activity_spec.rb spec/models/api_key_spec.rb spec/models/async_reward_spec.rb spec/models/behavior_leaderboard_spec.rb spec/models/component_spec.rb spec/models/content_spec.rb spec/models/destroy_spec.rb spec/models/group_spec.rb spec/models/leaderboard_spec.rb spec/models/leaky_pail_spec.rb spec/models/level_spec.rb spec/models/levels_stat_spec.rb spec/models/mailer_template_spec.rb spec/models/memoization_spec.rb spec/models/meta_condition_spec.rb spec/models/network_spec.rb spec/models/next_reward_spec.rb spec/models/notifier_spec.rb spec/models/player_spec.rb spec/models/players_stat_spec.rb spec/models/reward_definition_spec.rb spec/models/reward_leaderboard_spec.rb spec/models/reward_spec.rb spec/models/simple_behavior_spec.rb spec/models/site_spec.rb spec/models/stats_resource_spec.rb spec/models/style_set_spec.rb spec/models/tx_leaderboard_position_spec.rb spec/models/unit_spec.rb spec/models/user_spec.rb -- --color
/Users/Hao/.rvm/gems/ruby-1.8.7-p174@global/gems/bundler-1.0.18/lib/bundler.rb:207: warning: Insecure world writable dir /Users/Hao/Documents/Projects/project in PATH, mode 040777
/Users/Hao/.rvm/gems/ruby-1.8.7-p174@global/gems/bundler-1.0.18/lib/bundler/runtime.rb:136: warning: Insecure world writable dir /Users/Hao/Documents/Projects/project in PATH, mode 040777
/Users/Hao/.rvm/gems/ruby-1.8.7-p174@global/gems/bundler-1.0.18/lib/bundler.rb:207: warning: Insecure world writable dir /Users/Hao/Documents/Projects/project in PATH, mode 040777
/Users/Hao/.rvm/gems/ruby-1.8.7-p174@global/gems/bundler-1.0.18/lib/bundler/runtime.rb:136: warning: Insecure world writable dir /Users/Hao/Documents/Projects/project in PATH, mode 040777
./spec/controllers/api_base_controller_spec.rb:1: uninitialized constant Api (NameError)
    from /Users/Hao/.rvm/gems/ruby-1.8.7-p174@project.project.master/gems/rcov-0.9.10/bin/rcov:516:in `load'
    from /Users/Hao/.rvm/gems/ruby-1.8.7-p174@project.project.master/gems/rcov-0.9.10/bin/rcov:516
    from /Users/Hao/.rvm/gems/ruby-1.8.7-p174@project.project.master/bin/rcov:19:in `load'
    from /Users/Hao/.rvm/gems/ruby-1.8.7-p174@project.project.master/bin/rcov:19
rake aborted!

The class name is Api::Berlin::BaseController.

Rspec works fine when run standalone. However, with Rcov, it doesn't recognize the Api because class Api is never defined. It's just namespaced by the folder.

Using Rspec 2.6.0, Rake 0.8.7, Ruby 1.8.7-p174, Rails 3.0.5, Rcov 0.9.10

Is this issue not resolved yet?
have same problem occured in my project :(

Not resolved :(

akradev commented Aug 9, 2012

same here

No longer care about this issue.

hahuang65 closed this Mar 10, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment