How to assert certain method is called with Ruby minitest framework?

Posted by steven.yang on Stack Overflow See other posts from Stack Overflow or by steven.yang
Published on 2012-06-03T10:06:57Z Indexed on 2012/06/03 10:40 UTC
Read the original article Hit count: 280

Filed under:
|
|
|

I want to test whether a function invokes other functions properly with minitest Ruby, but I cannot find a proper assert to test from the doc.

The source code
class SomeClass
  def invoke_function(name)
    name == "right" ? right () : wrong ()
  end

  def right
    #...
  end

  def wrong
    #...
  end
end
The test code:
describe SomeClass do
  it "should invoke right function" do
    # assert right() is called
  end

  it "should invoke other function" do
    # assert wrong() is called
  end
end

© Stack Overflow or respective owner

Related posts about ruby

Related posts about unit-testing