rspec - 为什么 be_valid 不起作用
我正在尝试执行此操作:
describe "should fail on create if the name is shorter than 5 characters" do
group = Factory.build(:group, :name => "a")
group.should be_invalid
group.should have(1).error_on(:name)
end
但出现以下错误:
/spec/models/group_model_spec.rb:22: undefined local variable or method `be_valid' for #<Class:0x105d13ed0> (NameError)
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example_group.rb:132:in `module_eval'
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example_group.rb:132:in `subclass'
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example_group.rb:119:in `describe'
from /xxxx/spec/models/group_model_spec.rb:15
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example_group.rb:132:in `module_eval'
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example_group.rb:132:in `subclass'
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example_group.rb:119:in `describe'
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/extensions/object.rb:6:in `describe'
from /Users/bhellman/Sites/companyline/spec/models/group_model_spec.rb:3
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `load'
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `load_spec_files'
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `map'
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `load_spec_files'
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/command_line.rb:18:in `run'
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:55:in `run_in_process'
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:46:in `run'
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:10:in `autorun'
from /usr/bin/rspec:19
有想法吗?谢谢
I'm trying to do this:
describe "should fail on create if the name is shorter than 5 characters" do
group = Factory.build(:group, :name => "a")
group.should be_invalid
group.should have(1).error_on(:name)
end
But I get the following error:
/spec/models/group_model_spec.rb:22: undefined local variable or method `be_valid' for #<Class:0x105d13ed0> (NameError)
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example_group.rb:132:in `module_eval'
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example_group.rb:132:in `subclass'
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example_group.rb:119:in `describe'
from /xxxx/spec/models/group_model_spec.rb:15
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example_group.rb:132:in `module_eval'
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example_group.rb:132:in `subclass'
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/example_group.rb:119:in `describe'
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/extensions/object.rb:6:in `describe'
from /Users/bhellman/Sites/companyline/spec/models/group_model_spec.rb:3
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `load'
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `load_spec_files'
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `map'
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/configuration.rb:386:in `load_spec_files'
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/command_line.rb:18:in `run'
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:55:in `run_in_process'
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:46:in `run'
from /Library/Ruby/Gems/1.8/gems/rspec-core-2.5.1/lib/rspec/core/runner.rb:10:in `autorun'
from /usr/bin/rspec:19
Ideas? Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是正确的语法:
This is the correct syntax :