RSpec用于自定义验证

时间:2016-06-10 06:24:04

标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-4 rspec rspec3

我在rails模型中有自定义验证:

validate :custom_validation_method

def custom_validation_method
  # do stuff here
end

我如何为此制作RSpec?谢谢!

1 个答案:

答案 0 :(得分:1)

测试验证(任何)

describe MyClass do
  it '#custom_validation' do
    expect(subject.valid?).to be_falsey
    #do stuff to subject to make it valid
    expect(subject.valid?).to be_truthy
  end
end