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

Function mocking by export in shunit2 #7

Open
yman45 opened this issue Sep 12, 2021 · 1 comment
Open

Function mocking by export in shunit2 #7

yman45 opened this issue Sep 12, 2021 · 1 comment
Assignees

Comments

@yman45
Copy link

yman45 commented Sep 12, 2021

Your shunit2 description mentions that it can't be used to mock functions by export. In my experience it's working though.
Looks like alias in your unit test example is still in effect and break function export test.
This patch makes tests work for me.

diff --git a/example-shunit2/test/unit_test.sh b/example-shunit2/test/unit_test.sh
index 82176e0..38d64ed 100755
--- a/example-shunit2/test/unit_test.sh
+++ b/example-shunit2/test/unit_test.sh
@@ -20,12 +20,10 @@ function test_there_should_be_20_percent_discount_for_large_quantities_on_odd_da
 
   assertEquals 0 $?
   assertContains "${result}" "Total 320"
+  unalias getDay
 }
 
 function test_there_should_be_no_discount_even_for_large_quantities_on_even_days() {
-  # Mocking by exporting functions does not work for shunit2
-  startSkipping
-
   source src/ice_cream_price.sh
 
   # Mocking a function by exporting a function

And by the way, thanks for the great guide!

@dodie
Copy link
Owner

dodie commented Sep 15, 2021

Hey @yman45 ,

Thanks for the correction! I'll check and update the guide!

Cheers,
David

@dodie dodie self-assigned this Sep 15, 2021
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