Skip to content

Commit f4e9846

Browse files
author
Kirill Platonov
committed
clean up tests and remove all comments from code
1 parent 554a2a4 commit f4e9846

File tree

3 files changed

+24
-48
lines changed

3 files changed

+24
-48
lines changed

lib/proxy_manager.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
require 'net/ping'
33

44
module ProxyManager
5-
# Define gem's root path
6-
# @return [String] string path
75
def self.root
86
File.expand_path '../..', __FILE__
97
end

lib/proxy_manager/proxy.rb

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,6 @@ module ProxyManager
22
class Proxy
33
attr_reader :list
44

5-
# Create main object
6-
# @param proxies [Array, String] array of proxies or file with proxies
7-
# @example
8-
# # from array
9-
# proxy = ProxyManager::Proxy.new(['127.0.0.1:80', '127.0.0.1:8080'])
10-
#
11-
# # or from file
12-
# proxy = ProxyManager::Proxy.new('proxies.txt')
13-
# @return [Class] Main object
14-
# @see Main
155
def initialize(proxies)
166
@list = []
177

spec/proxy_manager/proxy_spec.rb

Lines changed: 24 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,65 +8,53 @@
88
'support',
99
'proxies.txt'
1010
) }
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']) }
1212

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 }
2115

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
2418
end
19+
end
2520

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! }
2923
end
3024

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
3528

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
3832
end
3933

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
4236
end
4337
end
4438

4539
context 'when load from file' do
46-
let(:proxy) { ProxyManager::Proxy.new(proxies_file) }
40+
subject { ProxyManager::Proxy.new(proxies_file) }
4741

48-
it 'should return list' do
49-
expect(proxy.list).to match_array list
50-
end
42+
its(:list) { should match_array list }
5143

5244
context 'and save file' do
53-
before { @source = File.read(proxies_file) }
45+
let(:source) { IO.read(proxies_file) }
5446

5547
it 'should update proxies source' do
56-
proxy.get(2)
48+
subject.get(2)
5749

5850
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$/, '')
6353

64-
expect(File.open(proxies_file, "rb").read).to eq(source)
54+
expect(IO.read(proxies_file)).to eq(source)
6555
end
6656

67-
after do
68-
File.open(proxies_file, 'w').write(@source)
69-
end
57+
after { IO.write(proxies_file, source) }
7058
end
7159
end
7260
end

0 commit comments

Comments
 (0)