2011-01-11 86 views
1

我正在使用rails 3 w/rspec-rails 2.4.1并且在模型生成过程中出现错误。从Google搜索找不到任何内容。任何人都知道可能会发生什么?rspec未定义的局部变量或方法`class_nesting_depth`

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>' 

编辑:这里是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? 
      template 'fixtures.yml', File.join('spec/fixtures', "#{table_name}.yml") 
     end 
     end 
    end 
    end 
end 
+0

应用程序中的lib/generators/rspec/model/model_generator.rb文件在做什么?它显示在堆栈轨迹试图看起来不显眼。这是失败的。 – 2011-01-11 05:10:46

回答

1

我的罪魁祸首,当我从 https://github.com/pjb3/rails3-generators.git克隆保罗·巴里的HAML发电机到我的应用程序li​​b文件夹。这对我所有生成rspec测试的发生器都产生了同样的错误。我立即将其删除,并在此后正常工作。

相关问题