rspec-i18n 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. data/.gitignore +2 -0
  2. data/Gemfile +6 -0
  3. data/History.rdoc +40 -2
  4. data/License.txt +0 -1
  5. data/README.rdoc +19 -19
  6. data/Rakefile +54 -4
  7. data/TODO.txt +5 -24
  8. data/Tasks +3 -0
  9. data/VERSION.yml +3 -3
  10. data/bin/rspec-i18n +4 -13
  11. data/cucumber.yml +1 -0
  12. data/examples/i18n/de/german_spec.rb +39 -0
  13. data/examples/i18n/pt/{person_spec.rb → portuguese_spec.rb} +39 -7
  14. data/features/command_line/list_languages.feature +113 -0
  15. data/features/support/env.rb +13 -0
  16. data/lib/spec-i18n/command_line/language_help_formatter.rb +64 -58
  17. data/lib/spec-i18n/command_line/main.rb +1 -6
  18. data/lib/spec-i18n/command_line/options.rb +31 -17
  19. data/lib/spec-i18n/dsl/main.rb +23 -4
  20. data/lib/spec-i18n/example.rb +1 -0
  21. data/lib/spec-i18n/example/before_and_after_hooks.rb +26 -8
  22. data/lib/spec-i18n/example/example_group_methods.rb +9 -6
  23. data/lib/spec-i18n/example/pending.rb +19 -0
  24. data/lib/spec-i18n/example/subject.rb +2 -4
  25. data/lib/spec-i18n/expectations/extensions/kernel.rb +6 -4
  26. data/lib/spec-i18n/languages.yml +88 -50
  27. data/lib/spec-i18n/matchers.rb +0 -2
  28. data/lib/spec-i18n/matchers/be.rb +36 -49
  29. data/lib/spec-i18n/matchers/method_missing.rb +33 -17
  30. data/lib/spec-i18n/matchers/register_all_matchers.rb +1 -2
  31. data/lib/spec-i18n/matchers/translate_basic_matchers.rb +40 -14
  32. data/lib/spec-i18n/parser/natural_language.rb +228 -27
  33. data/lib/spec-i18n/platform.rb +0 -2
  34. data/lib/spec-i18n/runner/configuration.rb +64 -6
  35. data/lib/spec-i18n/spec_language.rb +29 -2
  36. data/rspec-i18n.gemspec +30 -20
  37. data/spec/spec-i18n/command_line/language_help_formatter_spec.rb +74 -49
  38. data/spec/spec-i18n/command_line/options_spec.rb +11 -2
  39. data/spec/spec-i18n/dsl/main_spec.rb +54 -12
  40. data/spec/spec-i18n/example/before_and_after_hooks_spec.rb +210 -88
  41. data/spec/spec-i18n/example/example_group_methods_spec.rb +26 -8
  42. data/spec/spec-i18n/example/pending_spec.rb +41 -0
  43. data/spec/spec-i18n/example/subject_spec.rb +27 -41
  44. data/spec/spec-i18n/expectations/kernel_spec.rb +29 -15
  45. data/spec/spec-i18n/matchers/be_close_spec.rb +7 -5
  46. data/spec/spec-i18n/matchers/be_instance_of_spec.rb +4 -5
  47. data/spec/spec-i18n/matchers/be_kind_of_spec.rb +3 -6
  48. data/spec/spec-i18n/matchers/be_spec.rb +255 -89
  49. data/spec/spec-i18n/matchers/eql_spec.rb +4 -6
  50. data/spec/spec-i18n/matchers/equal_spec.rb +28 -7
  51. data/spec/spec-i18n/matchers/exist_spec.rb +4 -5
  52. data/spec/spec-i18n/matchers/have_spec.rb +1 -1
  53. data/spec/spec-i18n/matchers/include_spec.rb +6 -8
  54. data/spec/spec-i18n/matchers/match_spec.rb +4 -5
  55. data/spec/spec-i18n/matchers/raise_error_spec.rb +5 -4
  56. data/spec/spec-i18n/matchers/satisfy_spec.rb +4 -5
  57. data/spec/spec-i18n/parser/natural_language_spec.rb +420 -58
  58. data/spec/spec-i18n/runner/{runner_spec.rb → rspec_i18n_language_spec.rb} +0 -0
  59. data/spec/spec-i18n/runner/{configuration_spec.rb → rspec_i18n_spec.rb} +28 -7
  60. data/spec/spec-i18n/spec_examples/pt/pessoa_spec.rb +63 -5
  61. data/spec/spec-i18n/spec_language_spec.rb +24 -10
  62. data/spec/spec.opts +1 -2
  63. data/spec/spec_helper.rb +26 -18
  64. metadata +102 -44
