Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New to bats, can anyone share a real world project using bats and bats-mock #25

Closed
TheFern2 opened this issue Jun 21, 2023 · 3 comments
Closed

Comments

@TheFern2
Copy link

Hello, I have some scripts that depend on hardware and hence the need for my to use mock/stubs. Can anyone please share some insight as to how to setup a bats project, do all stub files go into a certain folder?

@TheFern2
Copy link
Author

I took a look at some of the "used by" projects, and tried to setup my structure like flash, although that repo sources from node modules, I have bats installed with brew.

Anyways if someone could please look at this project and tell me what's wrong, it does run my src/project.sh get_signal_level function but the stub isn't being injected for some reason and I get the following results.

  • src/ holds the project code
  • test/ holds bats tests and test_helper.bash with stub functions

https://github.com/TheFern2/my-bats-mock-test

~/g/t/bats-test ❯❯❯ bats test/first_test.bats                                                                  ✘ 1
first_test.bats
 ✗ cell_mgmt get_signal_level tests
   (in test file test/first_test.bats, line 19)
     `[ "$result" == 'nosignal' ]' failed
   Stubbing cell_mgmt
   ./src/project.sh: line 7: cell_mgmt: command not found

1 test, 1 failure

@ChrisJStone
Copy link

How did you install bats-mock? looking in the mock folder under test your missing binstub. This is more then likely the cause of your issue as I recreated your project setup at my-bats-mock-test and was able to get a passing test. Since I installed both bats and bats-mock as submodules, you would need to use git clone --recursive to automatically download bats and bats-mock if you wanted to test on your local machine.

@TheFern2
Copy link
Author

@ChrisJStone thank you, that was the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants