# `Igniter.Test`
[🔗](https://github.com/ash-project/igniter/blob/v0.8.2/lib/igniter/test.ex#L5)

Tools for testing with igniter.

# `apply_igniter`

```elixir
@spec apply_igniter(Igniter.t()) ::
  {:ok, Igniter.t(),
   %{
     tasks: [{String.t(), [String.t()]}],
     warnings: [String.t()],
     notices: [String.t()]
   }}
  | {:error, [String.t()]}
```

Fakes applying the changes of an igniter.

This function returns any tasks, errors, warnings.

# `apply_igniter!`

```elixir
@spec apply_igniter!(Igniter.t()) :: Igniter.t() | no_return()
```

Applies an igniter, raising an error if there are any issues.

See `apply_igniter/1` for more.

# `assert_content_equals`

# `assert_creates`

Asserts that a file was created during the igniter run.

The third argument is optional. It can be either:

  * a string — the file's full contents are compared for equality
  * a 1-arity function — invoked with the file's contents so you can run
    custom assertions (e.g. regex matches) against the file

## Examples

    test_project()
    |> Igniter.create_new_file("lib/example.ex", "defmodule Example, do: nil")
    |> assert_creates("lib/example.ex")

    test_project()
    |> Igniter.create_new_file("lib/example.ex", "defmodule Example, do: nil")
    |> assert_creates("lib/example.ex", "defmodule Example, do: nil")

    test_project()
    |> Igniter.create_new_file("mix.exs", contents)
    |> assert_creates("mix.exs", fn file ->
      assert file =~ ~r/def project/
      assert file =~ "app: :test"
    end)

# `assert_has_delayed_task`

# `assert_has_issue`

# `assert_has_notice`

# `assert_has_patch`

# `assert_has_task`

# `assert_has_warning`

# `assert_moves`

```elixir
@spec assert_moves(Igniter.t(), from :: String.t(), [{:to, String.t()}]) ::
  Igniter.t()
```

Asserts that a file was moved to a specific location.

## Example

    test_project()
    |> Igniter.move_file("lib/old_location.ex", "lib/new_location.ex")
    |> assert_moves("lib/old_location.ex", "lib/new_location.ex")

# `assert_rms`

# `assert_unchanged`

# `assert_unchanged`

# `diff`

```elixir
@spec diff(Igniter.t(), opts :: Keyword.t()) :: String.t()
```

Return the current `igniter` diff.

## Options

* `:only` - Only return the diff for this file or files

# `phx_test_project`

Sets up a test igniter that mimics a new phoenix project

# `puts_diff`

```elixir
@spec puts_diff(Igniter.t(), opts :: Keyword.t()) :: Igniter.t()
```

Print the current `igniter` diff, returning the `igniter`.

This is primarily used for debugging purposes.

## Options

* `:label` - A label to print before the diff
* `:only` - Only print the diff for this file or files

# `refute_creates`

Asserts that a file was NOT created during the igniter run.

This will pass if the file doesn't exist at all, or if it already existed
before the igniter run started.

## Examples

    test_project()
    |> refute_creates("lib/non_existent.ex")

    test_project()
    |> refute_creates("mix.exs")  # mix.exs already exists

# `test_project`

```elixir
@spec test_project(opts :: Keyword.t()) :: Igniter.t()
@spec test_project(opts :: Keyword.t()) :: Igniter.t()
```

Sets up a test igniter that has  only the files passed to it.

## Starting point

All of the files of an empty mix project are added by default.
You can specify more or overwrite files with the `:files` option.

## Limitations

You cannot install new dependencies, or use dependencies your own project does not have.
If you need to do that kind of thing, you will have to do a test that uses tools like
`System.cmd` in a temporary directory.

## Options

* `files` - A map of file paths to file contents. The file paths should be relative to the project root.
* `app_name` - The name of the application. Defaults to `:test`.

## Examples

    test_project(files: %{
      "lib/foo.ex" => """
      defmodule MyApp.Foo do
        use Ash.Resource
      end
      """
    })

---

*Consult [api-reference.md](api-reference.md) for complete listing*