@@ -0,0 +1,13 @@
1
+ require 'aruba'
2
+
3
+ module ArubaOverrides
4
+ def detect_ruby_script(cmd)
5
+ if cmd =~ /^rspec-i18n/
6
+ "ruby -S ../../bin/#{cmd}"
7
+ else
8
+ super(cmd)
9
+ end
10
+ end
11
+ end
12
+
13
+ World(ArubaOverrides)
@@ -1,85 +1,91 @@
1
- require 'term/ansicolor'
2
- require 'terminal-table/import'
1
+ require 'spec-i18n/spec_language'
3
2
  require 'spec-i18n/parser'
4
-
3
+
4
+ def require_terminal_table
5
+ begin
6
+ require 'terminal-table/import'
7
+ rescue LoadError
8
+ require 'rubygems'
9
+ require 'terminal-table/import'
10
+ end
11
+ end
12
+
13
+ require_terminal_table
14
+
5
15
  module SpecI18n
6
16
  module CommandLine
7
- class LanguageHelpFormatter
8
-
17
+ class Language
18
+ extend SpecI18n::Parser
9
19
  class << self
10
- include SpecI18n::Parser
11
- include Term::ANSIColor
12
-
13
- String.class_eval do
14
- include Term::ANSIColor
15
- end
16
-
20
+
21
+ # List Name and Native Keywords of all the languages in the
22
+ # languages.yml
23
+ #
17
24
  def list_languages_and_exit(io)
18
25
  languages = list_languages
19
-
20
- languages_table = table do
26
+ print_table io, table_for_languages(languages), :exit => true
27
+ end
28
+
29
+ # Return a table to use with command to list all languages
30
+ #
31
+ def table_for_languages(languages)
32
+ table do
21
33
  self.headings = ['Language', 'Name', 'Native']
22
- languages.each do |language|
23
- add_row language
24
- end
34
+ languages.each { |language| add_row language }
25
35
  end
26
-
27
- print_table io, languages_table, :exit => true
28
36
  end
29
37
 
30
38
  def list_keywords_and_exit(io, lang)
31
-
32
- language = NaturalLanguage.get(lang)
33
-
34
- keywords = list_basic_keywords(language)
35
-
36
- print_table io, table(nil, *keywords)
37
-
38
- advanced_keywords = list_advanced_keywords(io, language)
39
-
40
- print_table io, advanced_keywords, :exit => true
39
+ language = NaturalLanguage.new(lang)
40
+ keywords_table(io, language)
41
+ matchers_table(io, language)
42
+ hooks_table(io, language)
43
+ Kernel.exit(0)
41
44
  end
42
45
 
43
- def list_languages
44
- languages = SpecI18n::SPEC_LANGUAGES.keys.sort.map do |lang|
45
- [ lang, grep_value(lang, 'name'), grep_value(lang, 'native') ]
46
- end
46
+ # Print the table to list all languages or keywords of a language
47
+ #
48
+ def print_table(io, raw, options={})
49
+ io.puts raw
50
+ Kernel.exit(0) if options[:exit]
47
51
  end
48
52
 
49
- def grep_value(lang, key)
50
- SpecI18n::SPEC_LANGUAGES[lang][key]
53
+ def keywords_table(io, language)
54
+ table_for_keywords = table do
55
+ self.headings = ['Rspec Keywords', 'Translated Keyword']
56
+ language.basic_keywords.sort.each do |rspec_keyword, translated_keyword|
57
+ add_row [rspec_keyword, translated_keyword.to_s.split('|').join(' / ')]
58
+ end
59
+ end
60
+ print_table io, table_for_keywords
51
61
  end
52
62
 
