diff --git a/src/mocking.sh b/src/mocking.sh index d97b6cf..460cfeb 100644 --- a/src/mocking.sh +++ b/src/mocking.sh @@ -71,8 +71,14 @@ mock() { mkdir -p ${mock_workspace} echo "1" > ${mock_workspace}/invocation_index - _mock_handler ${mock_workspace} > ${mocks}/${executable} - chmod +x ${mocks}/${executable} + if [ -n "${executable%%*/*}" ]; then + _mock_handler ${mock_workspace} > ${mocks}/${executable} + chmod +x ${mocks}/${executable} + else + mkdir -p $(dirname ${executable}) + _mock_handler ${mock_workspace} > ${executable} + chmod +x ${executable} + fi invocation_count=1 else diff --git a/test/test_mocking_paths.sh b/test/test_mocking_paths.sh new file mode 100644 index 0000000..41cd005 --- /dev/null +++ b/test/test_mocking_paths.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +test_mocking_a_relative_path_works() { + mock some/path/to/a/file --and echo "Hello" + + result=$(some/path/to/a/file) + assert ${?} succeeded + assert "${result}" equals "Hello" +} + +test_mocking_a_file_path_works() { + mock file.exe --and echo "Hello" + + result=$(file.exe) + assert ${?} succeeded + assert "${result}" equals "Hello" +} + +test_mocking_a_relative_file_path_works() { + mock path/file.exe --and echo "Hello" + + result=$(path/file.exe) + assert ${?} succeeded + assert "${result}" equals "Hello" +}