Skip to content

Commit

Permalink
fixing specs
Browse files Browse the repository at this point in the history
  • Loading branch information
mokus80 committed Dec 15, 2023
1 parent 03d6057 commit af5e301
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
2 changes: 1 addition & 1 deletion lib/delayed/performable_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Delayed
class PerformableMethod
attr_accessor :object, :method_name, :args, :kwargs

def initialize(object, method_name, *args, **kwargs)
def initialize(object, method_name, args, kwargs = {})
raise NoMethodError, "undefined method `#{method_name}' for #{object.inspect}" unless object.respond_to?(method_name, true)

if object.respond_to?(:persisted?) && !object.persisted?
Expand Down
38 changes: 20 additions & 18 deletions spec/performable_method_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
end
end

describe 'perform with positional argument' do
describe 'perform with hash object' do
before do
@method = Delayed::PerformableMethod.new('foo', :count, {:o => true})
@method = Delayed::PerformableMethod.new('foo', :count, [], {:o => true})
end

it 'calls the method on the object' do
Expand All @@ -34,20 +34,22 @@
end
end

describe 'perform with positional argument and kwargs' do
before do
@method = Delayed::PerformableMethod.new('foo', :count, {:o => true}, :o2 => false)
end
# I do not think this spec case is needed with Ruby 3

it 'calls the method on the object' do
expect(@method.object).to receive(:count).with({:o => true}, :o2 => false)
@method.perform
end
end
# describe 'perform with positional argument and kwargs' do
# before do
# @method = Delayed::PerformableMethod.new('foo', :count, {:o => true}, :o2 => false)
# end

# it 'calls the method on the object' do
# expect(@method.object).to receive(:count).with({:o => true}, :o2 => false)
# @method.perform
# end
# end

describe 'perform with postional hash argument' do
before do
@method = Delayed::PerformableMethod.new('foo', :count, { :o => true, :o2 => true })
@method = Delayed::PerformableMethod.new('foo', :count, [], { :o => true, :o2 => true })
end

it 'calls the method on the object' do
Expand Down Expand Up @@ -92,7 +94,7 @@ def test_method(_o1, _o2)
end

it 'calls the method on the object' do
expect(@method.object).to receive(:test_method).with(['o', @params])
expect(@method.object).to receive(:test_method).with('o', @params)
@method.perform
end

Expand All @@ -102,13 +104,13 @@ def test_method(_o1, _o2)
end
end

describe 'perform with sample object and hash object' do
describe 'perform with args and kwargs' do
before do
@method = Delayed::PerformableMethod.new('foo', :count, ['o', {:o => true}])
@method = Delayed::PerformableMethod.new('foo', :count, 'o', {:o => true})
end

it 'calls the method on the object' do
expect(@method.object).to receive(:count).with(['o', :o => true])
expect(@method.object).to receive(:count).with('o', :o => true)
@method.perform
end
end
Expand All @@ -121,11 +123,11 @@ def test_method(name:, any:)
end
end

@method = Delayed::PerformableMethod.new(klass.new, :test_method, [], :name => 'name', :any => 'any')
@method = Delayed::PerformableMethod.new(klass.new, :test_method, [], {:name => 'name', :any => 'any'})
end

it 'calls the method on the object' do
expect(@method.object).to receive(:test_method).with([], :name => 'name', :any => 'any')
expect(@method.object).to receive(:test_method).with({:name => 'name', :any => 'any'})
@method.perform
end

Expand Down

0 comments on commit af5e301

Please sign in to comment.