53
- def list_basic_keywords(language)
54
- NaturalLanguage::BASIC_KEYWORDS.map do |keyword|
55
- words = language.keywords[keyword]
56
- [ keyword, words.split('|').join(' / ')]
63
+ def matchers_table(io, language)
64
+ matchers = language.matchers
65
+ return if matchers.empty?
66
+ table_for_matchers = table do
67
+ self.headings = ['Rspec Matchers', 'Translated Keyword']
68
+ matchers.sort.each do |rspec_keyword, translated_keyword|
69
+ add_row [rspec_keyword, translated_keyword.split('|').join(' / ')]
70
+ end
57
71
  end
72
+ print_table io, table_for_matchers
73
+ true
58
74
  end
59
75
 
60
- def list_advanced_keywords(io, language)
61
- NaturalLanguage::ADVANCED_KEYWORDS.map do |keyword|
62
- language_keywords = [keyword]
63
- language.keywords[keyword].map do |key, values|
64
- language_keywords << [key, values.to_s.split('|').join(' / ')]
76
+ def hooks_table(io, language)
77
+ hooks = language.hooks_permutation
78
+ return nil if hooks.empty?
79
+ table_for_hooks = table do
80
+ self.headings = ['Rspec Hooks', 'Translated Keyword']
81
+ hooks.each do |rspec_keyword, translated_keyword|
82
+ add_row [rspec_keyword, translated_keyword.join(' / ')]
65
83
  end
66
-
67
- keywords_table = table do
68
- self.headings = [language_keywords.shift]
69
- language_keywords.each do |keywords|
70
- add_row keywords
71
- end
72
- end
73
-
74
- keywords_table
75
-
76
84
  end
85
+ print_table io, table_for_hooks
86
+ true
77
87
  end
78
88
 
79
- def print_table(io, raw, options={})
80
- io.puts raw.to_s.send(options[:color] || :green).bold
81
- Kernel.exit(0) if options[:exit]
82
- end
83
89
  end
84
90
 
85
91
  end
@@ -1,4 +1,3 @@
1
- require 'cucumber/formatter/color_io'
2
1
  require 'spec-i18n/command_line/options'
3
2
  require 'spec-i18n/platform'
4
3
 
@@ -11,11 +10,7 @@ module SpecI18n
11
10
 
12
11
  def initialize(args, out_stream = STDOUT, error_stream = STDERR)
13
12
  @args = args
14
- if SpecI18n::WINDOWS
15
- @out_stream = out_stream == STDOUT ? Formatter::ColorIO.new(Kernel, STDOUT) : out_stream
16
- else
17
- @out_stream = out_stream
18
- end
13
+ @out_stream = out_stream
19
14
  @error_stream = error_stream
20
15
  end
21
16
 
@@ -14,34 +14,48 @@ module SpecI18n
14
14
  @args = args
15
15
  @args.extend(::OptionParser::Arguable)
16
16
  @args.options do |opts|
17
- opts.banner = [ "Usage: rspec-i18n [options] [LANGUAGE]", "", "Examples:",
18
- "rspec-i18n --language help", "rspec-i18n --language pt"].join("\n")
19
- opts.on("-l LANGUAGE", "--language LANGUAGE", "List keywords for a particular language",
20
- %{Run with "--language help" to see all languages}) do |language|
21
- print_languages(language)
22
- end
23
- opts.on_tail("-v", "--version", "Show version.") do
24
- print_and_exit(SpecI18n::VERSION)
25
- end
26
- opts.on_tail("-h", "--help", "You're looking at it.") do
27
- print_and_exit(opts.help)
28
- end
17
+ banner(opts)
18
+ show_language_and_keywords(opts)
19
+ show_version(opts)
20
+ show_help(opts)
29
21
  end.parse!
30
22
  self
31
23
  end
32
24
 
33
- def print_languages(language)
34
- if language == 'help'
35
- LanguageHelpFormatter.list_languages_and_exit(@output_stream)
36
- else
37
- LanguageHelpFormatter.list_keywords_and_exit(@output_stream, language)
25
+ def banner(opts)
26
+ opts.banner = [ "Usage: rspec-i18n [options] [LANGUAGE]", "", "Examples:",
27
+ "rspec-i18n --language help", "rspec-i18n --language pt"].join("\n")
28
+ end
29
+
30
+ def show_language_and_keywords(opts)
31
+ opts.on("-l LANGUAGE", "--language LANGUAGE", "List keywords for a particular language",
32
+ %{Run with "--language help" to see all languages}) do |language|
33
+ print_languages(language)
38
34
  end
