Skip to content

Commit

Permalink
Fix support for multiple arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
aldesantis committed Jul 15, 2018
1 parent f6899fe commit 6dc9ade
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 11 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## [0.2.1]

### Fixed

- Fixed support for multiple arguments

## [0.2.0]

### Added
Expand All @@ -18,5 +24,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
Initial release.

[Unreleased]: https://github.com/aldesantis/adaptor/compare/v0.2.0...HEAD
[0.2.1]: https://github.com/aldesantis/adaptor/compare/v0.2.0...v0.2.1
[0.2.0]: https://github.com/aldesantis/adaptor/compare/v0.1.0...v0.2.0
[0.1.0]: https://github.com/aldesantis/adaptor/tree/v0.1.0
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }

# Specify your gem's dependencies in adaptor.gemspec
gemspec

gem 'pry'
6 changes: 6 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ GEM
remote: https://rubygems.org/
specs:
ast (2.4.0)
coderay (1.1.2)
coveralls (0.8.22)
json (>= 1.8, < 3)
simplecov (~> 0.16.1)
Expand All @@ -17,10 +18,14 @@ GEM
docile (1.3.1)
jaro_winkler (1.5.1)
json (2.1.0)
method_source (0.9.0)
parallel (1.12.1)
parser (2.5.1.2)
ast (~> 2.4.0)
powerpack (0.1.2)
pry (0.11.3)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
rainbow (3.0.0)
rake (10.5.0)
rspec (3.7.0)
Expand Down Expand Up @@ -65,6 +70,7 @@ DEPENDENCIES
adaptor!
bundler (~> 1.16)
coveralls (~> 0.8)
pry
rake (~> 10.0)
rspec (~> 3.0)
rubocop (~> 0.52)
Expand Down
2 changes: 1 addition & 1 deletion lib/adaptor/loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def instantiate_adaptor(adaptor, args)

def cut_args(args, method:)
arity = method.arity
arity.negative? ? args : args[0..arity]
arity.negative? ? args : args[0..(arity - 1)]
end
end
end
Expand Down
14 changes: 7 additions & 7 deletions spec/adaptor/loader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,42 @@
describe '#load_adaptor' do
it 'loads the appropriate adaptor' do
expect([
subject.load_adaptor(1),
subject.load_adaptor(2)
subject.load_adaptor(1, foo: :bar),
subject.load_adaptor(2, foo: :bar)
]).to match([
an_instance_of(AdaptorTest::AdaptorOne),
an_instance_of(AdaptorTest::AdaptorTwo)
])
end

it 'returns nil when no adaptor is found' do
expect(subject.load_adaptor(3)).to eq(nil)
expect(subject.load_adaptor(3, foo: :bar)).to eq(nil)
end
end

describe '#load_adaptors' do
it 'loads the appropriate adaptor' do
expect(subject.load_adaptors(2)).to match([
expect(subject.load_adaptors(2, foo: :bar)).to match([
an_instance_of(AdaptorTest::AdaptorTwo),
an_instance_of(AdaptorTest::AdaptorMultipleOfTwo)
])
end

it 'returns an empty array when no adaptors are found' do
expect(subject.load_adaptors(3)).to eq([])
expect(subject.load_adaptors(3, foo: :bar)).to eq([])
end
end

describe '#load_adaptors!' do
it 'loads the appropriate adaptors' do
expect(subject.load_adaptors!(2)).to match([
expect(subject.load_adaptors!(2, foo: :bar)).to match([
an_instance_of(AdaptorTest::AdaptorTwo),
an_instance_of(AdaptorTest::AdaptorMultipleOfTwo)
])
end

it 'raises NoAdaptorError when no adaptors are found' do
expect { subject.load_adaptors!(3) }.to raise_error(Adaptor::NoAdaptorError)
expect { subject.load_adaptors!(3, foo: :bar) }.to raise_error(Adaptor::NoAdaptorError)
end
end
end
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Coveralls.wear!

require "bundler/setup"
require 'pry'
require "adaptor"

RSpec.configure do |config|
Expand Down
6 changes: 3 additions & 3 deletions spec/support/adaptor_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def self.supports?(val)
val == 1
end

def initialize(_val)
def initialize(_val, _options)
end
end

Expand All @@ -17,7 +17,7 @@ def self.supports?(val)
val == 2
end

def initialize(_val)
def initialize(_val, _options)
end
end

Expand All @@ -28,7 +28,7 @@ def self.supports?(val)
(val % 2).zero?
end

def initialize(_val)
def initialize(_val, _options)
end
end

Expand Down

0 comments on commit 6dc9ade

Please sign in to comment.