Skip to content

Commit

Permalink
Rewrite specs (#13)
Browse files Browse the repository at this point in the history
The current specs are not exhaustive, failing to find a number of bugs
in the gem.

Rewrite the specs to:

* test individual units rather than the gem as a whole at a high level

* clean up after themselves as much as possible

* have all data and setup for the specs in the spec files themselves

* test more scenarios

* draw attention to existing bugs that we're not fixing yet

* provide a more reliable basis to ensure the correct behaviour of
  future refactors

This commit also removes an unused private method from
Sinject::Container, discovered when it showed as uncovered in the spec
coverage report.

Co-authored-by: Tim Regener <Tim.Regener@sage.com>
  • Loading branch information
KevinBrowne and timlapluie authored Mar 7, 2024
1 parent 1bd4915 commit 5f83022
Show file tree
Hide file tree
Showing 8 changed files with 776 additions and 221 deletions.
6 changes: 0 additions & 6 deletions lib/sinject/container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,6 @@ def match?(contract, dependency)
return false
end

# this method is called to get a standard param type for comparison purposes
def param_type(type)
return :arg if type == :opt || type == :req
return :key if type == :keyreq || type == :key
end

def create_instance(item)
# check if a custom initializer block has been specified
if item.initialize_block != nil
Expand Down
37 changes: 37 additions & 0 deletions spec/sinject/class_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# frozen_string_literal: true

require 'spec_helper'
require 'sinject/container_item'
require 'sinject/container'
require 'sinject/class'

describe Class do
before { @original_container = Sinject::Container.instance }
after { Sinject::Container.instance = @original_container }

describe '.dependency' do
let(:container) { Sinject::Container.new }
let(:foo) { Class.new }
let(:bar) { Class.new }

before do
container.register(key: :foo, class: foo)
container.register(key: :bar, class: bar)
end

describe 'creates instance methods that' do
it 'have the names specified' do
expect(subject.instance_methods).not_to include(:foo, :bar)
subject.dependency :foo, :bar
expect(subject.instance_methods).to include(:foo, :bar)
end

it 'return the dependency registered with the same name in the container' do
subject.dependency :foo, :bar
instance = subject.new
expect(instance.foo).to be_an_instance_of(foo)
expect(instance.bar).to be_an_instance_of(bar)
end
end
end
end
Loading

0 comments on commit 5f83022

Please sign in to comment.