39
35
  end
40
36
 
37
+ def show_version(opts)
38
+ opts.on_tail("-v", "--version", "Show version.") do
39
+ print_and_exit(SpecI18n::VERSION)
40
+ end
41
+ end
42
+
43
+ def show_help(opts)
44
+ opts.on_tail("-h", "--help", "You're looking at it.") do
45
+ print_and_exit(opts.help)
46
+ end
47
+ end
48
+
49
+ def print_languages(language)
50
+ return Language.list_languages_and_exit(@output_stream) if language == 'help'
51
+ Language.list_keywords_and_exit(@output_stream, language)
52
+ end
53
+
41
54
  def print_and_exit(message)
42
55
  @output_stream.puts message
43
56
  Kernel.exit(0)
44
57
  end
58
+
45
59
  end
46
60
  end
47
61
  end
@@ -2,19 +2,38 @@ module Spec
2
2
  module DSL
3
3
  module Main
4
4
 
5
- # Register adverbs for the dsl keywords
5
+ # Translate adverbs for the dsl keywords
6
6
  #
7
7
  # { "describe" => ["descreva", "contexto"]}
8
8
  #
9
9
  # Register alias for the language specified
10
+ #
10
11
  def register_adverbs
11
- language = SpecI18n.natural_language
12
- @adverbs = language.dsl_keywords
13
- @adverbs.each do |key, values|
12
+ natural_language.dsl_keywords.each do |key, values|
14
13
  values.map { |value| alias_method value, key }
15
14
  end
16
15
  end
17
16
 
17
+ # Translate adverbs for the shared_examples_for keyword
18
+ #
19
+ # { "shared_examples_for" => ['exemplos_distribuidos_para']}
20
+ #
21
+ def translate_shared_examples_for
22
+ natural_language.shared_examples_for_keywords.each do |shared_examples_method, shared_example_keywords|
23
+ shared_example_keywords.each { |keyword| alias_method keyword, shared_examples_method }
24
+ end
25
+ end
26
+
27
+ # Translate adverbs for the share_as keywords
28
+ #
29
+ # { 'share_as' => ['distribua', 'distribua_como']}
30
+ #
31
+ def translate_share_as_keywords
32
+ natural_language.share_as_keywords.each do |share_as_method, share_as_keywords|
33
+ share_as_keywords.each { |keyword| alias_method keyword, share_as_method }
34
+ end
35
+ end
36
+
18
37
  end
19
38
  end
20
39
  end
@@ -1,3 +1,4 @@
1
1
  require 'spec-i18n/example/before_and_after_hooks'
2
2
  require 'spec-i18n/example/example_group_methods'
3
+ require 'spec-i18n/example/pending'
3
4
  require 'spec-i18n/example/subject'
@@ -2,15 +2,16 @@ module Spec
2
2
  module Example
3
3
  module BeforeAndAfterHooks
4
4
 
5
+ # Translate hooks(before and after) keywords
6
+ #
5
7
  def register_hooks
6
- language = SpecI18n.natural_language
7
- language.before_and_after_keywords.each do |key, values|
8
- values.map do |value|
9
- alias_method value, key
10
- end
8
+ natural_language.before_and_after_keywords.each do |key, values|
9
+ values.collect { |value| alias_method value, key }
11
10
  end
12
11
  end
13
12
 
13
+ # OverWriting a methor for rspec to work with hooks parameters
14
+ #
14
15
  def before_parts(scope)
15
16
 
16
17
  scope = grep_language_and_scope(scope) || scope
@@ -22,9 +23,11 @@ module Spec
22
23
  end
23
24
  end
24
25
 
26
+ # OverWriting a methor for rspec to work with hooks parameters
27
+ #
25
28
  def after_parts(scope)
26
29
 
27
- scope = grep_language_and_scope(scope) || scope
30
+ scope = grep_language_and_scope(scope)
28
31
 
