Reputation: 171
I have a before_validation callback in my model. I am unable to find how to write test cases for callbacks in minitest rails.
test 'callback set_slug before_validation' do
company = Company.new(name: 'test')
mock_method = MiniTest::Mock.new
mock_method.expect :set_slug, 'clickapps1'
company.stub :set_slug, 'clickapps1' do
company.valid?
end
mock_method.verify
end
Upvotes: 0
Views: 1835
Reputation: 171
I used the mocha gem and then my test case looks like:
test 'callback set_slug before_validation' do
company = Company.new(name: 'test')
company.expects(:set_slug)
company.valid?
end
and now it works.
Upvotes: 6