From 5154aa22d137e9bf909837aded0289ee807b4833 Mon Sep 17 00:00:00 2001 From: Aida Date: Fri, 30 Jun 2017 09:54:21 +0200 Subject: [PATCH 1/7] Rename language help feature --- .../docs/{gherkin/language_help.feature => cli/i18n.feature} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename features/docs/{gherkin/language_help.feature => cli/i18n.feature} (97%) diff --git a/features/docs/gherkin/language_help.feature b/features/docs/cli/i18n.feature similarity index 97% rename from features/docs/gherkin/language_help.feature rename to features/docs/cli/i18n.feature index 0de429fd79..8733c0da8d 100644 --- a/features/docs/gherkin/language_help.feature +++ b/features/docs/cli/i18n.feature @@ -1,5 +1,5 @@ @needs-many-fonts -Feature: Language help +Feature: i18n It's possible to ask cucumber which keywords are used for any particular language by running: @@ -39,4 +39,4 @@ Feature: Language help Scenario: Seek help for invalid language When I run `cucumber --i18n foo` Then the output includes the message "Invalid language 'foo'" - And cucumber lists all the supported languages \ No newline at end of file + And cucumber lists all the supported languages From 10746d9e51f764ea47edea222cc5628c5e17b928 Mon Sep 17 00:00:00 2001 From: Aida Date: Fri, 30 Jun 2017 09:56:08 +0200 Subject: [PATCH 2/7] Fix i18n scenarios to meet new requirements --- features/docs/cli/i18n.feature | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/features/docs/cli/i18n.feature b/features/docs/cli/i18n.feature index 8733c0da8d..cfafa790eb 100644 --- a/features/docs/cli/i18n.feature +++ b/features/docs/cli/i18n.feature @@ -4,14 +4,14 @@ Feature: i18n It's possible to ask cucumber which keywords are used for any particular language by running: - `cucumber --i18n help` + `cucumber --i18n-keywords ` 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" | @@ -33,10 +33,10 @@ Feature: i18n """ 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 From d4c9888632d1bb8ed99a4e6a132208e773e8858f Mon Sep 17 00:00:00 2001 From: Aida Date: Fri, 30 Jun 2017 10:11:14 +0200 Subject: [PATCH 3/7] Implement new cli options for language help --- lib/cucumber/cli/options.rb | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/cucumber/cli/options.rb b/lib/cucumber/cli/options.rb index 1422aa6ac1..0b7642c285 100644 --- a/lib/cucumber/cli/options.rb +++ b/lib/cucumber/cli/options.rb @@ -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', @@ -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] @@ -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} @@ -334,12 +341,10 @@ 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 + if ::Gherkin::DIALECTS.keys.include? lang list_keywords_and_exit(lang) + else + indicate_invalid_language_and_exit(lang) end end From 3ac32fbcb4692f51d110bbff52c701ac4f601efb Mon Sep 17 00:00:00 2001 From: Aida Manna Date: Fri, 30 Jun 2017 13:45:59 +0200 Subject: [PATCH 4/7] Update unit tests for language help to meet the new requirements --- spec/cucumber/cli/options_spec.rb | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/spec/cucumber/cli/options_spec.rb b/spec/cucumber/cli/options_spec.rb index 2b1097c51f..bbe440144f 100644 --- a/spec/cucumber/cli/options_spec.rb +++ b/spec/cucumber/cli/options_spec.rb @@ -56,38 +56,38 @@ 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) - end + it 'lists all known languages' do + when_parsing '--i18n-languages' do + expect(Kernel).to receive(:exit) 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 From 65b12249c953e6eb237e02a83f5a50ff864509e8 Mon Sep 17 00:00:00 2001 From: Aida Manna Date: Fri, 30 Jun 2017 13:51:26 +0200 Subject: [PATCH 5/7] Fix test to assert that the languages list is displayed --- spec/cucumber/cli/options_spec.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/spec/cucumber/cli/options_spec.rb b/spec/cucumber/cli/options_spec.rb index bbe440144f..c83b725729 100644 --- a/spec/cucumber/cli/options_spec.rb +++ b/spec/cucumber/cli/options_spec.rb @@ -60,8 +60,10 @@ def after_parsing(args) include RSpec::WorkInProgress it 'lists all known languages' do - when_parsing '--i18n-languages' do - expect(Kernel).to receive(:exit) + after_parsing '--i18n-languages' do + ::Gherkin::DIALECTS.keys.map do |key| + expect(@output_stream.string).to include(key.to_s); + end end end From 264ba99fb9fcf08587dc2e9baa32e9c4d38c8bc3 Mon Sep 17 00:00:00 2001 From: Aida Manna Date: Fri, 30 Jun 2017 15:27:02 +0200 Subject: [PATCH 6/7] Keep RuboCop happy --- lib/cucumber/cli/options.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cucumber/cli/options.rb b/lib/cucumber/cli/options.rb index 0b7642c285..8e791e13cd 100644 --- a/lib/cucumber/cli/options.rb +++ b/lib/cucumber/cli/options.rb @@ -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 From 22a522a8580614a21cb5ddcac0502fb185cdafe7 Mon Sep 17 00:00:00 2001 From: Aida Manna Date: Mon, 3 Jul 2017 10:09:03 +0200 Subject: [PATCH 7/7] Use Guard Clause instead of if/else --- lib/cucumber/cli/options.rb | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/cucumber/cli/options.rb b/lib/cucumber/cli/options.rb index 8e791e13cd..d63f346374 100644 --- a/lib/cucumber/cli/options.rb +++ b/lib/cucumber/cli/options.rb @@ -341,11 +341,8 @@ def require_jars(jars) def set_language(lang) require 'gherkin/dialect' - if ::Gherkin::DIALECTS.keys.include? lang - list_keywords_and_exit(lang) - else - indicate_invalid_language_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