Skip to content

Commit

Permalink
Adds after_run hook to env.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
kelseyroy committed Jul 20, 2023
1 parent f41bfce commit a6336f9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 0 additions & 1 deletion lib/http_server_fixture/data/test-data.json

This file was deleted.

7 changes: 6 additions & 1 deletion lib/to_do/db.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
defmodule ToDo.DB do
@file_path Application.compile_env(:http_server, :file_path, "lib/to_do/data/to_dos.json")

def all, do: File.read!(@file_path) |> JSON.decode!()
def all do
case File.exists?(@file_path) do
true -> File.read!(@file_path) |> JSON.decode!()
false -> %{}
end
end

def save(data), do: File.write(@file_path, JSON.encode!(data), [:read, :write])

Expand Down
7 changes: 7 additions & 0 deletions test/http_server_spec/features/support/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@
HOSTNAME = yaml["server"]["hostname"]
PORT = yaml["server"]["port"]
PROTOCOL = yaml["server"]["protocol"]

Spinach.hooks.after_run do |status|
pn = File.expand_path('../../../../lib/http_server_fixture/data/test-data.json', __dir__)
File.delete(pn) if File.exist?(pn)
file_deleted = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\ntest-data file deleted\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
puts file_deleted unless File.exist?(pn)
end

0 comments on commit a6336f9

Please sign in to comment.