enmanuel martinez enmanuel martinez - 2 months ago 30
Ruby Question

testing devise model with minitest undefined method 'valid'

I'm trying to make a simple validity test to a user model generated through devise. my test/models/user_test.rb file looks like this

require 'test_helper'

class UserTest < ActiveSupport::TestCase


def setup
@user = User.new(email: "admin@example.com", password: "foobar" )
end

test should be valid do
assert @user.valid?
end

end


the error i'm getting is:

/home/ubuntu/workspace/test/models/user_test.rb:10:in `<class:UserTest>': undefined local variable or method `valid' for UserTest:Class (NameError)
from /home/ubuntu/workspace/test/models/user_test.rb:3:in `<top (required)>'
from /usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require'
from /usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-


I saw in this link that they manege to do a very similar test.

i completed the rails tutorial from which i learned to create a fully functional user mvc system but now i want to try to do it faster with devise.

thanks.

Answer

You need to write: "should be valid" Look here for example link