Skip to content

Commit 8557185

Browse files
committed
feat(utils): integral_string? as module_function
1 parent eff59f2 commit 8557185

3 files changed

Lines changed: 19 additions & 14 deletions

File tree

lib/env_pull_request/utils.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ module Utils
33
def integral_string?(value)
44
value.is_a?(String) && /^\d+$/ =~ value ? true : false
55
end
6+
module_function :integral_string?
67
end
78
end

test/test_ci.rb

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,18 @@ def self.shutdown
3030
test '#pull_request?' do
3131
assert do
3232
EnvPullRequest.new do
33-
ENV['PULL_REQUEST_ID'].to_i if ENV['PULL_REQUEST_ID']
33+
if Utils.integral_string? ENV['PULL_REQUEST_ID']
34+
ENV['PULL_REQUEST_ID'].to_i
35+
end
3436
end.pull_request? == false
3537
end
3638
end
3739
test '#pull_request_id' do
3840
assert do
3941
EnvPullRequest.new do
40-
ENV['PULL_REQUEST_ID'].to_i if ENV['PULL_REQUEST_ID']
42+
if Utils.integral_string? ENV['PULL_REQUEST_ID']
43+
ENV['PULL_REQUEST_ID'].to_i
44+
end
4145
end.pull_request_id.nil?
4246
end
4347
end
@@ -58,14 +62,18 @@ def self.shutdown
5862
test '#pull_request?' do
5963
assert do
6064
EnvPullRequest.new do
61-
ENV['PULL_REQUEST_ID'].to_i if ENV['PULL_REQUEST_ID']
65+
if Utils.integral_string? ENV['PULL_REQUEST_ID']
66+
ENV['PULL_REQUEST_ID'].to_i
67+
end
6268
end.pull_request? == true
6369
end
6470
end
6571
test '#pull_request_id' do
6672
assert do
6773
EnvPullRequest.new do
68-
ENV['PULL_REQUEST_ID'].to_i if ENV['PULL_REQUEST_ID']
74+
if Utils.integral_string? ENV['PULL_REQUEST_ID']
75+
ENV['PULL_REQUEST_ID'].to_i
76+
end
6977
end.pull_request_id == pull_id
7078
end
7179
end

test/test_utils.rb

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,37 @@
22

33
module EnvPullRequest
44
class TestUtils < Test::Unit::TestCase
5-
target = Class.new do
6-
include Utils
7-
end.new
8-
95
sub_test_case 'not integral' do
106
test 'nil' do
117
assert do
12-
target.integral_string?(nil) == false
8+
Utils.integral_string?(nil) == false
139
end
1410
end
1511
test 'empty string' do
1612
assert do
17-
target.integral_string?('') == false
13+
Utils.integral_string?('') == false
1814
end
1915
end
2016
test 'integer' do
2117
assert do
22-
target.integral_string?(1) == false
18+
Utils.integral_string?(1) == false
2319
end
2420
end
2521
test 'decimal string' do
2622
assert do
27-
target.integral_string?('1.1') == false
23+
Utils.integral_string?('1.1') == false
2824
end
2925
end
3026
end
3127
sub_test_case 'integral' do
3228
test '1' do
3329
assert do
34-
target.integral_string?('1') == true
30+
Utils.integral_string?('1') == true
3531
end
3632
end
3733
test '10000000000000000' do
3834
assert do
39-
target.integral_string?('10000000000000000') == true
35+
Utils.integral_string?('10000000000000000') == true
4036
end
4137
end
4238
end

0 commit comments

Comments
 (0)