ruby on rails - Rails4 Minitest | using a shared reusable object -


i getting following error when run rake test minitest:

$ rake test dl deprecated, please use fiddle run options: --seed 55196  # running:  .ee  finished in 0.950979s, 3.1546 runs/s, 1.0515 assertions/s.    1) error: categorytest#test_invalid_without_name: nomethoderror: undefined method `name=' nil:nilclass     test/models/category_test.rb:14:in `test_invalid_without_name'     2) error: categorytest#test_invalid_without_long_name: nomethoderror: undefined method `name=' nil:nilclass     test/models/category_test.rb:19:in `test_invalid_without_long_name'  3 runs, 1 assertions, 0 failures, 2 errors, 0 skips 

category_test.rb

require "test_helper"  class categorytest < activesupport::testcase    def category     @category = category.new(name:'homey')   end    def test_valid     assert category.valid?   end    def test_invalid_without_name     @category.name = nil     refute @category.valid?   end    def test_invalid_without_long_name     @category.name = "a"     refute @category.valid?   end  end 

in models have category.rb

class category < activerecord::base     validates :name, presence: true end 

it seems have nil class though instantiating in category method. idea happening. getting started using minitest not sure going on.

do

def category   @category ||= category.new(name:'homey') end 

then use category not @category

using getter way set instance var if didnt exist before or retrieve existing value


Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -