2016-09-16 86 views
0

我想對通過設計生成的用戶模型進行簡單的有效性測試。我的測試/模型/ user_test.rb文件看起來像這樣測試設計模型與minitest未定義的方法'有效'

require 'test_helper' 

class UserTest < ActiveSupport::TestCase 


def setup 
    @user = User.new(email: "[email protected]", password: "foobar") 
end 

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

end 

我得到的錯誤是:

/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- 

this link他們manege做了非常類似的測試看到。

我完成了從中學習創建一個功能齊全的用戶mvc系統的rails教程,但現在我想嘗試使用devise更快地完成它。

謝謝。

+0

'應該是有效的'需要在引號 – davidhu2000

回答

0

你需要寫:"should be valid" 看看這裏例如link

+0

這是一個非常沉悶的錯誤謝謝! –

0

我喜歡語法如下:

def test_should_be_valid 
    ##Your code 
end 

的方法與 「TEST_」 開始。

相關問題