Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc doc changes #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .formatter.exs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Used by "mix format"
[
inputs: ["mix.exs", "{config,lib,test}/**/*.{ex,exs}"]
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]
21 changes: 12 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# The directory Mix will write compiled artifacts to.
/_build
/_build/

# If you run "mix test --cover", coverage assets end up here.
/cover
/cover/

# The directory Mix downloads your dependencies sources to.
/deps
/deps/

# Where 3rd-party dependencies like ExDoc output generated docs.
/doc
# Where third-party dependencies like ExDoc output generated docs.
/doc/

# Ignore .fetch files in case you like to edit your project deps locally.
/.fetch
Expand All @@ -19,8 +19,11 @@ erl_crash.dump
# Also ignore archive artifacts (built via "mix archive.build").
*.ez

# Configuration file from asdf version manager
.tool-versions
# Ignore package tarball (built via "mix hex.build").
mockery-*.tar

# Temporary files for e.g. tests.
/tmp/

# Elixir LS files
.elixir_ls
# Configuration file from asdf version manager.
.tool-versions
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 2.3.1 (2019-10-10)

- Fixed issue preventing module attributes to be used in assert_called macros [#34](https://github.com/appunite/mockery/pull/34)
Expand Down
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

[![Build Status](https://travis-ci.org/appunite/mockery.svg?branch=master)](https://travis-ci.org/appunite/mockery)
[![Codecov.io](https://codecov.io/gh/appunite/mockery/branch/master/graph/badge.svg)](https://codecov.io/gh/appunite/mockery)
[![SourceLevel](https://app.sourcelevel.io/github/appunite/mockery.svg)](https://app.sourcelevel.io/github/appunite/mockery)
[![Hex.pm](https://img.shields.io/hexpm/v/mockery.svg)](https://hex.pm/packages/mockery)
[![Hex.pm](https://img.shields.io/hexpm/dt/mockery.svg)](https://hex.pm/packages/mockery)
[![Hex.pm](https://img.shields.io/hexpm/dw/mockery.svg)](https://hex.pm/packages/mockery)
[![Module Version](https://img.shields.io/hexpm/v/mockery.svg)](https://hex.pm/packages/mockery)
[![Hex Docs](https://img.shields.io/badge/hex-docs-lightgreen.svg)](https://hexdocs.pm/mockery/)
[![Total Download](https://img.shields.io/hexpm/dt/mockery.svg)](https://hex.pm/packages/mockery)
[![License](https://img.shields.io/hexpm/l/mockery.svg)](https://github.com/appunite/mockery/blob/master/LICENSE)
[![Last Updated](https://img.shields.io/github/last-commit/appunite/mockery.svg)](https://github.com/appunite/mockery/commits/master)


Simple mocking library for asynchronous testing in Elixir.

Expand Down Expand Up @@ -201,7 +203,8 @@ end

### Refute

Every assert_called/x function/macro has its refute_called/x counterpart.</br>
Every `assert_called/x` function/macro has its `refute_called/x` counterpart.

For more information see [docs](https://hexdocs.pm/mockery/Mockery.Assertions.html)

### History
Expand Down Expand Up @@ -270,9 +273,9 @@ For advanced usage examples see [EXAMPLES.md](EXAMPLES.md)

* <https://stephenbussey.com/2018/02/15/my-favorite-elixir-testing-tool-mockery>

## License
## Copyright and License

Copyright 2017-2019 Tobiasz Małecki <[email protected]>
Copyright 2017 Tobiasz Małecki <[email protected]>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
17 changes: 10 additions & 7 deletions lib/mockery.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule Mockery do
@moduledoc """
Core functionality
Core functionality.
"""
alias Mockery.Utils

Expand All @@ -15,12 +15,12 @@ defmodule Mockery do
@typep global_mock :: module | nil

@typedoc """
Mockery uses tuple calls to send additional data to internal proxy module
Mockery uses tuple calls to send additional data to internal proxy module.
"""
@opaque proxy_tuple :: {Mockery.Proxy, module, global_mock}

@typedoc """
Used to avoid unnecessary compile-time dependencies between modules
Used to avoid unnecessary compile-time dependencies between modules.

## Examples

Expand All @@ -32,18 +32,21 @@ defmodule Mockery do
@bar2 Mockery.of("Bar")
end

`mix xref graph` can be used to check difference between module and string versions
`mix xref graph` can be used to check difference between module and string versions.
"""
@type elixir_module_as_string :: String.t()

@doc """
Function used to prepare module for mocking.

For Mix.env other than :test it returns module given in the first argument.

If Mix.env equal :test it creates a proxy to the original module.
When Mix is missing it assumes that env is :prod

When Mix is missing it assumes that env is `:prod`.

## Examples

#### Prepare for mocking (elixir module)

defmodule Foo do
Expand Down Expand Up @@ -162,13 +165,13 @@ defmodule Mockery do

will raise an error.

It is also possible to mock function with given name and any arity
It is also possible to mock function with given name and any arity:

mock Mod, :fun, "mocked value"

but this version doesn't support function as value.

Also, multiple mocks for same module are chainable
Also, multiple mocks for same module are chainable:

Mod
|> mock(:fun1, "value")
Expand Down
28 changes: 14 additions & 14 deletions lib/mockery/assertions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ defmodule Mockery.Assertions do

## Examples

Assert Mod.fun/2 was called
Assert Mod.fun/2 was called:

assert_called Mod, fun: 2

Assert any function named :fun from module Mod was called
Assert any function named :fun from module Mod was called:

assert_called Mod, :fun

Expand All @@ -47,11 +47,11 @@ defmodule Mockery.Assertions do

## Examples

Assert Mod.fun/2 wasn't called
Assert Mod.fun/2 wasn't called:

refute_called Mod, fun: 2

Assert any function named :fun from module Mod wasn't called
Assert any function named :fun from module Mod wasn't called:

refute_called Mod, :fun

Expand All @@ -76,11 +76,11 @@ defmodule Mockery.Assertions do

## Examples

Assert Mod.fun/2 was called with given args list
Assert Mod.fun/2 was called with given args list:

assert_called Mod, :fun, ["a", "b"]

You can also use unbound variables inside args pattern
You can also use unbound variables inside args pattern:

assert_called Mod, :fun, ["a", _second]

Expand All @@ -104,11 +104,11 @@ defmodule Mockery.Assertions do

## Examples

Assert Mod.fun/2 wasn't called with given args list
Assert Mod.fun/2 wasn't called with given args list:

refute_called Mod, :fun, ["a", "b"]

You can also use unbound variables inside args pattern
You can also use unbound variables inside args pattern:

refute_called Mod, :fun, ["a", _second]

Expand All @@ -135,15 +135,15 @@ defmodule Mockery.Assertions do

## Examples

Assert Mod.fun/2 was called with given args 5 times
Assert Mod.fun/2 was called with given args 5 times:

assert_called Mod, :fun, ["a", "b"], 5

Assert Mod.fun/2 was called with given args from 3 to 5 times
Assert Mod.fun/2 was called with given args from 3 to 5 times:

assert_called Mod, :fun, ["a", "b"], 3..5

Assert Mod.fun/2 was called with given args 3 or 5 times
Assert Mod.fun/2 was called with given args 3 or 5 times:

assert_called Mod, :fun, ["a", "b"], [3, 5]

Expand All @@ -170,15 +170,15 @@ defmodule Mockery.Assertions do

## Examples

Assert Mod.fun/2 was not called with given args 5 times
Assert Mod.fun/2 was not called with given args 5 times:

refute_called Mod, :fun, ["a", "b"], 5

Assert Mod.fun/2 was not called with given args from 3 to 5 times
Assert Mod.fun/2 was not called with given args from 3 to 5 times:

refute_called Mod, :fun, ["a", "b"], 3..5

Assert Mod.fun/2 was not called with given args 3 or 5 times
Assert Mod.fun/2 was not called with given args 3 or 5 times:

refute_called Mod, :fun, ["a", "b"], [3, 5]

Expand Down
15 changes: 10 additions & 5 deletions lib/mockery/history.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ defmodule Mockery.History do
Provides calls history for Mockery.Assertions macros.

It's disabled by default.
It can be enabled/disabled globally by following config

It can be enabled/disabled globally by following config:

config :mockery, history: true

Or for single test process
Or for single test process:

Mockery.History.enable_history()
Mockery.History.disable_history()

Process config has higher priority than global config
Process config has higher priority than global config.
"""
import IO.ANSI
alias Mockery.Utils
Expand All @@ -27,7 +28,9 @@ defmodule Mockery.History do
end

@doc """
Enables history in scope of single test process
Enables history in scope of single test process.

## Examples

use Mockery

Expand All @@ -47,7 +50,9 @@ defmodule Mockery.History do
end

@doc """
Disables history in scope of single test process
Disables history in scope of single test process.

## Examples

use Mockery

Expand Down
7 changes: 5 additions & 2 deletions lib/mockery/macro.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ defmodule Mockery.Macro do
When Mix is missing it assumes that env is :prod.

## Examples

#### Prepare for mocking

defmodule Foo do
Expand Down Expand Up @@ -40,13 +41,15 @@ defmodule Mockery.Macro do
## Mockery.of/2 comparison

* It's based on macro and process dictionary instead of on tuple calls. (Tuple calls
are disabled by default in OTP21+ and require additional compile flag to be reenabled)
are disabled by default in OTP21+ and require additional compile flag to be reenabled)

* It doesn't support passing module names as a string as it don't create unwanted compile-time
dependencies between modules
dependencies between modules

## Potential issues

Output of `mockable/2` macro should not be bind to variable or module attribute.

If it happens, you'll see a compilation warning at best, and in the worst case Mockery won't
work correctly.

Expand Down
Loading