我正试图让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'
答案 0 :(得分: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哈希语法的代码。或者它可能是别的东西。你能发布该文件中的其他行吗?
答案 1 :(得分:1)
查看源文件/Users/stacyrandel/rails_projects/callred/app/models/user.rb
行21
,确保根据本教程在正确的上下文中使用uniqueness
:http://guides.rubyonrails.org/active_record_validations_callbacks.html#uniqueness
正如@dpassage在另一个答案中所指出的,ruby版本之间存在差异:
Ruby 1.8.7:
validates :email, :uniqueness => true
Ruby 1.9 +:
validates :email, uniqueness: true
但你的堆栈跟踪显示使用了ruby 1.9.3,所以应该没问题。