Skip to content

Commit

Permalink
Merge pull request #5 from Sage/feature_travis_ci_setup
Browse files Browse the repository at this point in the history
Feature travis ci setup
  • Loading branch information
vaughanbrittonsage authored Nov 30, 2016
2 parents 33111d6 + 97931d8 commit 9ddcf5d
Show file tree
Hide file tree
Showing 15 changed files with 97 additions and 42 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
/spec/reports/
/tmp/
.idea
/.idea
7 changes: 0 additions & 7 deletions .idea/.rakeTasks

This file was deleted.

4 changes: 0 additions & 4 deletions .idea/misc.xml

This file was deleted.

15 changes: 15 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
language: ruby
rvm:
- 2.3.0
- 2.3.1

cache: bundler

deploy:
provider: rubygems
api_key:
secure: "EDl36Hp48wNCJDhLSaoFcMKv+oZfmUky5gOOEJGJxmjva8f7f1IN2+sYczsAc2pwRz7AEF9z8xVvOB1P3qBHUY1meJjz5l6FujTx4UF0KL3jSJA+viiJxzKzhEav8UCcoR5KeAWOAg6rvaoRS2AFM39NawdeAmGaJexf97SC9fqb6SA7y8e3LFUtzbje4dFfyn9Yg88wb3n8wIscDQH3uV5ZUwyK2F6WAkEbd00VN4rL4DMdnMCQImi6w4sobEKc0qaqY0UMBJfiF68W5P+L21rQPfFowUoRJWW16vDbhuOW0VZpaq6AqEAr1lxrARO46bnRZV/O3vdIYzwzJn96rPGY2ixfFLMkyOJQ9UrCYwRZ1/GKrF5GdVrksqyVkI9UfKu9wsy882glUezbzmfGtax3k+AB0L+9BZ3e7Nw7YWYTJr//Bgkb0ajs8oHmt8n/KGYUPSc4ITZK+WSEMeTUELhm2JptEJ4ElEVRzdbL+c1eRUV4Q6nYcG0Kur1KG1qaV8FeP5hBGqL3BCqg+m9l2gwROkCjwAaQybgUmXfdwcjUt9s/V1p4ccJpNNAxa5J0UL+FAuZWb0zaXeZ2jgZ7b7OlyQWf6cNXrM+r9diP96XCKHnQoby5snMM0PBrWy/dnxZcZXnwGACYwLTujQsjQpWCa7yBXom1XyM9Ojq37HM="
gem: sinject
on:
tags: true

2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
source "https://rubygems.org"
source "http://rubygems.org"
gemspec

8 changes: 6 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
require "bundler/gem_tasks"
task :default => :spec
require 'rake'
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec)

task :default => :spec
1 change: 0 additions & 1 deletion lib/sinject.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require "sinject/version"
require 'sinject/class'
require 'sinject/container'
require 'sinject/container_item'
Expand Down
5 changes: 2 additions & 3 deletions lib/sinject/container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def register(options = {}, &initialize_block)
raise Sinject::DependencyRegistrationKeyNotSpecifiedException.new
end

if(!options.has_key?(:key))
if(!options.has_key?(:class))
raise Sinject::DependencyRegistrationClassNotSpecifiedException.new
end

Expand Down Expand Up @@ -117,7 +117,7 @@ def load_groups
Sinject::DependencyGroup.descendants.each do |g|
group = g.new
if group.is_valid?
group.register(Sinject::Container.instance)
group.register(self)
end
end
end
Expand Down Expand Up @@ -155,7 +155,6 @@ def validate_contract(dependency_class, contract_class)
end

def create_instance(item)
instance = nil

#check if a custom initializer block has been specified
if item.initialize_block != nil
Expand Down
2 changes: 1 addition & 1 deletion lib/sinject/exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def initialize(key)
end

def to_s
"A Dependency has already been registered for the key: '#{key}'"
"A Dependency has already been registered for the key: '#{@key}'"
end

end
Expand Down
3 changes: 0 additions & 3 deletions lib/sinject/version.rb

This file was deleted.

8 changes: 8 additions & 0 deletions script/cleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh
echo cleanup started
echo stop all containers
docker stop $(docker ps -a -q)
echo removed untagged images
docker rmi -f $(docker images | grep "<none>" | awk "{print \$3}")
docker rm -v $(docker ps -a -q -f status=exited)
echo cleanup complete
6 changes: 6 additions & 0 deletions script/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
gem_test_runner:
image: codeguru/ruby:2.3.1-alpine-3.4
container_name: gem_test_runner
command: bash -c "while true; do echo 'Container is running...'; sleep 2; done"
volumes:
- ../:/gem_src
8 changes: 8 additions & 0 deletions script/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh

echo start rspec tests
docker-compose up -d

spec_path=spec/$1

docker exec -it gem_test_runner bash -c "cd gem_src && bundle install && bundle exec rspec ${spec_path}"
32 changes: 26 additions & 6 deletions sinject.gemspec
Original file line number Diff line number Diff line change
@@ -1,20 +1,40 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'sinject/version'

####################
#### Set GEM Version based on GIT Release TAG when built with Travis
####################
version = ''
if ENV['TRAVIS_TAG'] != nil
puts "CI Branch - '#{ENV['TRAVIS_TAG']}'"
version = ENV['TRAVIS_TAG']
end

