2014-10-29 45 views
0

我有兩個錯誤,當我運行rake test錯誤單元測試:underfined assert_not

1)Error 
test_should_require_a_following_id(RelationTest) 
NoMethodError:underfined method 'assert_not' for #<RelationTest:0x3dd0058> 
2)Error 
test_should_require_a_follower_id(RelationTest) 
NoMethodError:underfined method 'assert_not' for #<RelationTest:0x3c1d700> 

這是我relation_test.rb

require 'test_helper' 
class RelationTest < ActiveSupport::TestCase 
    def setup 
    @relation = Relation.new(follower_id: 9, following_id: 10) 
    end 

    test "should be valid" do 
    assert @relation.valid? 
    end 

    test "should require a follower_id" do 
    @relation.follower_id = nil 
    assert_not @relation.valid? 
    end 

    test "should require a following_id" do 
    @relation.following_id = nil 
    assert_not @relation.valid? 
    end 
end 

我的關係模型

class Relation < ActiveRecord::Base 
    attr_accessible :following_id, :follower_id 
    belongs_to :follower, :class_name => "User" 
    belongs_to :following, :class_name => "User" 

    validates :follower_id, presence: true 
    validates :following_id, presence: true 
end 

能有什麼我確實解決了這個問題,請幫助我! 我認爲問題是我的鐵桿(3.2.19),但assert @relation.valid?仍然工作?

+0

OMG!我使用版本3.2.19。我如何將assert_not更改爲我的版本,或者我必須更新版本4.0.2 – mayoneQD 2014-10-29 10:36:58

回答

0

assert_not已被添加到rails 4.0.2中。您需要這樣做:

assert [email protected]? 
+0

它的工作!真的很感謝你 :) – mayoneQD 2014-10-30 02:05:49