RSpec unit testing¶
RSpec is the easiest tool to use to quickly test your Ruby code.
Learn by example
Check out our example RSpec repository.
Output formats¶
RSpec supports the following outputs:
progress
minimal output only showing a.
for success andF
for failure.documentaion
a text type output showing results as text.RspecJunitFormatter
a custom formatter outputting JUnit. <-- Supported by Calliope
Getting JUnit XML output¶
Add the gem to your Gemfile using gem 'rspec_junit_formatter'
or install it separately using gem install rspec_junit_formatter
Then run your RSpec with the new formatter using rspec --format RspecJunitFormatter --out rspec.xml
Adding it to your CI/CD¶
GitLab¶
stages:
- build
- test
# Build whatever project you are testing
build:
stage: build
script:
- docker build --tag=eu.gcr.io/$GC_PROJECT/calliope:$CI_COMMIT_REF_SLUG-$REVISION .
# Test it referring to yhe build tag
test:
stage: test
variables:
PROFILE_ID_TEST: 248
PROFILE_ID_MASTER: 248
PROFILE_ID_DEVELOPMENT: 248
CALLIOPE_API_KEY: YourApiKey
script:
- mkdir output
- docker run -e "RAILS_ENV=development" --rm \
-v $PWD/output:/srv/output \
--name testing_calliope_build eu.gcr.io/$GC_PROJECT/calliope:$CI_COMMIT_REF_SLUG-$REVISION \
bundle exec rspec -f d -f RspecJunitFormatter --out /srv/output/rspec.xml --require rails_helper
- if [ "$CI_COMMIT_REF_SLUG" == "master" ]; then CALLIOPE_PROFILE_ID="${PROFILE_ID_MASTER}"; fi
- if [ "$CI_COMMIT_REF_SLUG" == "test" ]; then CALLIOPE_PROFILE_ID="${PROFILE_ID_TEST}"; else CALLIOPE_PROFILE_ID="${PROFILE_ID_DEVELOPMENT}"; fi
- curl -X POST
-H "Content-Type:multipart/form-data"
-H "x-api-key:${CALLIOPE_API_KEY}"
-F "file[]=@path/to/testresult"
"https://app.calliope.pro/api/v2/profile/${CALLIOPE_PROFILE_ID}/import/junit?tag[]=RSpec&tag[]=branch:$CI_COMMIT_REF_SLUG&tag[]=revision:$REVISION"
Feedback or additions¶
If you have and feedback or wish to suggestion future additions to this documentation, please let us know.