29
32
  case scope
30
33
  when :each; after_each_parts
@@ -33,15 +36,30 @@ module Spec
33
36
  end
34
37
  end
35
38
 
39
+ # Grep the tranlated scope
40
+ #
41
+ # pt:
42
+ # hooks:
43
+ # each: cada
44
+ #
45
+ # grep_language_and_scope(:cada) # => :each
46
+ # grep_language_and_scope(:each) # => :each
47
+ #
36
48
  def grep_language_and_scope(scope)
37
49
  if SpecI18n.spec_language
38
- language = SpecI18n.natural_language
39
- scope = grep_the_scope(scope, language.hooks_params_keywords)
50
+ hooks = natural_language.hooks_params_keywords
51
+ scope = grep_the_scope(scope, hooks)
52
+ else
53
+ scope
40
54
  end
41
55
  end
42
56
 
43
57
  # Receive a String Scope and return the scope in english for
44
58
  # the rspec run the right method
59
+ #
60
+ # grep_the_scope(:cada, { 'each' => [ 'cada' ] }) # => :each
61
+ #
62
+ #
45
63
  def grep_the_scope(scope, hooks)
46
64
  scopes = [:each, :all, :suite]
47
65
  return scope if scopes.include?(scope)
@@ -3,12 +3,15 @@ module Spec
3
3
  module ExampleGroupMethods
4
4
 
5
5
  def self.register_example_adverbs
6
- language = SpecI18n.natural_language
7
- @adverbs = language.example_group_keywords
8
- @adverbs.each do |key, values|
9
- values.map do |value|
10
- alias_method value, key
11
- end
6
+ natural_language.example_group_keywords.each do |key, values|
7
+ values.each { |value| alias_method value, key }
8
+ end
9
+ end
10
+
11
+ # tranlated it_should_behave_like word
12
+ def self.translate_it_should_behave_like
13
+ natural_language.it_should_behave_like_keywords.each do |it_should_behave_like_method, it_should_behave_like_keywords|
14
+ it_should_behave_like_keywords.each { |keyword| alias_method keyword, it_should_behave_like_method}
12
15
  end
13
16
  end
14
17
 
@@ -0,0 +1,19 @@
1
+ module Spec
2
+ module Example
3
+ module Pending
4
+
5
+ class << self
6
+
7
+ # Translate the pending word
8
+ #
9
+ def translate_pending_keywords
10
+ natural_language.pending_keywords.each do |pending_method, translated_methods|
11
+ translated_methods.each { |translated_method| alias_method translated_method, pending_method}
12
+ end
13
+ end
14
+
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -5,8 +5,7 @@ module Spec
5
5
  # TODO: Removing Duplications
6
6
  class << self
7
7
  def register_subjects
8
- language = SpecI18n.natural_language
9
- subject_and_its_keywords = language.subject_keywords.merge(language.its_keywords)
8
+ subject_and_its_keywords = natural_language.subject_keywords.merge(natural_language.its_keywords)
10
9
  subject_and_its_keywords.each do |key, values|
11
10
  values.map { |value| alias_method value, key }
12
11
  end
@@ -16,8 +15,7 @@ module Spec
16
15
  module ExampleMethods
17
16
  class << self
18
17
  def register_subjects
19
- language = SpecI18n.natural_language
20
- subject_and_expectation_keywords = language.subject_keywords.merge(language.expectation_keywords)
18
+ subject_and_expectation_keywords = natural_language.subject_keywords.merge(natural_language.expectation_keywords)
21
19
  subject_and_expectation_keywords.each do |key, values|
22
20
  values.map { |value| alias_method value, key }
23
21
  end
@@ -1,9 +1,11 @@
1
1
  module Kernel
2
+
3
+ # Translate the <b>should</b> and <b>should_not</b> method
4
+ #
2
5
  def register_expectations_keywords
3
- language = SpecI18n.natural_language
4
- @adverbs = language.expectation_keywords
5
- @adverbs.each do |key, values|
6
- values.map { |value| alias_method value, key }
6
+ natural_language.expectation_keywords.each do |key, values|
7
+ values.collect { |value| alias_method value, key }
7
8
  end
8
9
  end
10
+
9
11
  end