cok ilginc geldi zaman bulup ögrenmek istiyorum.
Github projesi maalesef ölmüs. 2022 den beri update almiyor. Ancak hala kullanilabilir durumda.
shellspec kurulduktan sonra kullanacagimiz proje root unda
shellspec --init
calisitiriyoruz.
$ cd hello
# Initialize
$ shellspec --init
create .shellspec
create spec/spec_helper.sh
Böylece “.shellspec” ve “spec/spec_helper.sh” adinda iki dosya olusturuluyor.
Projede script lib klasöründe ve klasör yapisi asagindaki gib.
.
├── lib
│ └── hello.sh
└── spec
├── hello_spec.sh
└── spec_helper.sh
Bu klasör yapisinda hello_spec.sh dosyasinda testlerimizi isleyecegiz ancak önce “lib/hello.sh”. bakalim.
hello() {
echo "Hello ${1}!"
}
simdi bu scripti test etmek icin kullandigimiz test scriptine bakalim.
Describe 'hello.sh'
Include lib/hello.sh
Describe 'hello testing wrong'
It 'First test'
When call hello "tosba!"
The output should eq 'Hello tosba!'
End
End
Describe 'hello testing correct'
It 'says hello'
test() {
hello "testing!"
}
When call test
The output should eq 'Hello testing!'
End
End
Describe 'hello testing Not correct'
It 'says hello'
test() {
hello "testing!"
}
When call test
The output should eq 'Hello testing!'
End
End
End
Bu scripti project rootunda shellspec komutu ile calistirdigimizda 3 test de fail olacak.
$shellspec
Running: /bin/sh [bash 3.2.57(1)-release]
FFF
Examples:
1) hello.sh hello testing wrong First test
When call hello tosba!
1.1) The output should eq Hello tosba!
expected: "Hello tosba!"
got: "Hello tosba!!"
# spec/hello_spec.sh:11
2) hello.sh hello testing correct says hello
When call test
2.1) The output should eq Hello testing!
expected: "Hello testing!"
got: "Hello testing!!"
# spec/hello_spec.sh:21
3) hello.sh hello testing Not correct says hello
When call test
3.1) The output should eq Hello testing!
expected: "Hello testing!"
got: "Hello testing!!"
# spec/hello_spec.sh:30
Finished in 0.15 seconds (user 0.10 seconds, sys 0.04 seconds)
3 examples, 3 failures
Failure examples / Errors: (Listed here affect your suite's status)
shellspec spec/hello_spec.sh:5 # 1) hello.sh hello testing wrong First test FAILED
shellspec spec/hello_spec.sh:16 # 2) hello.sh hello testing correct says hello FAILED
shellspec spec/hello_spec.sh:25 # 3) hello.sh hello testing Not correct says hello FAILED
Bir yerde dikkat edin test sonuc ciktisinda FFF diye birsey var o 3 test oldugunu 3 ünün de FAIL oldugunu gösteriyor.
Simdi ilk testi gecirelim. Farki görün.
$shellspec
Running: /bin/sh [bash 3.2.57(1)-release]
.FF
Examples:
1) hello.sh hello testing correct says hello
When call test
1.1) The output should eq Hello testing!
expected: "Hello testing!"
got: "Hello testing!!"
# spec/hello_spec.sh:21
2) hello.sh hello testing Not correct says hello
When call test
2.1) The output should eq Hello testing!
expected: "Hello testing!"
got: "Hello testing!!"
# spec/hello_spec.sh:30
Finished in 0.15 seconds (user 0.10 seconds, sys 0.04 seconds)
3 examples, 2 failures
Failure examples / Errors: (Listed here affect your suite's status)
shellspec spec/hello_spec.sh:16 # 1) hello.sh hello testing correct says hello FAILED
shellspec spec/hello_spec.sh:25 # 2) hello.sh hello testing Not correct says hello FAILED
ve simdide tüm testleri gecirelim.
$shellspec
Running: /bin/sh [bash 3.2.57(1)-release]
...
Finished in 0.15 seconds (user 0.10 seconds, sys 0.03 seconds)
3 examples, 0 failures
Ayrica ilk test ile 2nci ve 3üncü testin syntaxlarina da dikkat edin.
Ilki dogrudan hello.sh kullaniyor.
It 'First test'
When call hello "tosba!"
The output should eq 'Hello tosba!'
End
Ikincisi bir fonksiyon ile cagiriyor. O fonksiyonu test ediyor.
Describe 'hello testing correct'
It 'says hello'
test() {
hello "testing!"
}
When call test
The output should eq 'Hello testing!'
End
End
Daha da detaylari github sayfasinda.