Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undefined method `assert' in ruby on rails

Getting this error message after running the command

rake test:units

 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!

Source code of the application is as below. Its giving error on line assert.

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
like image 607
Mayank Jain Avatar asked Dec 27 '22 01:12

Mayank Jain


1 Answers

Should be:

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

just like in the book Agile Web Development with Rails.

like image 105
Mchl Avatar answered Dec 29 '22 15:12

Mchl