Hammox Versions Save

🏝 automated contract testing via type checking for Elixir functions and mocks

v0.7.0

1 year ago

New features

[#120]

Hammox now includes telemetry events! See Telemetry Guide for more information.

Big thanks to @SophisticaSean for carrying this start to finish!

v0.6.1

1 year ago

Performance improvements

[#103]

Hammox now uses :persistent_term instead of a GenServer for caching typespecs, resulting in a ~5x speedup. Thanks @SophisticaSean for making and benchmarking the changes and @Adzz for suggesting :persistent_term!

v0.6.0

1 year ago

New features

Multiple behaviour support in Hammox.Protect and Hammox.protect/2 [#93]

use Hammox.Protect now accepts multiple :behaviour options:

use Hammox.Protect, module: My.Module, behaviour: My.Module.Contract, behaviour: My.Module.OtherContract

Which is functionally equivalent to:

use Hammox.Protect, module: My.Module, behaviour: My.Module.Contract
use Hammox.Protect, module: My.Module, behaviour: My.Module.OtherContract

Likewise, Hammox.protect/2 now additionally supports a list of behaviours as second argument:

Hammox.protect(My.Module, [My.Module.Contract, My.Module.OtherContract]),

Big thanks to @camilleryr for submitting these changes.

Bug fixes

  • Complex multiline typespecs no longer cause a CaseClauseError with recent versions of Elixir when Hammox tries to print them [#113]
  • The bool() type is now correctly supported and no longer causes an exception [#115]
  • Type guards are now correctly supported and no longer cause an exception [#116]
  • Fixes incorrect usage of Code.ensure_compiled/1 [#111] (thanks to @Adzz)

Other

  • Tweaks to documentation [#84][#87] (thanks to @kianmeng and @wojtekmach)

v0.5.0

3 years ago

Raising when Hammox.Protect is used on a module without callbacks

[#75]

Using Hammox.Protect on a module without callbacks is essentially a no-op. This is most likely due to a mistake, and we now raise in this scenario.

v0.4.0

3 years ago

Hammox.Protect

[#71]

You can now do use Hammox.Protect instead of calling Hammox.protect/3 directly as a less verbose way of creating protected functions in tests. See the Hammox.Protect API docs for more details and the README for an example.

Dependency upgrades

  • :ordinal 0.1.0 -> 0.2.0 [#68]

v0.3.1

3 years ago

Bug fixes

  • fixes crash when using maps explicitly specifying a __struct__ key [#64]

Acknlowledgements

Thanks to @randycoulman for the fix!

v0.3.0

3 years ago

The biggest release yet!

Huge speed improvements

[#53]

Hammox v0.2 and below was completely stateless. Any time a Hammox-protected function was called, types needed to be read from disk and parsed from the compiled binary files. This created a huge bottleneck which given complex typespecs with many types slowed down Hammox-heavy test suites considerably.

Hammox v0.3 includes a typespec cache server and keeps all types in memory once first read from disk. Now the performance impact is practically indistinguishable from Mox.

Interface simplifications and shortcuts

Decorate all functions designated by a behaviour by default

[#54] [#55]

When using the "batch" version of protect where you pass an implementation module, a behaviour module, and a list of functions, the list of functions is now optional. Hammox will decorate all functions from the behaviour by default.

Example:

defmodule Calculator do
  @callback add(integer(), integer()) :: integer()
end

defmodule TestCalculator do
  def add(a, b), do: a + b
end

# Hammox v0.2
Hammox.protect(TestCalculator, Calculator, add: 2)

# Hammox v0.3
Hammox.protect(TestCalculator, Calculator)

Shortcuts for behaviour-implementation modules

[#51] [#62]

When using modules which contain both callbacks and implementations, you now only need to pass the module to protect once.

Example:

defmodule Calculator do
  @callback add(integer(), integer()) :: integer()
  def add(a, b), do: a + b
end

# Hammox v0.2
Hammox.protect(Calculator, Calculator, add: 2)

# Hammox v0.3
Hammox.protect(Calculator, add: 2)

Better exceptions for protect edge cases

[#52]

Before, passing nonexistent module to protect resulted in an ugly internal exception. Now, we raise a better exception explaning what happened.

Type checking for stubs

[#58]

Before, calls to stubs created by Hammox were not being type checked. This was an oversight. In Hammox v0.3, calls to stubs created by Hammox using Hammox.stub/3 are type checked.

Mox update

[#50]

Hammox v0.3 now includes Mox 1.0.0.

Acknlowledgements

Thanks to @saneery, @randycoulman, @jotaviobiondo and @SophisticaSean for helping make this release happen!

v0.2.5

3 years ago

Bug fixes

  • adds support for all of @type, @typep, @opaque [#41, #42]

Acknowledments

Thanks to @gabrielpra1 for spotting this!

v0.2.4

4 years ago

Fixes

  • fixes error when using parametrized type definitions spanning multiple lines [#29]

v0.2.3

4 years ago

Dependency upgrades

  • :mox 0.5.1 -> 0.5.2