Project

mock_java

0.0
No commit activity in last 3 years
No release in over 3 years
mock_java a lib that help to mock java classes in ruby world!
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 1.9
~> 10.0
~> 3.2
 Project Readme

MockJava - Mocking java classes in Ruby World!

Essential Information

Mock java is not a real mock, but a lib that creates a ruby class that extends java classes.

Since it creates a ruby class, you can use rspec to change the behaviour class since it's a real Ruby class!

I created this since I don't like the idea of using rspec using tools from java classes to mock like Mockito! So if you have the same will, this might be your tool!

Usage

First include the module in your spec_helper file:

RSpec.configure do |config|
  config.include MockJava
end

after importing your java file with:

java_import com.package.ExampleJavaClass

To mock this example class you mock with this command:

mock = mock_java ExampleJavaClass

If you need you need to pass arguments to your constructors use this:

mock = mock_java ExampleJavaClass, 'param1', 'param2'

If you already have an object you can mock with this:

example = ExampleJavaClass.new
mock = mock_java example

Contributting to MockJava

  • For, fix, then send me a pull request.