Skip to content

Commit fb449ba

Browse files
authored
Run test with RBS test at runtime (line#537)
Resolve line#508
1 parent bea6c17 commit fb449ba

File tree

3 files changed

+40
-11
lines changed

3 files changed

+40
-11
lines changed

Rakefile

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,13 @@ end
1818
## Development
1919

2020
desc "Run normal tests (exclude no_missing_require_* specs)"
21-
task :test_normal do
22-
sh "bundle exec rspec --exclude-pattern 'spec/line/bot/line_bot_api_gem_spec.rb,spec/line/bot/line_bot_gem_spec.rb'"
21+
task :test_normal, [:skip_tag] do |_, args|
22+
skip_tag = args[:skip_tag]
23+
24+
rspec_opts = []
25+
rspec_opts << "--tag '~#{skip_tag}'" if skip_tag
26+
27+
sh "bundle exec rspec --exclude-pattern 'spec/line/bot/line_bot_api_gem_spec.rb,spec/line/bot/line_bot_gem_spec.rb' #{rspec_opts.join(' ')}"
2328
end
2429

2530
desc "Test line-bot-api gem spec"
@@ -50,6 +55,30 @@ task :rbs do
5055
sh "bundle exec rbs -I sig validate"
5156
end
5257

58+
desc "RBS type check (with test)"
59+
task :rbs_test do
60+
Dir['lib/line/bot/v2/**/*.rb'].sort.each do |file|
61+
require_relative file
62+
end
63+
64+
line_v2_targets = ObjectSpace.each_object(Module)
65+
.map(&:name)
66+
.compact
67+
.select do |mod_name|
68+
mod_name.start_with?('Line::Bot::V2::')
69+
end
70+
71+
line_v2_targets = line_v2_targets.map { |name| "#{name}::*" }.uniq
72+
73+
ENV['RUBYOPT'] = '-rbundler/setup -rrbs/test/setup'
74+
ENV['RBS_TEST_LOGLEVEL'] = 'error'
75+
ENV['RBS_TEST_RAISE'] = 'true'
76+
ENV['RBS_TEST_OPT'] = '-Isig'
77+
ENV['RBS_TEST_TARGET'] = line_v2_targets.join(',')
78+
79+
Rake::Task[:test_normal].invoke('rbs_test:skip')
80+
end
81+
5382
desc "Run rubocop"
5483
task :rubocop do
5584
sh "bundle exec rubocop"
@@ -81,5 +110,6 @@ task :ci do
81110
Rake::Task[:rubocop].invoke
82111
Rake::Task[:validate_yard_comment].invoke
83112
Rake::Task[:rbs].invoke
113+
Rake::Task[:rbs_test].invoke
84114
Rake::Task[:build_test].invoke
85115
end

sig/line/bot/v2/utils.rbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module Line
1616

1717
def self.hash_to_struct: (Hash[untyped, untyped]) -> ::Struct[untyped]
1818

19-
def self.camelize: (String | Symbol) -> String
19+
def self.camelize: (String | Symbol) -> String?
2020
end
2121
end
2222
end

spec/line/bot/v2/misc_spec.rb

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,9 @@
9797
let(:client) { Line::Bot::V2::ManageAudience::ApiClient.new(channel_access_token: channel_access_token) }
9898

9999
it 'uploads a json to the audience successfully' do
100-
create_audience_group_request = {
101-
description: 'Test Audience',
102-
}
103-
100+
create_audience_group_request = Line::Bot::V2::ManageAudience::CreateAudienceGroupRequest.new(
101+
description: 'Test Audience'
102+
)
104103
stub_request(:post, "https://api.line.me/v2/bot/audienceGroup/upload")
105104
.with(
106105
body: "{\"description\":\"Test Audience\"}",
@@ -165,14 +164,14 @@
165164
'Authorization' => "Bearer #{channel_access_token}",
166165
}
167166
)
168-
.to_return(status: response_code, body: { "status" => "ready" }.to_json, headers: { 'Content-Type' => 'application/json' })
167+
.to_return(status: response_code, body: { "status" => "processing" }.to_json, headers: { 'Content-Type' => 'application/json' })
169168

170169
body, status_code, headers = client.get_message_content_transcoding_by_message_id_with_http_info(
171170
message_id: message_id
172171
)
173172

174173
expect(status_code).to eq(200)
175-
expect(body.status).to eq('ready')
174+
expect(body.status).to eq('processing')
176175
expect(headers['content-type']).to eq('application/json')
177176
end
178177
end
@@ -536,7 +535,7 @@
536535
expect(body.sent_messages[0].quote_token).to eq('IStG5h1Tz7b...')
537536
end
538537

539-
it 'response - success - using hash (not recommended way)' do
538+
it 'response - success - using hash (not recommended way)', rbs_test: :skip do
540539
stub_request(:post, "https://api.line.me/v2/bot/message/push")
541540
.with(
542541
headers: {
@@ -1581,7 +1580,7 @@
15811580
end
15821581

15831582
context 'with invalid enum values' do
1584-
it "doesn't raise any error" do
1583+
it "doesn't raise any error", rbs_test: :skip do
15851584
liff_app = Line::Bot::V2::Liff::LiffApp.new(
15861585
liff_id: 'liffId123',
15871586
view: Line::Bot::V2::Liff::LiffView.new(

0 commit comments

Comments
 (0)