错误单元测试:未定义的assert_not

时间:2014-10-29 10:30:52

标签: ruby-on-rails ruby

我运行rake test时出现两个错误:

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?仍在工作?

1 个答案:

答案 0 :(得分:0)

rails 4.0.2中添加了

assert_not。你需要这样做:

assert !@relation.valid?