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:
parent
a930528c92
commit
346d7db032
2 changed files with 35 additions and 1 deletions
|
@ -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
34
spec/counter_spec.rb
Normal 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
|
Loading…
Reference in a new issue