Skip to content

Commit

Permalink
Support mocking for paths
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Roy authored and lindycoder committed Dec 1, 2016
1 parent 4ca6968 commit d9f2b5c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/mocking.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions test/test_mocking_paths.sh
Original file line number Diff line number Diff line change
@@ -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"
}

0 comments on commit d9f2b5c

Please sign in to comment.