{"action":"created","issue":{"url":"https://api.github.com/repos/antonmi/espec/issues/167","repository_url":"https://api.github.com/repos/antonmi/espec","labels_url":"https://api.github.com/repos/antonmi/espec/issues/167/labels{/name}","comments_url":"https://api.github.com/repos/antonmi/espec/issues/167/comments","events_url":"https://api.github.com/repos/antonmi/espec/issues/167/events","html_url":"https://github.com/antonmi/espec/issues/167","id":191774223,"number":167,"title":"Problems with Ecto Sandbox","user":{"login":"mwean","id":732173,"avatar_url":"https://avatars.githubusercontent.com/u/732173?v=3","gravatar_id":"","url":"https://api.github.com/users/mwean","html_url":"https://github.com/mwean","followers_url":"https://api.github.com/users/mwean/followers","following_url":"https://api.github.com/users/mwean/following{/other_user}","gists_url":"https://api.github.com/users/mwean/gists{/gist_id}","starred_url":"https://api.github.com/users/mwean/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mwean/subscriptions","organizations_url":"https://api.github.com/users/mwean/orgs","repos_url":"https://api.github.com/users/mwean/repos","events_url":"https://api.github.com/users/mwean/events{/privacy}","received_events_url":"https://api.github.com/users/mwean/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-11-25T23:18:54Z","updated_at":"2016-11-26T19:19:32Z","closed_at":null,"body":"I'm having problems with using the Ecto sandbox with espec. I have two examples, one where I don't create any records and expect `Sandbox.Repo.aggregate(Sandbox.Item, :count, :id)` to be 0, and another where I create 2 records and expect `Sandbox.Repo.aggregate(Sandbox.Item, :count, :id)` to be 2. If the 2-record example runs first, then they persist into the second and cause a failure. If I reproduce the examples with ExUnit, the examples work as expected.\r\n\r\nIs there a different way to use the sandbox with espec?\r\n\r\nHere's an example repo: https://github.com/mwean/sandbox\r\n\r\n```elixir\r\n# config/test.ex\r\nconfig :sandbox, Sandbox.Repo,\r\n  adapter: Ecto.Adapters.Postgres,\r\n  database: \"sandbox_test\",\r\n  hostname: \"localhost\",\r\n  port: \"5432\",\r\n  pool: Ecto.Adapters.SQL.Sandbox\r\n```\r\n\r\n```elixir\r\n# spec/spec_helper.exs\r\nEcto.Adapters.SQL.Sandbox.mode(Sandbox.Repo, :manual)\r\n```\r\n\r\n```elixir\r\n# spec/sandbox_spec.exs\r\ndefmodule SandboxSpec do\r\n  use ESpec, async: false\r\n\r\n  before do\r\n    Ecto.Adapters.SQL.Sandbox.checkout(Sandbox.Repo)\r\n  end\r\n\r\n  context \"there are no records\" do\r\n    it \"says there are no records\" do\r\n      expect(Sandbox.Repo.aggregate(Sandbox.Item, :count, :id)).to eq(0)\r\n    end\r\n  end\r\n\r\n  context \"there are records\" do\r\n    it \"says there are records\" do\r\n      Sandbox.Repo.insert!(%Sandbox.Item{name: \"a\"})\r\n      Sandbox.Repo.insert!(%Sandbox.Item{name: \"b\"})\r\n\r\n      expect(Sandbox.Repo.aggregate(Sandbox.Item, :count, :id)).to eq(2)\r\n    end\r\n  end\r\nend\r\n```\r\n\r\nElixir version: 1.3.4\r\nOS: macOS 10.12.1\r\n\r\n```\r\n> MIX_ENV=test mix deps\r\n...\r\n* espec 1.2.0 (Hex package) (mix)\r\n  locked at 1.2.0 (espec) 93a057d9\r\n  ok\r\n* ecto 2.0.5 (Hex package) (mix)\r\n  locked at 2.0.5 (ecto) 7f4c79ac\r\n  ok\r\n```"},"comment":{"url":"https://api.github.com/repos/antonmi/espec/issues/comments/263080751","html_url":"https://github.com/antonmi/espec/issues/167#issuecomment-263080751","issue_url":"https://api.github.com/repos/antonmi/espec/issues/167","id":263080751,"user":{"login":"dm1try","id":486807,"avatar_url":"https://avatars.githubusercontent.com/u/486807?v=3","gravatar_id":"","url":"https://api.github.com/users/dm1try","html_url":"https://github.com/dm1try","followers_url":"https://api.github.com/users/dm1try/followers","following_url":"https://api.github.com/users/dm1try/following{/other_user}","gists_url":"https://api.github.com/users/dm1try/gists{/gist_id}","starred_url":"https://api.github.com/users/dm1try/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dm1try/subscriptions","organizations_url":"https://api.github.com/users/dm1try/orgs","repos_url":"https://api.github.com/users/dm1try/repos","events_url":"https://api.github.com/users/dm1try/events{/privacy}","received_events_url":"https://api.github.com/users/dm1try/received_events","type":"User","site_admin":false},"created_at":"2016-11-26T19:19:32Z","updated_at":"2016-11-26T19:19:32Z","body":"in that case, I suggest manually call `checkin`for the connection in `finally` block.\r\n```elixir\r\n  finally do\r\n    :ok = Ecto.Adapters.SQL.Sandbox.checkin(Sandbox.Repo)\r\n  end\r\n```"}}
{"actor":{"display_login":"dm1try"}}