当我运行rspec spec/models/vote_spec.rb
我收到以下错误:
/Users/louismorin/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activesupport-4.0.5/lib/active_support/dependencies.rb:229:in `require': /Users/louismorin/code/CP299/app/models/vote.rb:5: syntax error, unexpected tINTEGER, expecting '(' (SyntaxError)
...:value, inclusion: { in: [-1. 1], message: "%{value is not a...
... ^
/Users/louismorin/code/CP299/app/models/vote.rb:5: syntax error, unexpected '}', expecting keyword_end
from /Users/louismorin/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activesupport-4.0.5/lib/active_support/dependencies.rb:229:in `block in require'
from /Users/louismorin/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activesupport-4.0.5/lib/active_support/dependencies.rb:214:in `load_dependency'
from /Users/louismorin/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activesupport-4.0.5/lib/active_support/dependencies.rb:229:in `require'
from /Users/louismorin/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activesupport-4.0.5/lib/active_support/dependencies.rb:330:in `require_or_load'
from /Users/louismorin/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activesupport-4.0.5/lib/active_support/dependencies.rb:463:in `load_missing_constant'
from /Users/louismorin/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activesupport-4.0.5/lib/active_support/dependencies.rb:184:in `const_missing'
from /Users/louismorin/code/CP299/spec/models/vote_spec.rb:3:in `<top (required)>'
from /Users/louismorin/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.2/lib/rspec/core/configuration.rb:1105:in `load'
from /Users/louismorin/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.2/lib/rspec/core/configuration.rb:1105:in `block in load_spec_files'
from /Users/louismorin/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.2/lib/rspec/core/configuration.rb:1105:in `each'
from /Users/louismorin/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.2/lib/rspec/core/configuration.rb:1105:in `load_spec_files'
from /Users/louismorin/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.2/lib/rspec/core/runner.rb:96:in `setup'
from /Users/louismorin/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.2/lib/rspec/core/runner.rb:84:in `run'
from /Users/louismorin/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.2/lib/rspec/core/runner.rb:69:in `run'
from /Users/louismorin/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.2/lib/rspec/core/runner.rb:37:in `invoke'
from /Users/louismorin/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rspec-core-3.1.2/exe/rspec:4:in `<top (required)>'
from /Users/louismorin/.rbenv/versions/2.1.2/bin/rspec:23:in `load'
from /Users/louismorin/.rbenv/versions/2.1.2/bin/rspec:23:in `<main>'
这是我的vote.rb文件:
class Vote < ActiveRecord::Base
belongs_to :user
belongs_to :post
validates :value, inclusion: { in: [-1, 1], message: "%{value} is not a valid vote." }
end
答案 0 :(得分:1)
看起来in:
选项in: [-1. 1]
应为in: [-1, 1]
(逗号,不是句点)。
虽然它在给定的vote.rb
文件中看起来正确,但错误输出显示的是句点而不是逗号。