Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/drewolson/ex_spec
BDD-like syntax for ExUnit
https://github.com/drewolson/ex_spec
elixir exunit hex
Last synced: about 1 month ago
JSON representation
BDD-like syntax for ExUnit
- Host: GitHub
- URL: https://github.com/drewolson/ex_spec
- Owner: drewolson
- License: mit
- Created: 2014-07-26T17:19:15.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2018-06-06T13:36:56.000Z (over 6 years ago)
- Last Synced: 2024-11-01T09:34:18.105Z (about 1 month ago)
- Topics: elixir, exunit, hex
- Language: Elixir
- Homepage:
- Size: 28.3 KB
- Stars: 99
- Watchers: 4
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- freaking_awesome_elixir - Elixir - BDD-like syntax for ExUnit. (Testing)
- fucking-awesome-elixir - ex_spec - BDD-like syntax for ExUnit. (Testing)
- awesome-elixir - ex_spec - BDD-like syntax for ExUnit. (Testing)
README
## ExSpec
[![Build Status](https://travis-ci.org/drewolson/ex_spec.svg)](https://travis-ci.org/drewolson/ex_spec) [![Hex Version](http://img.shields.io/hexpm/v/ex_spec.svg?style=flat)](https://hex.pm/packages/ex_spec) [![Hex docs](http://img.shields.io/badge/hex.pm-docs-green.svg?style=flat)](https://hexdocs.pm/ex_spec)
ExSpec is a simple wrapper around ExUnit that adds Rspec-style macros. Specifically, it adds `context` and `it`.
While it takes inspiration from Rspec, ExSpec is significantly simplier. The `context` macro has only two functions:
1. Aid test organization
2. Prepend to the message of any `it` defined within its do blocksThe `it` macro is identical to `ExUnit.Case.test` except that it is aware of the messages of its surrounding `context` blocks. It also works seemlessly with `ExUnit`'s `describe` function.
Other than the functionality described above, ExSpec is just ExUnit. When `use`ing `ExSpec`, any options provided will be passed to `ExUnit.Case` (e.g. `async: true`).
A simple example is shown below. For more examples, see the tests.
### Example
```elixir
defmodule PersonTest do
use ExSpec, async: truedescribe "name" do
context "with first and last name" do
it "joins the names with a space" do
drew = %Person{first_name: "Drew", last_name: "Olson"}assert Person.name(drew) == "Drew Olson"
end
endcontext "with only a first name" do
it "returns the first name" do
drew = %Person{first_name: "Drew", last_name: nil}assert Person.name(drew) == "Drew"
end
end
end
end
```### Installation
Add `ex_spec` to your `mix.exs` dependencies:
```elixir
def deps do
[{:ex_spec, "~> 2.0", only: :test}]
end
```