Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

RSpec pipeline configurations for Ruby on Rails?

Aniket Rao October 12, 2016

Can anyone help me with my rspec configurations for Bitbucket pipeline? How do I set it up?

This is the build failed message.

Screen Shot 2016-10-13 at 9.52.26 AM.png

pipelines configuration file

# This is a sample build configuration for Ruby.
# Check our guides at https://confluence.atlassian.com/x/VYk8Lw for more examples.
# Only use spaces to indent your .yml configuration.
# -----
# You can specify a custom docker image from Docker Hub as your build environment.
image: ruby:2.3.0

pipelines:
  default:
    - step:
        script: # Modify the commands below to build your repository.
          - bundler --version
          - bundle install
          - bundle exec rspec

 

What am I missing out on?

4 answers

1 accepted

0 votes
Answer accepted
Aniket Rao October 14, 2016

Created the docker image with ruby version 2.3.1 and then my script is as below along with my database.yml and secrets.yml which the Pipeline needs to run tests. After hours of debugging and error after error.

Moving all base configurations to docker is much efficient I suppose.

## bitbucket-pipelines.yml
image: aniketrao/ruby-psql
pipelines:
   default:
      - step:
         script: # Modify the commands below to build your repository.
            - /etc/init.d/postgresql start
            - sudo -u postgres sh -c 'createuser --superuser root & createdb ruby'
            - sudo -u postgres psql -c "ALTER USER root PASSWORD 'postgres';"
            - gem install 'pg'
            - ruby test.rb
            - apt-get update
            - apt-get --assume-yes install nodejs
            - bundle install
            - mv config/secrets.ci.yml config/secrets.yml
            - mv config/database.ci.yml config/database.yml
            - bundle exec rake db:create db:migrate db:schema:load --trace
            - bundle exec rspec
## database.ci.yml
 
development:
   adapter: postgresql
   database: app_test
   host: localhost
   pool: 5
   username: root
   password: postgres
   template: template0
## secrets.ci.yml
 
development:
  secret_key_base: 6fe52c848a0448c9ddaebd47aad73b85caf99df2f3b70537ae43109e1843159ba432142142f66181195df1f5da49a54abc902bd4c5ffe86697b17d90d05b8fd9

 

If anyone is stuck, this should help.

 

Thanks Sten!

1 vote
Sten Pittet
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 13, 2016

Looking online it seems that installing nodejs might solve your issue.

Could you try the following configuration and tell me what you get?

# This is a sample build configuration for Ruby.
# Check our guides at https://confluence.atlassian.com/x/VYk8Lw for more examples.
# Only use spaces to indent your .yml configuration.
# -----
# You can specify a custom docker image from Docker Hub as your build environment.
image: ruby:2.3.0
 
pipelines:
  default:
    - step:
        script: # Modify the commands below to build your repository.
          - apt-get update
          - apt-get install nodejs
          - bundle install
          - bundle exec rspec
0 votes
BrennanHoeting January 20, 2018

Atlassian has released instructions on how to do this here.

bitbucket-pipelines.yml

image: ruby:2.4.2

pipelines:
default:
- step:
script:
- export DATABASE_URL=postgresql://test_user:test_user_password@localhost/pipelines
- bundle install
- bundle exec rails db:test:prepare
- bundle exec rspec
services:
- postgres
definitions:
services:
postgres:
image: postgres
environment:
POSTGRES_DB: pipelines
POSTGRES_USER: test_user
POSTGRES_PASSWORD: test_user_password

 config/database.yml

test:
<<: *default
url: <%= ENV['DATABASE_URL'] %>
database: <%= ENV['POSTGRES_DB'] %>
username: <%= ENV['POSTGRES_USER'] %>
password: <%= ENV['POSTGRES_PASSWORD'] %>

 

0 votes
Alex Soto October 13, 2016

I suggest you troubleshoot with docker locally

 

```

docker run -it  --volume=`pwd`:/repo --workdir="/repo" ruby:2.3.0 /bin/bash

```

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events