Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emulate Cucumber-JS's new i18n CLI options #1140

Merged
merged 7 commits into from
Jul 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
@needs-many-fonts
Feature: Language help
Feature: i18n

It's possible to ask cucumber which keywords are used for any
particular language by running:

`cucumber --i18n <language code> help`
`cucumber --i18n-keywords <LANG>`

This will print a table showing all the different words we use for
that language, to allow you to easily write features in any language
you choose.

Scenario: Get help for Portuguese language
When I run `cucumber --i18n pt help`
When I run `cucumber --i18n-keywords pt`
Then it should pass with:
"""
| feature | "Funcionalidade", "Característica", "Caracteristica" |
Expand All @@ -33,10 +33,10 @@ Feature: Language help
"""

Scenario: List languages
When I run `cucumber --i18n help`
When I run `cucumber --i18n-languages`
Then cucumber lists all the supported languages

Scenario: Seek help for invalid language
When I run `cucumber --i18n foo`
When I run `cucumber --i18n-keywords foo`
Then the output includes the message "Invalid language 'foo'"
And cucumber lists all the supported languages
And cucumber lists all the supported languages
24 changes: 13 additions & 11 deletions lib/cucumber/cli/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Options
NO_PROFILE_LONG_FLAG = '--no-profile'
FAIL_FAST_FLAG = '--fail-fast'
RETRY_FLAG = '--retry'
OPTIONS_WITH_ARGS = ['-r', '--require', '--i18n', '-f', '--format', '-o', '--out',
OPTIONS_WITH_ARGS = ['-r', '--require', '--i18n-keywords', '-f', '--format', '-o', '--out',
'-t', '--tags', '-n', '--name', '-e', '--exclude',
PROFILE_SHORT_FLAG, PROFILE_LONG_FLAG, RETRY_FLAG,
'-l', '--lines', '--port',
Expand Down Expand Up @@ -82,7 +82,7 @@ def []=(key, value)
@options[key] = value
end

def parse!(args)
def parse!(args) # rubocop:disable Metrics/AbcSize
@args = args
@expanded_args = @args.dup

Expand All @@ -97,7 +97,8 @@ def parse!(args)
end

opts.on("#{RETRY_FLAG} ATTEMPTS", *retry_msg) {|v| set_option :retry, v.to_i }
opts.on('--i18n LANG', *i18n_msg) {|lang| set_language lang }
opts.on('--i18n-languages', *i18n_languages_msg) { list_languages_and_exit }
opts.on('--i18n-keywords LANG', *i18n_keywords_msg) {|lang| set_language lang }
opts.on(FAIL_FAST_FLAG, 'Exit immediately following the first failing scenario') { set_option :fail_fast }
opts.on('-f FORMAT', '--format FORMAT', *format_msg, *FORMAT_HELP) do |v|
add_option :formats, [*parse_formats(v), @out_stream]
Expand Down Expand Up @@ -201,7 +202,13 @@ def format_msg
[ 'How to format features (Default: pretty). Available formats:' ]
end

def i18n_msg
def i18n_languages_msg
[
'List all available languages'
]
end

def i18n_keywords_msg
[
'List keywords for in a particular language',
%{Run with "--i18n help" to see all languages}
Expand Down Expand Up @@ -334,13 +341,8 @@ def require_jars(jars)
def set_language(lang)
require 'gherkin/dialect'

if lang == 'help'
list_languages_and_exit
elsif !::Gherkin::DIALECTS.keys.include? lang
indicate_invalid_language_and_exit(lang)
else
list_keywords_and_exit(lang)
end
return indicate_invalid_language_and_exit(lang) unless ::Gherkin::DIALECTS.keys.include? lang
list_keywords_and_exit(lang)
end

def disable_profile_loading
Expand Down
26 changes: 14 additions & 12 deletions spec/cucumber/cli/options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,38 +56,40 @@ def after_parsing(args)
end
end

context '--i18n' do
context "with LANG specified as 'help'" do
include RSpec::WorkInProgress
context '--i18n-languages' do
include RSpec::WorkInProgress

it 'lists all known languages' do
when_parsing '--i18n help' do
expect(Kernel).to receive(:exit)
it 'lists all known languages' do
after_parsing '--i18n-languages' do
::Gherkin::DIALECTS.keys.map do |key|
expect(@output_stream.string).to include(key.to_s);
end
end
end

it 'exits the program' do
when_parsing('--i18n help') { expect(Kernel).to receive(:exit) }
end
it 'exits the program' do
when_parsing('--i18n-languages') { expect(Kernel).to receive(:exit) }
end
end

context '--i18n-keywords' do
context 'with invalid LANG' do
include RSpec::WorkInProgress

it 'exits' do
when_parsing '--i18n foo' do
when_parsing '--i18n-keywords foo' do
expect(Kernel).to receive(:exit)
end
end

it 'says the language was invalid' do
after_parsing '--i18n foo' do
after_parsing '--i18n-keywords foo' do
expect(@output_stream.string).to include("Invalid language 'foo'. Available languages are:")
end
end

it 'displays the language table' do
after_parsing '--i18n foo' do
after_parsing '--i18n-keywords foo' do
::Gherkin::DIALECTS.keys.map do |key|
expect(@output_stream.string).to include(key.to_s);
end
Expand Down