Skip to content

ModuleMocker allows to use different module in development and test environment

License

Notifications You must be signed in to change notification settings

rohanpujaris/module_mocker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ModuleMocker

ModuleMocker helps to mock a module during testing. ModuleMocker does not mock anything for the test, it just provide convention for mocking the module. ModuleMocker should be used to mock modules taht acesses external api or do other heavy lifting work needs to be mocked. You are responsible for defining the mock module and ModuleMocker will just provide easy way to use it and provide convention to define mock module instead of manually configuring it. Check this article on Mocking to have an idea of how ModuleMocker can be used.

SETUP

Add following dependency to mix.exs

    defp deps do
      # Add the dependency
      [{:module_mocker , "~> 0.1.0"}]
    end

Example:

def MyModule.MyAuth
  def func do
    IO.puts "Original function func"
  end
end

def MyModule.Mock.MyAuth
  def func do
    IO.puts "Mock function func"
  end
end

defmodule M do
  import ModuleMocker
  mock_for_test MyModule.MyAuth

  def func do
    # will call MyModule.MyAuth.func in development and production environment
    # will call MyModule.Mock.MyAuth.func in test environment
    @my_auth.func
  end
end

About

ModuleMocker allows to use different module in development and test environment

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages