Skip to content

Commit

Permalink
Merge pull request #83 from TamarinEA/master
Browse files Browse the repository at this point in the history
test: stub class method when check process
  • Loading branch information
isqad authored Oct 1, 2019
2 parents d843766 + 8fd7efe commit 974e840
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
22 changes: 12 additions & 10 deletions spec/lib/treasury/processors/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -449,16 +449,16 @@ def form_value(value)
end

context 'если есть батч' do
context 'и батч не пустой' do
before do
allow(ActiveRecord::Base).to receive(:pgq_next_batch).and_return(BATCH_ID)
allow(subject).to receive(:process_events_batch) do |events|
data = subject.instance_variable_get(:@data)
subject.instance_variable_set(:@data, data.merge(events.inject({}) { |r, id| r.merge(id => 1) }))
end
subject.instance_variable_set(:@events_batches, EVENTS_BATCHES_TEST)
before do
allow(ActiveRecord::Base).to receive(:pgq_next_batch).and_return(BATCH_ID)
allow(subject).to receive(:process_events_batch) do |events|
data = subject.instance_variable_get(:@data)
subject.instance_variable_set(:@data, data.merge(events.inject({}) { |r, id| r.merge(id => 1) }))
end
subject.instance_variable_set(:@events_batches, EVENTS_BATCHES_TEST)
end

context 'и батч не пустой' do
context 'when called' do
let(:storages) { [double('storage1'), double('storage2')] }

Expand Down Expand Up @@ -497,14 +497,16 @@ def form_value(value)
end
end

context 'и батч не пустой', pending: 'unimplemented' do
context 'и батч не пустой' do
before { allow(subject).to receive(:finish_batch) }

it 'то для каждого батча должен быть вызван метод обработки' do
EVENTS_BATCHES_TEST.each { |batch| subject.should_receive(:process_events_batch).with(batch) }
subject.process
end

it 'метод должен вернуть корректное кол-во обработанных событий' do
subject.process.should == {:events_processed => EVENTS_BATCHES_TEST.size, :rows_written => 0}
subject.process.should == {events_processed: EVENTS_BATCHES_TEST.flatten.size, rows_written: 5}
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/treasury/supervisor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
let(:supervisor) { described_class.new(supervisor_status) }

describe '#run_initializers' do
before { allow(supervisor).to receive(:process_is_alive?).and_return(false) }
before { allow(supervisor.class).to receive(:process_is_alive?).and_return(false) }

after { supervisor.send(:run_initializers) }

Expand Down

0 comments on commit 974e840

Please sign in to comment.