1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00

Fix wrong counter behavior with changed uri

This commit is contained in:
alex-konoval 2022-06-16 18:21:40 +03:00
parent a930528c92
commit 346d7db032
2 changed files with 35 additions and 1 deletions

View file

@ -14,7 +14,7 @@ module Capybara
end
def decrement(uri)
@mutex.synchronize { @value.delete_at(@value.index(uri) || @value.length) }
@mutex.synchronize { @value.delete_at(@value.index(uri) || @value.length - 1) }
end
def positive?

34
spec/counter_spec.rb Normal file
View file

@ -0,0 +1,34 @@
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Capybara::Server::Middleware::Counter do
let(:counter) { Capybara::Server::Middleware::Counter.new }
let(:uri) { '/example' }
context '#increment' do
it 'successfully' do
counter.increment(uri)
expect(counter.positive?).to be true
end
end
context 'decrement' do
before do
counter.increment(uri)
expect(counter.positive?).to be true
end
context 'successfully' do
it 'with same uri' do
counter.decrement(uri)
expect(counter.positive?).to be false
end
it 'with changed uri' do
counter.decrement('/')
expect(counter.positive?).to be false
end
end
end
end