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.rbの行を調べて、このチュートリアルに従って適切なコンテキストで使用され21ていることを確認してください: http://guides.rubyonrails.org/active_record_validations_callbacks.html#uniquenessuniqueness

他の回答で @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 に答える