|
8 | 8 | 'support',
|
9 | 9 | 'proxies.txt'
|
10 | 10 | ) }
|
11 |
| - let(:proxy) { ProxyManager::Proxy.new(['127.0.0.1:80', '127.0.0.1:8080']) } |
| 11 | + subject { ProxyManager::Proxy.new(['127.0.0.1:80', '127.0.0.1:8080']) } |
12 | 12 |
|
13 |
| - it 'should return list' do |
14 |
| - expect(proxy.list).to match_array list |
15 |
| - end |
16 |
| - |
17 |
| - context '#connectable' do |
18 |
| - it 'should response' do |
19 |
| - expect(proxy).to respond_to(:connectable?) |
20 |
| - end |
| 13 | + context '#get' do |
| 14 | + its(:get) { should be_a Array } |
21 | 15 |
|
22 |
| - it 'should receive array' do |
23 |
| - expect(proxy.connectable?(['google.com', 80])).to be_true |
| 16 | + it 'should return many proxies' do |
| 17 | + expect { subject.get(3) }.not_to raise_error |
24 | 18 | end
|
| 19 | + end |
25 | 20 |
|
26 |
| - it 'should receive string' do |
27 |
| - expect(proxy.connectable?('google.com:80')).to be_true |
28 |
| - end |
| 21 | + context '#get!' do |
| 22 | + it { should respond_to :get! } |
29 | 23 | end
|
30 | 24 |
|
31 |
| - context '#get' do |
32 |
| - it 'should response' do |
33 |
| - expect(proxy).to respond_to(:get) |
34 |
| - end |
| 25 | + context '#list' do |
| 26 | + its(:list) { should match_array list } |
| 27 | + end |
35 | 28 |
|
36 |
| - it 'should return array' do |
37 |
| - expect(proxy.get).to be_a Array |
| 29 | + context '::connectable' do |
| 30 | + it 'should receive array' do |
| 31 | + expect(ProxyManager::Proxy.connectable?(['127.0.0.1', 8080])).to be_false |
38 | 32 | end
|
39 | 33 |
|
40 |
| - it 'should return many proxies' do |
41 |
| - expect { proxy.get(3) }.not_to raise_error |
| 34 | + it 'should receive string' do |
| 35 | + expect(ProxyManager::Proxy.connectable?("127.0.0.1:8080")).to be_false |
42 | 36 | end
|
43 | 37 | end
|
44 | 38 |
|
45 | 39 | context 'when load from file' do
|
46 |
| - let(:proxy) { ProxyManager::Proxy.new(proxies_file) } |
| 40 | + subject { ProxyManager::Proxy.new(proxies_file) } |
47 | 41 |
|
48 |
| - it 'should return list' do |
49 |
| - expect(proxy.list).to match_array list |
50 |
| - end |
| 42 | + its(:list) { should match_array list } |
51 | 43 |
|
52 | 44 | context 'and save file' do
|
53 |
| - before { @source = File.read(proxies_file) } |
| 45 | + let(:source) { IO.read(proxies_file) } |
54 | 46 |
|
55 | 47 | it 'should update proxies source' do
|
56 |
| - proxy.get(2) |
| 48 | + subject.get(2) |
57 | 49 |
|
58 | 50 | source = ''
|
59 |
| - proxy.list.each_with_index do |p, index| |
60 |
| - source << "#{p[0]}:#{p[1]}" |
61 |
| - source << "\n" if proxy.list[index + 1] |
62 |
| - end |
| 51 | + subject.list.each { |p| source << "#{p[0]}:#{p[1]}\n" } |
| 52 | + source.sub!(/\n$/, '') |
63 | 53 |
|
64 |
| - expect(File.open(proxies_file, "rb").read).to eq(source) |
| 54 | + expect(IO.read(proxies_file)).to eq(source) |
65 | 55 | end
|
66 | 56 |
|
67 |
| - after do |
68 |
| - File.open(proxies_file, 'w').write(@source) |
69 |
| - end |
| 57 | + after { IO.write(proxies_file, source) } |
70 | 58 | end
|
71 | 59 | end
|
72 | 60 | end
|
0 commit comments