-
Notifications
You must be signed in to change notification settings - Fork 902
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The new release requires support for a range of Ruby version, which are defined in the project Gemfile. This change add support for validating against an in project Gemfile (or .ruby-version if it can't find one). It finally falls back on the baked in version with the CLI. There are also additional unit tests and some background comments.
- Loading branch information
Showing
7 changed files
with
297 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
packages/cli-doctor/src/tools/healthchecks/__tests__/ruby.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import ruby, {output} from '../ruby'; | ||
|
||
// | ||
// Mocks | ||
// | ||
const mockExeca = jest.fn(); | ||
jest.mock('execa', () => mockExeca); | ||
|
||
const mockLogger = jest.fn(); | ||
jest.mock('@react-native-community/cli-tools', () => ({ | ||
findProjectRoot: () => '.', | ||
logger: { | ||
warn: mockLogger, | ||
}, | ||
})); | ||
|
||
jest.mock('../../versionRanges', () => ({ | ||
RUBY: '>= 1.0.0', | ||
})); | ||
|
||
// | ||
// Placeholder Values | ||
// | ||
const Languages = { | ||
Ruby: {version: '1.0.0'}, | ||
}; | ||
|
||
const runRubyGetDiagnostic = () => { | ||
// @ts-ignore | ||
return ruby.getDiagnostics({Languages}); | ||
}; | ||
|
||
const Gemfile = { | ||
noGemfile: {code: 1}, | ||
noRuby: {code: 'ENOENT'}, | ||
ok: {stdout: output.OK}, | ||
unknown: (err: Error) => err, | ||
wrongRuby: (stderr: string) => ({code: 2, stderr}), | ||
}; | ||
|
||
// | ||
// Tests | ||
// | ||
|
||
describe('ruby', () => { | ||
beforeEach(() => { | ||
mockLogger.mockClear(); | ||
mockExeca.mockClear(); | ||
}); | ||
|
||
describe('Gemfile', () => { | ||
it('validates the environment', async () => { | ||
mockExeca.mockResolvedValueOnce(Gemfile.ok); | ||
|
||
expect(await runRubyGetDiagnostic()).toMatchObject({ | ||
needsToBeFixed: false, | ||
}); | ||
}); | ||
|
||
it('fails to find ruby to run the script', async () => { | ||
mockExeca.mockRejectedValueOnce(Gemfile.noRuby); | ||
|
||
const resp = await runRubyGetDiagnostic(); | ||
expect(resp.needsToBeFixed).toEqual(true); | ||
expect(resp.description).toMatch(/Ruby/i); | ||
}); | ||
|
||
it('fails to find the Gemfile and messages the user', async () => { | ||
mockExeca.mockRejectedValueOnce(Gemfile.noGemfile); | ||
|
||
const {description} = await runRubyGetDiagnostic(); | ||
expect(description).toMatch(/could not find/i); | ||
}); | ||
|
||
it('fails because the wrong version of ruby is installed', async () => { | ||
const stderr = '>= 3.2.0, < 3.2.0'; | ||
mockExeca.mockRejectedValueOnce(Gemfile.wrongRuby(stderr)); | ||
|
||
expect(await runRubyGetDiagnostic()).toMatchObject({ | ||
needsToBeFixed: true, | ||
versionRange: stderr, | ||
}); | ||
}); | ||
|
||
it('fails for unknown reasons, so we skip it but log', async () => { | ||
const error = Error('Something bad went wrong'); | ||
mockExeca.mockRejectedValueOnce(Gemfile.unknown(error)); | ||
|
||
await runRubyGetDiagnostic(); | ||
expect(mockLogger).toBeCalledTimes(1); | ||
expect(mockLogger).toBeCalledWith(error.message); | ||
}); | ||
|
||
it('uses are static ruby versions builtin into doctor if no Gemfile', async () => { | ||
mockExeca.mockRejectedValueOnce(new Error('Meh')); | ||
expect(await runRubyGetDiagnostic()).toMatchObject({ | ||
needsToBeFixed: false, | ||
version: Languages.Ruby.version, | ||
versionRange: '>= 1.0.0', | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters