/
slow_web_spec.rb
38 lines (31 loc) · 1.16 KB
/
slow_web_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
require File.join(File.dirname(File.expand_path(__FILE__)), 'spec_helper')
describe SlowWeb do
##############################################################################
# Setup
##############################################################################
before do
SlowWeb.reset
end
##############################################################################
# Tests
##############################################################################
it 'should add limit' do
SlowWeb.limit('github.com', 10, 60)
limit = SlowWeb.get_limit('github.com');
limit.host.should == 'github.com'
limit.count.should == 10
limit.period.should == 60
end
it 'should error when limiting the same host twice' do
SlowWeb.limit('github.com', 10, 60)
lambda {SlowWeb.limit('github.com', 10, 60)}.should raise_error('Limit already exists for this host: github.com')
end
it 'should show limit exceeded' do
SlowWeb.limit('github.com', 3, 60)
limit = SlowWeb.get_limit('github.com');
limit.add_request({})
limit.add_request({})
limit.add_request({})
SlowWeb.limit_exceeded?('github.com').should be_true
end
end