ProductPromotion
Logo

Elixir

made by https://0x3d.site

GitHub - BlakeWilliams/pact: Better dependency injection in Elixir
Better dependency injection in Elixir. Contribute to BlakeWilliams/pact development by creating an account on GitHub.
Visit Site

GitHub - BlakeWilliams/pact: Better dependency injection in Elixir

GitHub - BlakeWilliams/pact: Better dependency injection in Elixir

Pact

Pact is a dependency registry for Elixir to make testing dependencies easier.

Why?

Because testing Elixir dependencies could be a lot better. Why clutter up your code injecting dependencies when a process can handle it for you?

  • You can declare your modules instead of passing them around like state.
  • You can replace dependencies in a block context for easy testing.
  • It makes your code cleaner.

Usage

In your application code:

defmodule MyApp.Pact do
  use Pact

  register "http", HTTPoison
end

MyApp.Pact.start_link

defmodule MyApp.Users do
  def all do
    MyApp.Pact.get("http").get!("http://foobar.com/api/users")
  end
end

In your tests:

defmodule MyApp.UserTest do
  use ExUnit.Case
  require MyApp.Pact

  test "requests the corrent endpoint" do
    fakeHTTP = MyApp.Pact.generate :http do
      def get!(url) do
        send self(), {:called, url}
      end
    end

    MyApp.Pact.replace "http", fakeHTTP do
      MyApp.Users.all
    end

    assert_receive {:called, "http://foobar.com/api/users"}
  end
end

You can find more information in the documentation.

Disclaimer

Pact is very much an experiment at this point to see if it's viable. If you use Pact please get in touch with me to let me know how it worked out for you or how you think it could improve. If you have ideas feel free to open an issue or create a pull request.

Articles
to learn more about the elixir concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here 🔥.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here 🔥.

Queries
or most google FAQ's about Elixir.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory