defmodule Mix.Tasks.Phoenix.NewTest do
  use ExUnit.Case

  @app_name "photo_blog"
  @destination_path "/tmp"

  setup_all do
    Mix.Tasks.Phoenix.New.run([@app_name, @destination_path])
    :ok
  end

  test "creates files and directories" do
    expected_files = [".gitignore",
      "README.md",
      "lib",
      "lib/photo_blog.ex",
      "lib/photo_blog/controllers/pages.ex",
      "lib/photo_blog/router.ex",
      "lib/photo_blog/supervisor.ex",
      "mix.exs",
      "test",
      "test/photo_blog_test.exs",
      "test/test_helper.exs"]

    for file <- expected_files do
      path = Path.join(project_path, file)

      assert File.exists?(path)
    end
  end

  test "files contain application name" do
    path = Path.join(project_path, "lib/photo_blog.ex")
    {:ok, content} = File.read(path)

    assert Regex.match?(~r/PhotoBlog/, content)
  end

  test "missing name and/or path arguments" do
    assert :ok == Mix.Tasks.Phoenix.New.run([])
    assert :ok == Mix.Tasks.Phoenix.New.run([@app_name])
  end

  teardown_all do
    File.rm_rf(project_path)
    :ok
  end

  def project_path do
    Path.join(@destination_path, @app_name)
  end
end

defmodule Mix.Tasks.Phoenix.NewTest do
  use ExUnit.Case

  @app_name "photo_blog"
  @destination_path "/tmp"

  setup_all do
    Mix.Tasks.Phoenix.New.run([@app_name, @destination_path])
    on_exit fn() -> File.rm_rf(project_path) end
    :ok
  end

  test "creates files and directories" do
    expected_files = [".gitignore",
      "README.md",
      "lib",
      "lib/photo_blog.ex",
      "lib/photo_blog/controllers/pages.ex",
      "lib/photo_blog/router.ex",
      "lib/photo_blog/supervisor.ex",
      "mix.exs",
      "test",
      "test/photo_blog_test.exs",
      "test/test_helper.exs"]

    for file <- expected_files do
      path = Path.join(project_path, file)

      assert File.exists?(path)
    end
  end

  test "files contain application name" do
    path = Path.join(project_path, "lib/photo_blog.ex")
    {:ok, content} = File.read(path)

    assert Regex.match?(~r/PhotoBlog/, content)
  end

  test "missing name and/or path arguments" do
    assert :ok == Mix.Tasks.Phoenix.New.run([])
    assert :ok == Mix.Tasks.Phoenix.New.run([@app_name])
  end

  def project_path do
    Path.join(@destination_path, @app_name)
  end
end

Fix test callbacks (teardown_all -> on_exit
Fix test callbacks (teardown_all -> on_exit

lono-devices/phoenix,jwarwick/phoenix,KazuCocoa/phoenix,Joe-noh/phoenix,andrewvy/phoenix,marcioj/phoenix,robomc/phoenix,rodrigues/phoenix,pap/phoenix,foxnewsnetwork/phoenix,Ben-Evolently/phoenix,hotvulcan/phoenix,linearregression/phoenix,maxnordlund/phoenix,CD1212/phoenix,Gazler/phoenix,cas27/phoenix,mobileoverlord/phoenix,optikfluffel/phoenix,jeffweiss/phoenix,phoenixframework/phoenix,ericmj/phoenix,eksperimental/phoenix,mschae/phoenix,nshafer/phoenix,tony612/phoenix,phoenixframework/phoenix,Eventacular/phoenix,CultivateHQ/phoenix,daytonn/phoenix,Gazler/phoenix,Fluxuous/phoenix,GabrielNicolasAvellaneda/phoenix,lono-devices/phoenix,ericmj/phoenix,0x00evil/phoenix,ybur-yug/phoenix,ephe-meral/phoenix,wsmoak/phoenix,kyledecot/phoenix,iStefo/phoenix,mschae/phoenix,StevenNunez/phoenix,rafbgarcia/phoenix,rafbgarcia/phoenix,wicliff/phoenix,mvidaurre/phoenix,Dahoon/phoenix,jasond-s/phoenix,scrogson/phoenix,mitchellhenke/phoenix,brucify/phoenix,SmartCasual/phoenix,jamilabreu/phoenix,doomspork/phoenix,korobkov/phoenix,DavidAlphaFox/phoenix,hsavit1/phoenix,trarbr/phoenix,robhurring/phoenix,safi/phoenix,yoavlt/phoenix,mvidaurre/phoenix,VictorZeng/phoenix,optikfluffel/phoenix,nshafer/phoenix,paulcsmith/phoenix,JHKennedy4/phoenix,seejee/phoenix,stevedomin/phoenix,kidaa/phoenix,jwarwick/phoenix,bsmr-erlang/phoenix,gjaldon/phoenix,dmarkow/phoenix,Kosmas/phoenix,Kosmas/phoenix,evax/phoenix,seejee/phoenix,lancehalvorsen/phoenix,jxs/phoenix,nshafer/phoenix,jeffkreeftmeijer/phoenix,rodrigues/phoenix,sadiqmmm/phoenix,michalmuskala/phoenix,romul/phoenix,nickgartmann/phoenix,nicrioux/phoenix,greyhwndz/phoenix,0x00evil/phoenix,doron2402/phoenix,esbullington/phoenix-1,optikfluffel/phoenix,korobkov/phoenix,keathley/phoenix,henrik/phoenix,pap/phoenix,Rumel/phoenix,Joe-noh/phoenix,stevedomin/phoenix,andrewvy/phoenix,0x00evil/phoenix,milafrerichs/phoenix,omotenko/phoenix_auth,iStefo/phoenix,omotenko/phoenix_auth,switchflip/phoenix,manukall/phoenix,mitchellhenke/phoenix,Smulligan85/phoenix,ACPK/phoenix,dmarkow/phoenix,Rumel/phoenix,beni55/phoenix,vic/phoenix,javimolla/phoenix,gjaldon/phoenix,michalmuskala/phoenix,iguberman/phoenix,jamilabreu/phoenix,kevinold/phoenix,bsodmike/phoenix,keathley/phoenix,phoenixframework/phoenix,ugisozols/phoenix,mobileoverlord/phoenix,bsmr-erlang/phoenix,arthurcolle/phoenix,kholbekj/phoenix,wsmoak/phoenix,y-yagi/phoenix,evax/phoenix,justnoxx/phoenix,ephe-meral/phoenix,fbjork/phoenix,ybur-yug/phoenix,thegrubbsian/phoenix,FND/phoenix,sdnorm/phoenix,begleynk/phoenix,lancehalvorsen/phoenix,elliotcm/phoenix,xtity/simple_phoenix,Smulligan85/phoenix,stefania11/phoenix,cas27/phoenix,yonglehou/phoenix,eksperimental/phoenix,bdtomlin/phoenix,manukall/phoenix,DavidAlphaFox/phoenix,rafbgarcia/phoenix,CultivateHQ/phoenix,vic/phoenix,bitgamma/phoenix,trarbr/phoenix,ahmetabdi/phoenix