Skip to content

Commit

Permalink
RuboCop cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Pirri committed Apr 27, 2017
1 parent 557542a commit 094cc8d
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 57 deletions.
76 changes: 39 additions & 37 deletions fastlane_core/lib/fastlane_core/build_watcher.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion spaceship/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 19 additions & 19 deletions spaceship/spec/test_flight/build_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
{
id: 456,
bundleId: 'com.foo.bar',
trainVersion: '1.0',
trainVersion: '1.0'
}
end

Expand All @@ -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

Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down

0 comments on commit 094cc8d

Please sign in to comment.