Skip to content

Commit

Permalink
Merge pull request #213 from ellneal/feature/docker
Browse files Browse the repository at this point in the history
Making running the tests a bit easier
  • Loading branch information
samlown committed Nov 26, 2016
2 parents 29a0753 + 3d7ecbb commit e5116b8
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 2 deletions.
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM ruby:2.3

ENV WORK_DIR /usr/lib/couchrest_model

RUN mkdir -p $WORK_DIR
WORKDIR $WORK_DIR

COPY . $WORK_DIR

RUN bundle install --jobs=3 --retry=3

2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
source "https://rubygems.org"
gemspec

gem "guard-rspec", "~> 4.7.0", group: :test

# Enable for testing against local couchrest
# gem "couchrest", path: "/Users/sam/workspace/couchrest"
31 changes: 31 additions & 0 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# A sample Guardfile
# More info at https://github.com/guard/guard#readme

## Uncomment and set this to only include directories you want to watch
# directories %w(app lib config test spec features) \
# .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}

## Note: if you are using the `directories` clause above and you are not
## watching the project directory ('.'), then you will want to move
## the Guardfile to a watched dir and symlink it back, e.g.
#
# $ mkdir config
# $ mv Guardfile config/
# $ ln -s config/Guardfile .
#
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"

# Note: The cmd option is now required due to the increasing number of ways
# rspec may be run, below are examples of the most common uses.
# * bundler: 'bundle exec rspec'
# * bundler binstubs: 'bin/rspec'
# * spring: 'bin/rsspec' (This will use spring if running and you have
# installed the spring binstubs per the docs)
# * zeus: 'zeus rspec' (requires the server to be started separetly)
# * 'just' rspec: 'rspec'
guard :rspec, cmd: 'rspec' do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/couchrest/model/(.+)\.rb$}) { |m| "spec/unit/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
end

26 changes: 26 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version: "2"
services:
test:
build:
context: .
entrypoint: ["bundle", "exec"]
command: ["rspec"]
environment:
RAILS_ENV: test
COUCH_HOST: "http://couch:5984/"
depends_on:
- couch
volumes:
- ./:/usr/lib/couchrest_model
networks:
- couchrest_model
couch:
image: couchdb:1.6
ports:
- "5984"
networks:
- couchrest_model
- default
networks:
couchrest_model:
driver: bridge
17 changes: 16 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,29 @@
FIXTURE_PATH = File.join(File.dirname(__FILE__), '/fixtures')
SCRATCH_PATH = File.join(File.dirname(__FILE__), '/tmp')

COUCHHOST = "http://127.0.0.1:5984"
COUCHHOST = ENV["COUCH_HOST"] || "http://127.0.0.1:5984"
TESTDB = 'couchrest-model-test'
TEST_SERVER = CouchRest.new COUCHHOST
# TEST_SERVER.default_database = TESTDB
DB = TEST_SERVER.database(TESTDB)
end

RSpec.configure do |config|
config.before(:suite) do
couch_uri = URI.parse(ENV['COUCH_HOST'] || "http://127.0.0.1:5984")
CouchRest::Model::Base.configure do |config|
config.connection = {
:protocol => couch_uri.scheme,
:host => couch_uri.host,
:port => couch_uri.port,
:username => couch_uri.user,
:password => couch_uri.password,
:prefix => "couchrest",
:join => "_"
}
end
end

config.before(:all) { reset_test_db! }

config.after(:all) do
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/connection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
expect(@class.server).to be_a(CouchRest::Server)
end
it "should provide a server with default config" do
expect(@class.server.uri.to_s).to eql("http://localhost:5984")
expect(@class.server.uri.to_s).to eql(CouchRest::Model::Base.server.uri.to_s)
end
it "should allow the configuration to be overwritten" do
@class.connection = {
Expand Down

0 comments on commit e5116b8

Please sign in to comment.