0

我正试图让 rspec 重新开始工作。当我去测试任何东西时,我得到以下信息:

stacyrandel$ bundle exec rspec spec/requests/static_pages_spec.rb
/Users/stacyrandel/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `require': /Users/stacyrandel/rails_projects/callred/app/models/user.rb:21: syntax error, unexpected ':', expecting keyword_end (SyntaxError)
    uniqueness: { case_sensitive: false }
               ^
    from /Users/stacyrandel/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `block in require'
    from /Users/stacyrandel/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:236:in `load_dependency'
    from /Users/stacyrandel/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `require'
    from /Users/stacyrandel/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:359:in `require_or_load'
    from /Users/stacyrandel/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:502:in `load_missing_constant'
    from /Users/stacyrandel/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:192:in `block in const_missing'
    from /Users/stacyrandel/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:190:in `each'
    from /Users/stacyrandel/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:190:in `const_missing'
    from /Users/stacyrandel/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.8/lib/active_support/inflector/methods.rb:230:in `block in constantize'
    from /Users/stacyrandel/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.8/lib/active_support/inflector/methods.rb:229:in `each'
    from /Users/stacyrandel/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.8/lib/active_support/inflector/methods.rb:229:in `constantize'
    from /Users/stacyrandel/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.8/lib/active_support/inflector/methods.rb:260:in `safe_constantize'
    from /Users/stacyrandel/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.8/lib/active_support/core_ext/string/inflections.rb:66:in `safe_constantize'
    from /Users/stacyrandel/.rvm/gems/ruby-1.9.3-p327/gems/actionpack-3.2.8/lib/action_controller/metal/params_wrapper.rb:152:in `_default_wrap_model'
    from /Users/stacyrandel/.rvm/gems/ruby-1.9.3-p327/gems/actionpack-3.2.8/lib/action_controller/metal/params_wrapper.rb:169:in `_set_wrapper_defaults'
    from /Users/stacyrandel/.rvm/gems/ruby-1.9.3-p327/gems/actionpack-3.2.8/lib/action_controller/metal/params_wrapper.rb:133:in `inherited'
    from /Users/stacyrandel/.rvm/gems/ruby-1.9.3-p327/gems/actionpack-3.2.8/lib/abstract_controller/railties/routes_helpers.rb:7:in `block (2 levels) in with'
    from /Users/stacyrandel/.rvm/gems/ruby-1.9.3-p327/gems/actionpack-3.2.8/lib/action_controller/railties/paths.rb:7:in `block (2 levels) in with'
    from /Users/stacyrandel/rails_projects/callred/app/controllers/users_controller.rb:1:in `<top (required)>'
    from /Users/stacyrandel/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `require'
    from /Users/stacyrandel/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `block in require'
    from /Users/stacyrandel/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:236:in `load_dependency'
    from /Users/stacyrandel/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `require'
    from /Users/stacyrandel/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:359:in `require_or_load'
    from /Users/stacyrandel/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:313:in `depend_on'
    from /Users/stacyrandel/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:225:in `require_dependency'
    from /Users/stacyrandel/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.8/lib/rails/engine.rb:439:in `block (2 levels) in eager_load!'
    from /Users/stacyrandel/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.8/lib/rails/engine.rb:438:in `each'
    from /Users/stacyrandel/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.8/lib/rails/engine.rb:438:in `block in eager_load!'
    from /Users/stacyrandel/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.8/lib/rails/engine.rb:436:in `each'
    from /Users/stacyrandel/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.8/lib/rails/engine.rb:436:in `eager_load!'
    from /Users/stacyrandel/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.8/lib/rails/application/finisher.rb:53:in `block in <module:Finisher>'
    from /Users/stacyrandel/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.8/lib/rails/initializable.rb:30:in `instance_exec'
    from /Users/stacyrandel/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.8/lib/rails/initializable.rb:30:in `run'
    from /Users/stacyrandel/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.8/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /Users/stacyrandel/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.8/lib/rails/initializable.rb:54:in `each'
    from /Users/stacyrandel/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.8/lib/rails/initializable.rb:54:in `run_initializers'
    from /Users/stacyrandel/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.8/lib/rails/application.rb:136:in `initialize!'
    from /Users/stacyrandel/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.8/lib/rails/railtie/configurable.rb:30:in `method_missing'
    from /Users/stacyrandel/rails_projects/callred/config/environment.rb:5:in `<top (required)>'
    from /Users/stacyrandel/rails_projects/callred/spec/spec_helper.rb:3:in `require'
    from /Users/stacyrandel/rails_projects/callred/spec/spec_helper.rb:3:in `<top (required)>'
    from /Users/stacyrandel/rails_projects/callred/spec/requests/static_pages_spec.rb:1:in `require'
    from /Users/stacyrandel/rails_projects/callred/spec/requests/static_pages_spec.rb:1:in `<top (required)>'
    from /Users/stacyrandel/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `load'
    from /Users/stacyrandel/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `block in load_spec_files'
    from /Users/stacyrandel/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `map'
    from /Users/stacyrandel/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `load_spec_files'
    from /Users/stacyrandel/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.8.0/lib/rspec/core/command_line.rb:22:in `run'
    from /Users/stacyrandel/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:80:in `run_in_process'
    from /Users/stacyrandel/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:69:in `run'
    from /Users/stacyrandel/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:10:in `block in autorun'
4

2 回答 2

1

我认为堆栈跟踪中的重要行是这一行:

/Users/stacyrandel/rails_projects/callred/app/models/user.rb:21: syntax error, unexpected ':', expecting keyword_end (SyntaxError)
    uniqueness: { case_sensitive: false }

这表示您的代码中存在语法错误。这可能是因为出于某种原因,您使用 Ruby 1.8.x 来运行使用 1.9.3 哈希语法的代码。或者它可能是别的东西。您可以从该文件中发布其他行吗?

于 2012-11-24T06:30:44.140 回答
1

查看您的源文件/Users/stacyrandel/rails_projects/callred/app/models/user.rb21,确保uniqueness根据本教程在适当的上下文中使用它:http: //guides.rubyonrails.org/active_record_validations_callbacks.html#uniqueness

正如@dpassage 在另一个答案中指出的那样,ruby 版本之间存在差异:

  1. 红宝石 1.8.7:

    validates :email, :uniqueness => true
    
  2. 红宝石 1.9+:

    validates :email, uniqueness: true
    

但是您的堆栈跟踪显示使用了 ruby​​ 1.9.3,所以应该没问题。

于 2012-11-24T12:28:52.140 回答