#if the tag version starts with v (e.g. vx.x.x)
if version.downcase.match /^v/
#trim the v and set the version to x.x.x
version = version.dup
version.slice!(0)
elsif ENV['TRAVIS_TAG'] != nil && ENV['TRAVIS_TAG'] != ''
version = "0.0.0.#{ENV['TRAVIS_TAG']}"
else
#otherwise it is not a valid release tag so set the version 0.0.0 as it not being released.
version = '0.0.0'
end

Gem::Specification.new do |spec|
spec.name = "sinject"
spec.version = Sinject::VERSION
spec.authors = ["vaughan britton"]
spec.email = ["vaughanbritton@gmail.com"]
spec.version = version
spec.authors = ["Sage One"]
spec.email = ["vaughan.britton@sage.com"]

spec.summary = "Simple Dependency Injection."
spec.description = "A simple dependency injection framework."
spec.homepage = "https://github.com/vaughanbrittonsage/sinject"
spec.homepage = "https://github.com/sage/sinject"
spec.license = "MIT"

spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.files = Dir.glob("{bin,lib}/**/**/**")
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
Expand Down
37 changes: 23 additions & 14 deletions spec/sinject/sinject_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
expect(container).to eq(Sinject::Container.instance)
end

it 'should not populate the class variable when instance created with the singleton=false option' do
it 'should NOT populate the class variable when instance created with the singleton=false option' do

container = Sinject::Container.new(false)

Expand All @@ -20,15 +20,15 @@

it 'should report a registered dependency when asked' do

container = Sinject::Container.new
container = Sinject::Container.new(false)
container.register({ :key => :multi_instance, :class => MultiInstance })

expect(container.is_registered?(:multi_instance)).to eq(true)

end

it 'should return a multi instance object correctly' do
container = Sinject::Container.new
container = Sinject::Container.new(false)
container.register({ :key => :multi_instance, :class => MultiInstance, :singleton => false })
obj1 = container.get(:multi_instance)

Expand All @@ -41,7 +41,7 @@

it 'should return a single instance object correctly' do

container = Sinject::Container.new
container = Sinject::Container.new(false)
container.register({ :key => :single_instance, :class => SingleInstance, :singleton => true })
obj1 = container.get(:single_instance)

Expand All @@ -55,7 +55,7 @@

it 'should build a requested object with dependencies' do

container = Sinject::Container.new
container = Sinject::Container.new(false)
container.register({ :key => :hello_world, :class => HelloWorld, :singleton => true })
container.register({ :key => :goodbye_world, :class => GoodbyeWorld, :singleton => false })
container.register({ :key => :object_with_dependencies, :class => ObjectWithDependency, :singleton => false })
Expand All @@ -68,33 +68,33 @@
expect(obj.goodbye_world).to eq(obj.goodbye_world)
end

it 'should not throw an exception for a dependency registration with a valid contract' do
it 'should NOT throw an exception for a dependency registration with a valid contract' do

container = Sinject::Container.new
container = Sinject::Container.new(false)

expect { container.register({ :key => :logger, :class => CustomLogger, :singleton => true, :contract => LoggerContract }) }.not_to raise_error

end

it 'should throw a DependencyContractMissingMethodsException for a dependency registration with missing methods from the contract' do

container = Sinject::Container.new
container = Sinject::Container.new(false)

expect { container.register({ :key => :logger, :class => SingleInstance, :singleton => true, :contract => LoggerContract }) }.to raise_error(Sinject::DependencyContractMissingMethodsException)

end

it 'should throw a DependencyContractInvalidParametersException for a dependency registration with invalid method parameters compared to the contract' do

container = Sinject::Container.new
container = Sinject::Container.new(false)

expect { container.register({ :key => :cache_control, :class => RedisCacheControl, :singleton => true, :contract => CacheControlContract }) }.to raise_error(Sinject::DependencyContractInvalidParametersException)

end

it 'should create a dependency from a custom initialize block' do

container = Sinject::Container.new
container = Sinject::Container.new(false)
container.register({ :key => :hello_world, :class => HelloWorld }) do
instance = HelloWorld.new
instance.value = 'Custom init'
Expand All @@ -109,7 +109,7 @@

it 'should throw a DependencyInitializeException for a dependency initializer block that fails to create a dependency of the expected type' do

container = Sinject::Container.new
container = Sinject::Container.new(false)
container.register({ :key => :hello_world, :class => HelloWorld }) do
GoodbyeWorld.new
end
Expand All @@ -120,21 +120,30 @@

it 'should load dependencies from valid dependencygroups' do

container = Sinject::Container.new
container = Sinject::Container.new(false)
container.load_groups

expect(container.is_registered?(:hello_world)).to eq(true)
expect(container.is_registered?(:goodbye_world)).to eq(true)

end

it 'should not load dependencies from invalid dependencygroups' do
it 'should NOT load dependencies from invalid dependencygroups' do

container = Sinject::Container.new
container = Sinject::Container.new(false)
container.load_groups

expect(container.is_registered?(:logger)).to eq(false)

end

context 'when a duplicate dependency key is registered' do
it 'should raise an exception' do
container = Sinject::Container.new(false)
container.register({ :key => :single_instance, :class => SingleInstance, :singleton => true })
expect{ container.register({ :key => :single_instance, :class => SingleInstance, :singleton => true }) }.to raise_error(Sinject::DependencyRegistrationException)
end
end


end

0 comments on commit 9ddcf5d

Please sign in to comment.