From 094cc8d090c7d92ee38aeb9f76cd4c3102c0bb82 Mon Sep 17 00:00:00 2001 From: Mark Pirri Date: Thu, 27 Apr 2017 15:32:45 -0400 Subject: [PATCH] RuboCop cleanup --- .../lib/fastlane_core/build_watcher.rb | 76 ++++++++++--------- spaceship/spec/spec_helper.rb | 2 +- spaceship/spec/test_flight/build_spec.rb | 38 +++++----- 3 files changed, 59 insertions(+), 57 deletions(-) diff --git a/fastlane_core/lib/fastlane_core/build_watcher.rb b/fastlane_core/lib/fastlane_core/build_watcher.rb index a6b5fb729ef..5985deaa37b 100644 --- a/fastlane_core/lib/fastlane_core/build_watcher.rb +++ b/fastlane_core/lib/fastlane_core/build_watcher.rb @@ -1,52 +1,54 @@ module FastlaneCore class BuildWatcher - # @return The build we waited for. This method will always return a build - def self.wait_for_build_processing_to_be_complete(app_id: nil, platform: nil) - # First, find the train and build version we want to watch for - watched_build = watching_build(app_id: app_id, platform: platform) - UI.crash!("Could not find a build for app: #{app_id} on platform: #{platform}") if watched_build.nil? + class << self + # @return The build we waited for. This method will always return a build + def wait_for_build_processing_to_be_complete(app_id: nil, platform: nil) + # First, find the train and build version we want to watch for + watched_build = watching_build(app_id: app_id, platform: platform) + UI.crash!("Could not find a build for app: #{app_id} on platform: #{platform}") if watched_build.nil? - loop do - matched_build = matching_build(watched_build: watched_build, app_id: app_id, platform: platform) + loop do + matched_build = matching_build(watched_build: watched_build, app_id: app_id, platform: platform) - report_status(build: matched_build) + report_status(build: matched_build) - if matched_build && matched_build.processed? - return matched_build - end + if matched_build && matched_build.processed? + return matched_build + end - sleep 10 + sleep 10 + end end - end - private + private - def self.watching_build(app_id: nil, platform: nil) - processing_builds = Spaceship::TestFlight::Build.all_processing_builds(app_id: app_id, platform: platform) + def watching_build(app_id: nil, platform: nil) + processing_builds = Spaceship::TestFlight::Build.all_processing_builds(app_id: app_id, platform: platform) - watched_build = processing_builds.sort_by(&:upload_date).last - watched_build ||= Spaceship::TestFlight::Build.latest(app_id: app_id, platform: platform) - end + watched_build = processing_builds.sort_by(&:upload_date).last + watched_build || Spaceship::TestFlight::Build.latest(app_id: app_id, platform: platform) + end - def self.matching_build(watched_build: nil, app_id: nil, platform: nil) - matched_builds = Spaceship::TestFlight::Build.builds_for_train(app_id: app_id, platform: platform, train_version: watched_build.train_version) - matched_builds.find { |build| build.build_version == watched_build.build_version } - end + def matching_build(watched_build: nil, app_id: nil, platform: nil) + matched_builds = Spaceship::TestFlight::Build.builds_for_train(app_id: app_id, platform: platform, train_version: watched_build.train_version) + matched_builds.find { |build| build.build_version == watched_build.build_version } + end - def self.report_status(build: nil) - # Due to iTunes Connect, builds disappear from the build list alltogether - # after they finished processing. Before returning this build, we have to - # wait for the build to appear in the build list again - # As this method is very often used to wait for a build, and then do something - # with it, we have to be sure that the build actually is ready - if build.nil? - UI.message("Build doesn't show up in the build list any more, waiting for it to appear again") - elsif build.active? - UI.success("Build #{build.train_version} - #{build.build_version} is already being tested") - elsif build.ready_to_submit? || build.export_compliance_missing? - UI.success("Successfully finished processing the build #{build.train_version} - #{build.build_version}") - else - UI.message("Waiting for iTunes Connect to finish processing the new build (#{build.train_version} - #{build.build_version})") + def report_status(build: nil) + # Due to iTunes Connect, builds disappear from the build list alltogether + # after they finished processing. Before returning this build, we have to + # wait for the build to appear in the build list again + # As this method is very often used to wait for a build, and then do something + # with it, we have to be sure that the build actually is ready + if build.nil? + UI.message("Build doesn't show up in the build list any more, waiting for it to appear again") + elsif build.active? + UI.success("Build #{build.train_version} - #{build.build_version} is already being tested") + elsif build.ready_to_submit? || build.export_compliance_missing? + UI.success("Successfully finished processing the build #{build.train_version} - #{build.build_version}") + else + UI.message("Waiting for iTunes Connect to finish processing the new build (#{build.train_version} - #{build.build_version})") + end end end end diff --git a/spaceship/spec/spec_helper.rb b/spaceship/spec/spec_helper.rb index 42a626c7f9c..a57451c3b1d 100644 --- a/spaceship/spec/spec_helper.rb +++ b/spaceship/spec/spec_helper.rb @@ -73,7 +73,7 @@ def mock_client_response(method_name, with: anything) mock_method = allow(mock_client).to receive(method_name) mock_method = mock_method.with(with) if block_given? - mock_method.and_return(JSON.load(yield.to_json)) + mock_method.and_return(JSON.parse(yield.to_json)) else mock_method end diff --git a/spaceship/spec/test_flight/build_spec.rb b/spaceship/spec/test_flight/build_spec.rb index fbfd905a15d..784bd75267b 100644 --- a/spaceship/spec/test_flight/build_spec.rb +++ b/spaceship/spec/test_flight/build_spec.rb @@ -15,7 +15,7 @@ { id: 456, bundleId: 'com.foo.bar', - trainVersion: '1.0', + trainVersion: '1.0' } end @@ -28,9 +28,9 @@ it 'returns raises when the build cannot be found' do mock_client_response(:get_build).and_raise(Spaceship::Client::UnexpectedResponse) - expect { + expect do Spaceship::TestFlight::Build.find(app_id: 123, build_id: 456) - }.to raise_error(Spaceship::Client::UnexpectedResponse) + end.to raise_error(Spaceship::Client::UnexpectedResponse) end end @@ -47,7 +47,7 @@ appAdamId: 10, trainVersion: '1.0', uploadDate: '2017-01-01T12:00:00.000+0000', - externalState: 'testflight.build.state.export.compliance.missing', + externalState: 'testflight.build.state.export.compliance.missing' } ] end @@ -59,14 +59,14 @@ appAdamId: 10, trainVersion: '1.1', uploadDate: '2017-01-02T12:00:00.000+0000', - externalState: 'testflight.build.state.submit.ready', + externalState: 'testflight.build.state.submit.ready' }, { id: 3, appAdamId: 10, trainVersion: '1.1', uploadDate: '2017-01-03T12:00:00.000+0000', - externalState: 'testflight.build.state.processing', + externalState: 'testflight.build.state.processing' } ] end @@ -100,13 +100,13 @@ context '.latest' do it 'returns the latest build across all build trains' do latest_build = Spaceship::TestFlight::Build.latest(app_id: 10, platform: 'ios') - expect(latest_build.upload_date).to eq(Time.utc(2017,1,3,12)) + expect(latest_build.upload_date).to eq(Time.utc(2017, 1, 3, 12)) end end end context 'instances' do - let(:build) { Spaceship::TestFlight::Build.find(app_id: 'some-app-id', build_id: 'some-build-id') } + let(:build) { Spaceship::TestFlight::Build.find(app_id: 'some-app-id', build_id: 'some-build-id') } before do mock_client_response(:get_build) do @@ -122,16 +122,16 @@ }, exportCompliance: { usesEncryption: true, - encryptionUpdated: false, + encryptionUpdated: false }, testInfo: [ { locale: 'en-US', description: 'test info', feedbackEmail: 'email@example.com', - whatsNew: 'this is new!', + whatsNew: 'this is new!' } - ], + ] } end end @@ -140,16 +140,16 @@ build = Spaceship::TestFlight::Build.new build.id = 1 build.app_id = 2 - expect { + expect do build.reload - }.to change(build, :bundle_id).from(nil).to('some-bundle-id') + end.to change(build, :bundle_id).from(nil).to('some-bundle-id') end context 'submission state' do it 'is ready to submit' do mock_client_response(:get_build) do { - 'externalState': 'testflight.build.state.submit.ready' + 'externalState' => 'testflight.build.state.submit.ready' } end expect(build).to be_ready_to_submit @@ -158,7 +158,7 @@ it 'is ready to test' do mock_client_response(:get_build) do { - 'externalState': 'testflight.build.state.testing.ready' + 'externalState' => 'testflight.build.state.testing.ready' } end expect(build).to be_ready_to_test @@ -167,7 +167,7 @@ it 'is active' do mock_client_response(:get_build) do { - 'externalState': 'testflight.build.state.testing.active' + 'externalState' => 'testflight.build.state.testing.active' } end expect(build).to be_active @@ -176,7 +176,7 @@ it 'is processing' do mock_client_response(:get_build) do { - 'externalState': 'testflight.build.state.processing' + 'externalState' => 'testflight.build.state.processing' } end expect(build).to be_processing @@ -185,7 +185,7 @@ it 'is has missing export compliance' do mock_client_response(:get_build) do { - 'externalState': 'testflight.build.state.export.compliance.missing' + 'externalState' => 'testflight.build.state.export.compliance.missing' } end expect(build).to be_export_compliance_missing @@ -194,7 +194,7 @@ context '#upload_date' do it 'parses the string value' do - expect(build.upload_date).to eq(Time.utc(2017,1,1,12)) + expect(build.upload_date).to eq(Time.utc(2017, 1, 1, 12)) end end