Skip to content

Commit

Permalink
Improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriprat committed Jul 4, 2015
1 parent aaf74a0 commit 084ec91
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
27 changes: 24 additions & 3 deletions spec/resque_delay/performable_method_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ def played?
pm = ResqueDelay::PerformableMethod.new(klass, :to_s, [], nil, nil)
expect(pm.display_name).to eq('Fixnum.to_s')
end
it 'prints Unknowns' do
pm = ResqueDelay::PerformableMethod.new("I'm not exptected", :to_s, [], nil, nil)
expect(pm.display_name).to eq('Unknown#to_s')
end
end

describe '.load' do
Expand All @@ -103,23 +107,40 @@ def played?
pm = ResqueDelay::PerformableMethod.new(klass, :to_s, [], nil, nil)
expect(pm.send(:load, klass_key)).to eq(klass)
end
it 'loads other' do
obj = 'hello'
pm = ResqueDelay::PerformableMethod.new(klass, :to_s, [], nil, nil)
expect(pm.send(:load, obj)).to eq(obj)
end
end

describe '.perform' do
it 'execute the method' do
it 'executes AR methods' do
pm = ResqueDelay::PerformableMethod.new(ar, :play, [], nil, nil)
expect(ar).to receive(:play)
pm.perform
end
it 'loads DMs' do
it 'executes DM methods' do
pm = ResqueDelay::PerformableMethod.new(dm, :play, [], nil, nil)
expect(dm).to receive(:play)
pm.perform
end
it 'loads Classes' do
it 'executes Class methods' do
pm = ResqueDelay::PerformableMethod.new(klass, :to_s, [], nil, nil)
expect(klass).to receive(:to_s)
pm.perform
end
it 'eats ActiveRecord::NotFound exceptions' do
pm = ResqueDelay::PerformableMethod.new(ar, :play, [], nil, nil)
expect(ar).to receive(:play).and_raise(ActiveRecord::RecordNotFound)
pm.perform
end
it 'does NOT eat exceptions other than ActiveRecord::NotFound' do
expect do
pm = ResqueDelay::PerformableMethod.new(ar, :play, [], nil, nil)
expect(ar).to receive(:play).and_raise(::RuntimeError)
pm.perform
end.to raise_error(::RuntimeError)
end
end
end
11 changes: 9 additions & 2 deletions spec/resque_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,15 @@ def tell
it 'fails if in option is not valid' do
expect do
job = FairyTail.delay(in: 'I will fail').to_s
end.to raise_error { ::ArgumentError }
end.to raise_error(::ArgumentError)
end
end

describe 'self.perform' do
it 'sends perform with a hash' do
obj = "hello"
expect(obj).to receive(:to_s)
ResqueDelay::DelayProxy.perform({ 'object' => obj, 'method' => :to_s, 'args' => []})
end

end
end

0 comments on commit 084ec91

Please sign in to comment.