# Stub a method in a class with Minitest

Used: minitest@5.0.0

If you have a method in a Ruby class that you want to stub for testing, you can use Minitest `stub` method like:

```rb
MyClass.stub(:method, "value") do
  # Here the method is stubbed
end
```

But if the method is a private method, that will not work, in that case you have to change it with a more longer version:

```rb
MyClass
  .any_instance
  .stubs(:method)
  .returns("value") do
  # Here the method is stubbed
end
```

This works because Minitest will now stub any instance of the class and since it works at the instance level it will be able to stub private methods too.