2022-06-16 11:21:40 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe Capybara::Server::Middleware::Counter do
|
2022-07-09 14:20:40 -04:00
|
|
|
let(:counter) { described_class.new }
|
2022-06-16 11:21:40 -04:00
|
|
|
let(:uri) { '/example' }
|
|
|
|
|
2022-07-09 14:20:40 -04:00
|
|
|
describe '#increment' do
|
2022-06-16 11:21:40 -04:00
|
|
|
it 'successfully' do
|
|
|
|
counter.increment(uri)
|
2022-07-09 14:20:40 -04:00
|
|
|
expect(counter).to be_positive
|
2022-06-16 11:21:40 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-09 14:20:40 -04:00
|
|
|
describe '#decrement' do
|
2022-06-16 11:21:40 -04:00
|
|
|
before do
|
|
|
|
counter.increment(uri)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'successfully' do
|
|
|
|
it 'with same uri' do
|
2022-07-09 14:20:40 -04:00
|
|
|
expect(counter).to be_positive
|
2022-06-16 11:21:40 -04:00
|
|
|
counter.decrement(uri)
|
2022-07-09 14:20:40 -04:00
|
|
|
expect(counter).not_to be_positive
|
2022-06-16 11:21:40 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'with changed uri' do
|
2022-07-09 14:20:40 -04:00
|
|
|
expect(counter).to be_positive
|
2022-06-16 11:21:40 -04:00
|
|
|
counter.decrement('/')
|
2022-07-09 14:20:40 -04:00
|
|
|
expect(counter).not_to be_positive
|
2022-06-16 11:21:40 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|