locasms 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +6 -0
- data/.rubocop_todo.yml +30 -0
- data/.travis.yml +11 -4
- data/Gemfile +2 -0
- data/Guardfile +4 -2
- data/README.md +1 -1
- data/Rakefile +3 -1
- data/bin/console +2 -0
- data/lib/locasms.rb +4 -0
- data/lib/locasms/client.rb +22 -17
- data/lib/locasms/exception.rb +7 -7
- data/lib/locasms/helpers/date_time_helper.rb +38 -69
- data/lib/locasms/numbers.rb +14 -12
- data/lib/locasms/rest_client.rb +21 -13
- data/lib/locasms/version.rb +3 -1
- data/locasms.gemspec +25 -20
- data/spec/lib/locasms/client_spec.rb +96 -138
- data/spec/lib/locasms/helpers/date_time_helper_spec.rb +11 -35
- data/spec/lib/locasms/numbers_spec.rb +54 -68
- data/spec/lib/locasms/rest_client_spec.rb +43 -31
- data/spec/spec_helper.rb +5 -4
- metadata +50 -22
- data/.ruby-style.yml +0 -1063
data/lib/locasms/version.rb
CHANGED
data/locasms.gemspec
CHANGED
@@ -1,39 +1,44 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require 'locasms/version'
|
5
6
|
|
6
7
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
8
|
+
spec.name = 'locasms'
|
8
9
|
spec.version = LocaSMS::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
11
|
-
spec.description =
|
12
|
-
versão para Short Code SMS (SMS Plataforma)
|
13
|
-
spec.summary =
|
14
|
-
spec.homepage =
|
15
|
-
spec.license =
|
16
|
-
|
17
|
-
spec.files = `git ls-files`.split(
|
10
|
+
spec.authors = ['Adilson Carvalho', 'Leonardo Saraiva', 'Marco Carvalho']
|
11
|
+
spec.email = ['lc.adilson@gmail.com', 'vyper@maneh.org', 'marco.carvalho.swasthya@gmail.com']
|
12
|
+
spec.description = 'Cliente para o serviço de disparo de SMS da LocaSMS e de sua
|
13
|
+
versão para Short Code SMS (SMS Plataforma)'
|
14
|
+
spec.summary = 'Cliente para disparo de SMS, regular e Short Code, através da LocaSMS/SMS Plataforma'
|
15
|
+
spec.homepage = 'https://github.com/mcorp/locasms'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
18
19
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
20
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
-
spec.require_paths = [
|
21
|
+
spec.require_paths = ['lib']
|
21
22
|
|
22
|
-
spec.required_ruby_version = '~> 2.
|
23
|
+
spec.required_ruby_version = '~> 2.4'
|
23
24
|
|
24
|
-
spec.add_dependency 'multi_json', '~> 1.
|
25
|
+
spec.add_dependency 'multi_json', '~> 1.13'
|
25
26
|
|
26
|
-
spec.add_development_dependency 'bundler'
|
27
|
-
spec.add_development_dependency 'rake', '~>
|
27
|
+
spec.add_development_dependency 'bundler'
|
28
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
28
29
|
|
29
30
|
# test stuff
|
30
|
-
spec.add_development_dependency 'rspec', '~> 3.
|
31
|
+
spec.add_development_dependency 'rspec', '~> 3.9'
|
31
32
|
spec.add_development_dependency 'timecop', '~> 0.9'
|
32
33
|
|
33
34
|
# for documentation
|
35
|
+
spec.add_development_dependency 'redcarpet', '~> 3.5'
|
34
36
|
spec.add_development_dependency 'yard', '~> 0.9'
|
35
|
-
spec.add_development_dependency 'redcarpet', '~> 3.4'
|
36
37
|
|
37
38
|
# for code coverage
|
38
|
-
spec.add_development_dependency 'simplecov', '~> 0.
|
39
|
+
spec.add_development_dependency 'simplecov', '~> 0.18'
|
40
|
+
|
41
|
+
# for code quality
|
42
|
+
spec.add_development_dependency 'rubocop', '~> 0.93'
|
43
|
+
spec.add_development_dependency 'rubocop-rspec', '~> 1.43'
|
39
44
|
end
|
@@ -1,188 +1,148 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
|
-
describe LocaSMS::Client do
|
4
|
-
|
5
|
-
|
5
|
+
describe LocaSMS::Client do # rubocop:disable RSpec/FilePath
|
6
|
+
subject(:client) { described_class.new :login, :password, rest_client: rest_client, callback: nil }
|
7
|
+
|
8
|
+
let(:rest_client) { instance_double 'RestClient' }
|
9
|
+
let(:base_args) { { msg: 'given message', numbers: '11988889991,11988889992,11988889993' } }
|
10
|
+
let(:default_callback_args) { base_args.merge(url_callback: 'default') }
|
11
|
+
let(:some_callback_args) { base_args.merge(url_callback: 'something') }
|
6
12
|
|
7
13
|
describe '::ENDPOINT' do
|
8
|
-
let(:domain) {
|
14
|
+
let(:domain) { described_class::DOMAIN }
|
9
15
|
|
10
|
-
context '
|
11
|
-
it '
|
12
|
-
endpoint =
|
16
|
+
context 'when default' do
|
17
|
+
it 'returns the default URL' do
|
18
|
+
endpoint = described_class::ENDPOINT[client.type]
|
13
19
|
expect(endpoint).to eq("http://#{domain}/painel/api.ashx")
|
14
20
|
end
|
15
21
|
end
|
16
22
|
|
17
|
-
context '
|
18
|
-
subject {
|
23
|
+
context 'when shortcode' do
|
24
|
+
subject(:client) { described_class.new :login, :password, type: :shortcode }
|
19
25
|
|
20
|
-
it '
|
21
|
-
endpoint =
|
26
|
+
it 'returns the short code URL' do
|
27
|
+
endpoint = described_class::ENDPOINT[client.type]
|
22
28
|
expect(endpoint).to eq("http://#{domain}/shortcode/api.ashx")
|
23
29
|
end
|
24
30
|
end
|
25
31
|
end
|
26
32
|
|
27
33
|
describe '.initialize' do
|
28
|
-
it { expect(
|
29
|
-
it { expect(
|
34
|
+
it { expect(client.login).to be(:login) }
|
35
|
+
it { expect(client.password).to be(:password) }
|
30
36
|
end
|
31
37
|
|
32
38
|
describe '#deliver' do
|
33
|
-
it '
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
expect(rest_client).to receive(:get)
|
40
|
-
.once
|
41
|
-
.with(:sendsms, msg: 'given message', numbers:'XXX', url_callback: nil)
|
42
|
-
.and_return({})
|
43
|
-
|
44
|
-
subject.deliver 'given message', :a, :b, :c
|
39
|
+
it 'sends SMS' do
|
40
|
+
allow(rest_client).to receive(:get).and_return({})
|
41
|
+
|
42
|
+
client.deliver 'given message', '11988889991', '11988889992', '11988889993'
|
43
|
+
|
44
|
+
expect(rest_client).to have_received(:get).once.with(:sendsms, base_args.merge(url_callback: nil))
|
45
45
|
end
|
46
46
|
|
47
|
-
|
48
|
-
|
49
|
-
.once
|
50
|
-
.with([:a, :b, :c])
|
51
|
-
.and_raise(LocaSMS::Exception)
|
47
|
+
context 'when receive an error' do
|
48
|
+
let(:wrong_deliver) { -> { client.deliver('given message', '1', '2', '3') } }
|
52
49
|
|
53
|
-
expect(
|
50
|
+
it { expect(wrong_deliver).to raise_error(LocaSMS::Exception) }
|
54
51
|
|
55
|
-
|
52
|
+
it 'does not send SMS' do
|
53
|
+
allow(rest_client).to receive(:get)
|
54
|
+
|
55
|
+
wrong_deliver
|
56
|
+
|
57
|
+
expect(rest_client).not_to have_received(:get)
|
58
|
+
end
|
56
59
|
end
|
57
60
|
|
58
|
-
context '
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
expect(rest_client).to receive(:get)
|
67
|
-
.once
|
68
|
-
.with(:sendsms, msg: 'given message', numbers:'XXX', url_callback: 'something')
|
69
|
-
.and_return({})
|
70
|
-
|
71
|
-
subject.deliver 'given message', :a, :b, :c, url_callback: 'something'
|
72
|
-
end
|
61
|
+
context 'when callback given as arg to #deliver' do
|
62
|
+
it 'uses specific callback' do
|
63
|
+
allow(rest_client).to receive(:get).and_return({})
|
64
|
+
|
65
|
+
client.deliver 'given message', '11988889991', '11988889992', '11988889993', url_callback: 'something'
|
66
|
+
|
67
|
+
expect(rest_client).to have_received(:get).once.with(:sendsms, some_callback_args)
|
73
68
|
end
|
69
|
+
end
|
74
70
|
|
75
|
-
|
76
|
-
|
71
|
+
it 'uses default callback' do
|
72
|
+
client = described_class.new :login, :password, rest_client: rest_client, url_callback: 'default'
|
77
73
|
|
78
|
-
|
79
|
-
.once
|
80
|
-
.with([:a, :b, :c])
|
81
|
-
.and_return('XXX')
|
74
|
+
allow(rest_client).to receive(:get).and_return({})
|
82
75
|
|
83
|
-
|
84
|
-
.once
|
85
|
-
.with(:sendsms, msg: 'given message', numbers:'XXX', url_callback: 'default')
|
86
|
-
.and_return({})
|
76
|
+
client.deliver 'given message', '11988889991', '11988889992', '11988889993'
|
87
77
|
|
88
|
-
|
89
|
-
end
|
78
|
+
expect(rest_client).to have_received(:get).once.with(:sendsms, default_callback_args)
|
90
79
|
end
|
91
80
|
end
|
92
81
|
|
93
82
|
describe '#deliver_at' do
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
.once
|
102
|
-
.with(:datetime)
|
103
|
-
.and_return(%w[date time])
|
104
|
-
|
105
|
-
expect(rest_client).to receive(:get)
|
106
|
-
.once
|
107
|
-
.with(:sendsms, msg: 'given message', numbers:'XXX', jobdate: 'date', jobtime: 'time', url_callback: nil)
|
108
|
-
.and_return({})
|
109
|
-
|
110
|
-
subject.deliver_at 'given message', :datetime, :a, :b, :c
|
83
|
+
let(:base_args) do
|
84
|
+
{
|
85
|
+
msg: 'given message',
|
86
|
+
numbers: '11988889991,11988889992,11988889993',
|
87
|
+
jobdate: '10/10/2020',
|
88
|
+
jobtime: '10:10'
|
89
|
+
}
|
111
90
|
end
|
112
91
|
|
113
|
-
it '
|
114
|
-
|
115
|
-
.once
|
116
|
-
.with([:a, :b, :c])
|
117
|
-
.and_raise(LocaSMS::Exception)
|
92
|
+
it 'sends SMS' do
|
93
|
+
allow(rest_client).to receive(:get).and_return({})
|
118
94
|
|
119
|
-
|
120
|
-
.once
|
121
|
-
.with(:datetime)
|
122
|
-
.and_return(%w[date time])
|
95
|
+
client.deliver_at 'given message', '2020-10-10 10:10', '11988889991', '11988889992', '11988889993'
|
123
96
|
|
124
|
-
expect(rest_client).to
|
97
|
+
expect(rest_client).to have_received(:get).once.with(:sendsms, base_args.merge(url_callback: nil))
|
98
|
+
end
|
99
|
+
|
100
|
+
context 'when receive an error' do
|
101
|
+
let(:wrong_deliver_at) { -> { client.deliver_at('given message', '2020-10-10 10:10', '1', '2', '3') } }
|
102
|
+
|
103
|
+
it { expect(wrong_deliver_at).to raise_error(LocaSMS::Exception) }
|
125
104
|
|
126
|
-
|
105
|
+
it 'does not send SMS' do
|
106
|
+
allow(rest_client).to receive(:get)
|
107
|
+
|
108
|
+
wrong_deliver_at
|
109
|
+
|
110
|
+
expect(rest_client).not_to have_received(:get)
|
111
|
+
end
|
127
112
|
end
|
128
113
|
|
129
114
|
context 'with callback option' do
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
expect(LocaSMS::Helpers::DateTimeHelper).to receive(:split)
|
138
|
-
.once
|
139
|
-
.with(:datetime)
|
140
|
-
.and_return(%w[date time])
|
141
|
-
|
142
|
-
expect(rest_client).to receive(:get)
|
143
|
-
.once
|
144
|
-
.with(:sendsms, msg: 'given message', numbers:'XXX', jobdate: 'date', jobtime: 'time', url_callback: 'something')
|
145
|
-
.and_return({})
|
146
|
-
|
147
|
-
subject.deliver_at 'given message', :datetime, :a, :b, :c, url_callback: 'something'
|
148
|
-
end
|
115
|
+
it 'when callback given as arg to #deliver' do
|
116
|
+
allow(rest_client).to receive(:get).and_return({})
|
117
|
+
|
118
|
+
client.deliver_at 'given message', '2020-10-10 10:10', '11988889991', '11988889992', '11988889993', url_callback: 'something'
|
119
|
+
|
120
|
+
expect(rest_client).to have_received(:get).once.with(:sendsms, some_callback_args)
|
149
121
|
end
|
150
122
|
|
151
123
|
it 'uses default callback' do
|
152
|
-
client =
|
153
|
-
|
154
|
-
expect(client).to receive(:numbers)
|
155
|
-
.once
|
156
|
-
.with([:a, :b, :c])
|
157
|
-
.and_return('XXX')
|
124
|
+
client = described_class.new :login, :password, rest_client: rest_client, url_callback: 'default'
|
158
125
|
|
159
|
-
|
160
|
-
.once
|
161
|
-
.with(:datetime)
|
162
|
-
.and_return(%w[date time])
|
126
|
+
allow(rest_client).to receive(:get).and_return({})
|
163
127
|
|
164
|
-
|
165
|
-
.once
|
166
|
-
.with(:sendsms, msg: 'given message', numbers:'XXX', jobdate: 'date', jobtime: 'time', url_callback: 'default')
|
167
|
-
.and_return({})
|
128
|
+
client.deliver_at 'given message', '2020-10-10 10:10', '11988889991', '11988889992', '11988889993'
|
168
129
|
|
169
|
-
|
130
|
+
expect(rest_client).to have_received(:get).once.with(:sendsms, default_callback_args)
|
170
131
|
end
|
171
132
|
end
|
172
133
|
end
|
173
134
|
|
174
135
|
describe '#balance' do
|
175
|
-
it '
|
176
|
-
|
177
|
-
.once
|
178
|
-
.with(:getbalance)
|
179
|
-
.and_return({})
|
136
|
+
it 'checks param assignment' do
|
137
|
+
allow(rest_client).to receive(:get).and_return({})
|
180
138
|
|
181
|
-
|
139
|
+
client.balance
|
140
|
+
|
141
|
+
expect(rest_client).to have_received(:get).once.with(:getbalance)
|
182
142
|
end
|
183
143
|
end
|
184
144
|
|
185
|
-
context '
|
145
|
+
context 'when receive all campaign based methods' do
|
186
146
|
def check_for(method)
|
187
147
|
rest_method = {
|
188
148
|
campaign_status: :getstatus,
|
@@ -190,19 +150,17 @@ describe LocaSMS::Client do
|
|
190
150
|
campaign_release: :releasesms
|
191
151
|
}[method]
|
192
152
|
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
.and_return({})
|
153
|
+
allow(rest_client).to receive(:get).and_return({})
|
154
|
+
|
155
|
+
client.send method, '12345'
|
197
156
|
|
198
|
-
|
157
|
+
expect(rest_client).to have_received(:get).once.with(rest_method, id: '12345')
|
199
158
|
end
|
200
159
|
|
201
|
-
it{ check_for :campaign_status }
|
202
|
-
it{ check_for :campaign_hold }
|
203
|
-
it{ check_for :campaign_release }
|
160
|
+
it { check_for :campaign_status }
|
161
|
+
it { check_for :campaign_hold }
|
162
|
+
it { check_for :campaign_release }
|
204
163
|
|
205
|
-
it '
|
164
|
+
it 'has tests to cover campaign_status csv result'
|
206
165
|
end
|
207
|
-
|
208
166
|
end
|
@@ -1,50 +1,26 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
describe LocaSMS::Helpers::DateTimeHelper do
|
4
|
-
subject { LocaSMS::Helpers::DateTimeHelper }
|
5
|
-
|
6
|
-
describe '#parse' do
|
7
|
-
it 'Should call the class method' do
|
8
|
-
expect(subject).to receive(:parse)
|
9
|
-
.once
|
10
|
-
.with(:value)
|
11
|
-
|
12
|
-
subject.new.parse(:value)
|
13
|
-
end
|
14
|
-
end
|
1
|
+
# frozen_string_literal: true
|
15
2
|
|
16
|
-
|
17
|
-
it 'Should call the class method' do
|
18
|
-
expect(subject).to receive(:split)
|
19
|
-
.once
|
20
|
-
.with(:value)
|
3
|
+
require 'spec_helper'
|
21
4
|
|
22
|
-
|
23
|
-
|
24
|
-
end
|
5
|
+
describe LocaSMS::Helpers::DateTimeHelper do # rubocop:disable RSpec/FilePath
|
6
|
+
subject(:helper) { described_class }
|
25
7
|
|
26
8
|
describe '.parse' do
|
27
9
|
let(:expected) { Time.parse '1977-03-14 14:12:00' }
|
28
10
|
|
29
11
|
def try_for(value)
|
30
|
-
|
12
|
+
helper.parse(value) == expected
|
31
13
|
end
|
32
14
|
|
33
15
|
it { try_for DateTime.parse('1977-03-14 14:12:00') }
|
34
|
-
it { try_for Time.parse('1977-03-14 14:12:00')
|
35
|
-
it { try_for '1977-03-14 14:12:00'
|
36
|
-
it { try_for
|
16
|
+
it { try_for Time.parse('1977-03-14 14:12:00') }
|
17
|
+
it { try_for '1977-03-14 14:12:00' }
|
18
|
+
it { try_for 227_207_520 }
|
37
19
|
end
|
38
20
|
|
39
21
|
describe '.split' do
|
40
|
-
it '
|
41
|
-
expect(
|
42
|
-
.once
|
43
|
-
.with(:datetime)
|
44
|
-
.and_return(Time.parse('1977-03-14 14:12:00'))
|
45
|
-
|
46
|
-
expect(subject.split(:datetime)).to eq(%w(14/03/1977 14:12))
|
22
|
+
it 'breaks a date into date and time' do
|
23
|
+
expect(helper.split('1977-03-14 14:12:00')).to eq(%w[14/03/1977 14:12])
|
47
24
|
end
|
48
25
|
end
|
49
|
-
|
50
|
-
end
|
26
|
+
end
|
@@ -1,106 +1,92 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
|
-
describe LocaSMS::Numbers do
|
4
|
-
subject {
|
5
|
-
|
6
|
-
describe '.initialize' do
|
7
|
-
subject do
|
8
|
-
expect_any_instance_of(LocaSMS::Numbers).
|
9
|
-
to receive(:evaluate).
|
10
|
-
once.
|
11
|
-
with([:numbers]).
|
12
|
-
and_return(good: [1, 3], bad: [2, 4])
|
13
|
-
LocaSMS::Numbers.new :numbers
|
14
|
-
end
|
5
|
+
describe LocaSMS::Numbers do # rubocop:disable RSpec/FilePath
|
6
|
+
subject(:number_sanitizer) { described_class.new numbers }
|
15
7
|
|
16
|
-
|
17
|
-
it { expect(subject.bad).to eq([2, 4]) }
|
18
|
-
end
|
8
|
+
let(:numbers) { '1188889999' }
|
19
9
|
|
20
10
|
describe '#normalize' do
|
21
|
-
it do
|
22
|
-
expect(
|
23
|
-
eq(%w
|
11
|
+
it do
|
12
|
+
expect(number_sanitizer.normalize('+55 (11) 8888-9999')).to(
|
13
|
+
eq(%w[551188889999])
|
24
14
|
)
|
25
15
|
end
|
16
|
+
|
26
17
|
it do
|
27
|
-
expect(
|
28
|
-
eq(%w
|
18
|
+
expect(number_sanitizer.normalize('55', %w[11 22])).to(
|
19
|
+
eq(%w[55 11 22])
|
29
20
|
)
|
30
21
|
end
|
22
|
+
|
31
23
|
it do
|
32
|
-
expect(
|
33
|
-
eq(%w
|
24
|
+
expect(number_sanitizer.normalize(%w[55 ZZ 22])).to(
|
25
|
+
eq(%w[55 ZZ 22])
|
34
26
|
)
|
35
27
|
end
|
28
|
+
|
36
29
|
it do
|
37
|
-
expect(
|
38
|
-
eq(%w
|
30
|
+
expect(number_sanitizer.normalize('55,44,33', ['ZZ', '22,11'])).to(
|
31
|
+
eq(%w[55 44 33 ZZ 22 11])
|
39
32
|
)
|
40
33
|
end
|
41
|
-
|
42
|
-
|
43
|
-
|
34
|
+
|
35
|
+
it do
|
36
|
+
expect(number_sanitizer.normalize(55, [11, 22])).to(
|
37
|
+
eq(%w[55 11 22])
|
44
38
|
)
|
45
39
|
end
|
46
|
-
|
47
|
-
it { expect(
|
40
|
+
|
41
|
+
it { expect(number_sanitizer.normalize('Z')).to eq(['Z']) }
|
42
|
+
it { expect(number_sanitizer.normalize(nil)).to eq([]) }
|
48
43
|
end
|
49
44
|
|
50
45
|
describe '#valid_number?' do
|
51
|
-
it {
|
52
|
-
it {
|
53
|
-
it {
|
54
|
-
it {
|
55
|
-
it {
|
56
|
-
it {
|
57
|
-
|
58
|
-
it {
|
59
|
-
it {
|
46
|
+
it { is_expected.not_to be_valid_number('+55 (11) 8888-9999') }
|
47
|
+
it { is_expected.not_to be_valid_number('88889999') }
|
48
|
+
it { is_expected.not_to be_valid_number('988889999') }
|
49
|
+
it { is_expected.not_to be_valid_number('ABC') }
|
50
|
+
it { is_expected.not_to be_valid_number('') }
|
51
|
+
it { is_expected.not_to be_valid_number(nil) }
|
52
|
+
|
53
|
+
it { is_expected.to be_valid_number('1188889999') }
|
54
|
+
it { is_expected.to be_valid_number('11988889999') }
|
60
55
|
end
|
61
56
|
|
62
57
|
describe '#evaluate' do
|
63
|
-
it '
|
64
|
-
expect(
|
65
|
-
once.
|
66
|
-
with([:numbers]).
|
67
|
-
and_return([:good, :bad])
|
68
|
-
expect(subject).to receive(:valid_number?).
|
69
|
-
once.
|
70
|
-
with(:good).
|
71
|
-
and_return(true)
|
72
|
-
expect(subject).to receive(:valid_number?).
|
73
|
-
once.
|
74
|
-
with(:bad).
|
75
|
-
and_return(false)
|
76
|
-
expect(subject.evaluate(:numbers)).to(
|
77
|
-
eq(good: [:good], bad: [:bad])
|
78
|
-
)
|
58
|
+
it 'separates numbers in good and bad' do
|
59
|
+
expect(number_sanitizer.evaluate('11988889999', 'abc')).to eq(good: ['11988889999'], bad: ['abc'])
|
79
60
|
end
|
80
61
|
end
|
81
62
|
|
82
63
|
describe '#bad?' do
|
83
|
-
|
84
|
-
|
85
|
-
|
64
|
+
subject(:number_sanitizer) { described_class.new numbers }
|
65
|
+
|
66
|
+
context 'when bad is empty' do
|
67
|
+
let(:numbers) { '11988889999' }
|
68
|
+
|
69
|
+
it { expect(number_sanitizer).not_to be_bad }
|
86
70
|
end
|
87
|
-
|
88
|
-
|
89
|
-
|
71
|
+
|
72
|
+
context 'when bad has items' do
|
73
|
+
let(:numbers) { 'ABC' }
|
74
|
+
|
75
|
+
it { expect(number_sanitizer).to be_bad }
|
90
76
|
end
|
91
77
|
end
|
92
78
|
|
93
79
|
describe '#to_s' do
|
94
|
-
|
95
|
-
|
80
|
+
context 'when is empty returns empty string' do
|
81
|
+
let(:numbers) { '' }
|
82
|
+
|
83
|
+
it { expect(number_sanitizer.to_s).to eq('') }
|
96
84
|
end
|
97
85
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
expect(subject.to_s).to eq('1,2,3,4')
|
86
|
+
context 'when all good numbers returns in a string comma separated' do
|
87
|
+
let(:numbers) { %w[11988889991 11988889992 11988889993] }
|
88
|
+
|
89
|
+
it { expect(number_sanitizer.to_s).to eq('11988889991,11988889992,11988889993') }
|
103
90
|
end
|
104
91
|
end
|
105
|
-
|
106
92
|
end
|