运行该命令后收到此错误消息
耙子测试:单位
undefined method `assert' for ProductTest:Class (NoMethodError) from /home/mayank/src/proj/vendor/bundle/ruby/1.8/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in `require' from /home/mayank/src/proj/vendor/bundle/ruby/1.8/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in `require' from /home/mayank/src/proj/vendor/bundle/ruby/1.8/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:236:in `load_dependency' from /home/mayank/src/proj/vendor/bundle/ruby/1.8/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in `require' from /home/mayank/src/proj/vendor/bundle/ruby/1.8/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:10 from /home/mayank/src/proj/vendor/bundle/ruby/1.8/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:9:in `each' from /home/mayank/src/proj/vendor/bundle/ruby/1.8/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:9 from /home/mayank/src/proj/vendor/bundle/ruby/1.8/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:4:in `select' from /home/mayank/src/proj/vendor/bundle/ruby/1.8/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:4 rake aborted!
require 'test_helper' class ProductTest < ActiveSupport::TestCase product = Product.new assert product.invalid? assert product.errors[:title].any? assert product.errors[:description].any? assert product.errors[:price].any? assert product.errors[:image_url].any? # test "the truth" do # assert true # end end
解决方法
应该:
class ProductTest < ActiveSupport::TestCase test "product attributes must not be empty" do product = Product.new assert product.invalid? assert product.errors[:title].any? assert product.errors[:description].any? assert product.errors[:image_url].any? assert product.errors[:price].any? end end
就像书中的Agile Web Development with Rails一样.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。