开发者

rspec undefined local variable or method `class_nesting_depth`

I'm using rails 3 w/ rspec-rails 2.4.1 and I get an error during model generation. Can't find anything from googling. Anyone know what might be going on?

TIA

$ rails g model CourseRating student_id:integer course_id:integer difficulty:integer usefulness:integer
  invoke  active_record
  create    db/migrate/20110111044035_create_course_ratings.rb
  create    app/models/course_rating.rb
  invoke    rspec
  create      spec/models/course_rating_spec.rb
(erb):1:in `template': undefined local variable or method `class_nesting_depth' for #<Rspec::Generators::ModelGenerator:0x0000010424e460> (NameError)
    from /Users/glurban/.rvm/rubies/ruby-1.9.2-rc2/lib/ruby/1.9.1/erb.rb:753:in `eval'
    from /Users/glurban/.rvm/rubies/ruby-1.9.2-rc2/lib/ruby/1.9.1/erb.rb:753:in `result'
    from /Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/thor-0.14.6/lib/thor/actions/file_manipulation.rb:111:in `block in template'
    from /Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/thor-0.14.6/lib/thor/actions/create_file.rb:54:in `call'
    from /Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/thor-0.14.6/lib/thor/actions/create_file.rb:54:in `render'
    from /Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/thor-0.14.6/lib/thor/actions/create_file.rb:63:in `block (2 levels) in invoke!'
    from /Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/thor-0.14.6/lib/thor/actions/create_file.rb:63:in `open'
    from /Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/thor-0.14.6/lib/thor/actions/create_file.rb:63:in `block in invoke!'
    from /Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/thor-0.14.6/lib/thor/actions/empty_directory.rb:114:in `call'
    from /Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/thor-0.14.6/lib/thor/actions/empty_directory.rb:114:in `invoke_with_conflict_check'
    from /Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/thor-0.14.6/lib/thor/actions/create_file.rb:61:in `invoke!'
    from /Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/thor-0.14.6/lib/thor/actions.rb:95:in `action'
    from /Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/thor-0.14.6/lib/thor/actions/create_file.rb:26:in `create_file'
    from /Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/thor-0.14.6/lib/thor/actions/file_manipulation.rb:110:in `template'
    from /Users/glurban/code/recruitd/lib/generators/rspec/model/model_generator.rb:10:in `create_test_file'
    from /Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/thor-0.14.6/lib/thor/task.rb:22:in `run'
    from /Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/thor-0.14.6/lib/thor/invocation.rb:118:in `invoke_task'
    from /Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/thor-0.14.6/lib/thor/invocation.rb:124:in `block in invoke_all'
    from /Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/thor-0.14.6/lib/thor/invocation.rb:124:in `each'
    from /Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/thor-0.14.6/lib/thor/invocation.rb:124:in `map'
    from /Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/thor-0.14.6/lib/thor/invocation.rb:124:in `invoke_all'
    from /Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/thor-0.14.6/lib/thor/group.rb:226:in `dispatch'
    from /Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/thor-0.14.6/lib/thor/invocation.rb:109:in `invoke'
    from /Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/thor-0.14.6/lib/thor/group.rb:269:in `block in _invoke_for_class_method'
    from /Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/thor-0.14.6/lib/thor/shell.rb:74:in `with_padding'
    from /Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/thor-0.14.6/lib/thor/group.rb:258:in `_invoke_for_class_method'
    from /Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/thor-0.14.6/lib/thor/group.rb:150:in `_invoke_from_option_test_framework'
    from /Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/thor-0.14.6/lib/thor/task.rb:22:in `run'
    from /Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/thor-0.14.6/lib/thor/invocation.rb:118:in `invoke_task'
    from /Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/thor-0.14.6/lib/thor/invocation.rb:124:in `block in invoke_all'
    from /Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/thor-0.14.6/lib/thor/invocation.rb:124:in `each'
    from /Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/thor-0.14.6/lib/thor/invocation.rb:124:in `map'
    from /Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/thor-0.14.6/lib/thor/invocation.rb:124:in `invoke_all'
    from /Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/thor-0.14.6/lib/thor/group.rb:226:in `dispatch'
    from /Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/thor-0.14.6/lib/thor/invocation.rb:109:in `invoke'
    from /Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/thor-0.14.6/lib/thor/group.rb:269:in `block in _invoke_for_class_method'
    from /Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/thor-0.14.6/lib/thor/shell.rb:74:in `with_padding'
    from /Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/thor-0.14.6/lib/thor/group.rb:258:in `_invoke_for_class_method'
    from /Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/thor-0.14.6/lib/thor/group.rb:150:in `_invoke_from_option_orm'
    from /Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/thor-0.14.6/lib/thor/task.rb:22:in `run'
    from /Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/thor-0.14.6/lib/thor/invocation.rb:118:in `invoke_task'
    from /Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/thor-0.14.6/lib/thor/invocation.rb:124:in `block in invoke_all'
    from /Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/thor-0.14.6/lib/thor/invocation.rb:124:in `each'
    from /Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/thor-0.14.6/lib/thor/invocation.rb:124:in `map'
    from /Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/thor-0.14.6/lib/thor/invocation.rb:124:in `invoke_all'
    from /Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/thor-0.14.6/lib/thor/group.rb:226:in `dispatch'
    from /Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/thor-0.14.6/lib/thor/base.rb:389:in `start'
    from /Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/railties-3.0.0/lib/rails/generators.rb:163:in `invoke'
    from /Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/railties-3.0.0/lib/rails/commands/generate.rb:10:in `<top (required)>'
    from /Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:239:in `require'
    from /Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:239:in `block in require'
    from /Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:225:in `block in load_dependency'
    from /Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:591:in `new_constants_in'
    from /Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:225:in `load_dependency'
    from /Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/activesupport-3.0.0/lib/active_support/dependencies.rb:239:in `require'
    from /Users/glurban/.rvm/gems/ruby-1.9.2-rc2/gems/railties-3.0.0/lib/rails/commands.rb:17:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

Edit: here's lib/generators/rspec/model/model_generator.rb:

require 'generators/rspec'

module Rspec
  module Generators
    class ModelGenerator < Base
      argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
      class_option :fixture, :type => :boolean

      def create_test_file
        template 'model_spec.rb', File.join('spec/models', class_path, "#{file_name}_spec.rb")
      end

      hook_for :fixture_replacement

      def create_fixture_file
        if options[:fixture] && options[:fixture_replacement].nil?
          temp开发者_运维百科late 'fixtures.yml', File.join('spec/fixtures', "#{table_name}.yml")
        end
      end
    end
  end
end


The culprit for me was when I cloned Paul Barry's haml generator into my apps lib folder from https://github.com/pjb3/rails3-generators.git. This produced the same error for me for all my generators producing rspec tests. I promptly remove it and it worked fine after that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