Sign inSign up

meltwater/rspec

By meltwater

Updated almost 4 years ago

Simple (and small) rspec test suite for code testing based on ruby2.5-alpine3.7 image

Image
0

5.5K

meltwater/rspec repository overview

First, we take the basic ruby image and then to it we will add the necessary rspec libraries (more can and should be added as required, but the goal should always be to keep things simple).

Build Details (Dockerfile)

Though the repo is private, there is nothing to hide here if anyone wants to know how to create / mod for their own use.

FROM ruby:2.5-alpine3.7

# Install minimal rSpec base
RUN set -ex \
    && apk update \
    && apk add --no-cache --virtual rspec-base \
         ruby-json \
         ruby-rake \
         ruby-bundler

# Install gem build dependancies
RUN apk add --no-cache --virtual build-dependancies \
         build-base \
         make \
         ruby-dev

# Install required set of gems to make life easy (and fast) then clean house
ENV RSPEC_VERSION 3.8
RUN gem install rspec --no-rdoc --no-ri -v $RSPEC_VERSION \
    && gem install json --no-rdoc --no-ri \
    && gem cleanup \
    && apk del build-dependancies \
    && rm -rf /usr/lib/ruby/gems/*/cache/* \
          /var/cache/apk/* \
          /tmp/* \
          /var/tmp/*

Runtime (CLI / Shell)

$ docker run -it --rm meltwater/rspec:3.8 sh

Runtime (Drone.io)

So we run this against k8s deployments so I will give you the benefit of looking at the whole deal... Repo layout for our kubectl yaml is built with both application and environment in-mind, so the rspec info exists in a known directory structure (EX: environment/application/spec) for each respective environment and application.

pipeline:
  smoke-test:
    image: meltwater/rspec:3.8
    when: 
      event: [ push ]
      status: [ success ]
    commands:
      - |
        IS_ERROR=0 && IS_TESTED=0 && WORKDIR=$(pwd) && \
        for dir in $(cat yaml_files_changed | cut -d/ -f1,2 | sort | uniq); do
          if [ -d $dir/spec ]; then
            printf -- '-%.0s' $(seq 72) && echo '' && echo 'TESTING --> '$dir && printf -- '-%.0s' $(seq 72) && echo ''
            sh -c "cd $WORKDIR/$dir && rspec" | tee test_results;
            grep ' 0 failure' test_results 2>&1 >/dev/null || IS_ERROR=1
            IS_TESTED=$(($IS_TESTED+1))
          fi
        done
        if [ $IS_ERROR -gt 0 ]; then exit $IS_ERROR; fi
        if [ $IS_TESTED -eq 0 ]; then echo "SKIP: No rSpec Tests in associated yaml configs" && exit 0; fi

Output Sample:

------------------------------------------------------------------------
TESTING --> development/application
------------------------------------------------------------------------
..

Finished in 0.00259 seconds (files took 0.23591 seconds to load)
2 examples, 0 failures

------------------------------------------------------------------------
TESTING --> production/application
------------------------------------------------------------------------
..

Finished in 0.00272 seconds (files took 0.249 seconds to load)
2 examples, 0 failures

Tag summary

Content type

Image

Digest

sha256:414a7979a

Size

107 MB

Last updated

almost 4 years ago

docker pull meltwater/rspec