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.
- data/.gitignore +2 -0
- data/Gemfile +6 -0
- data/History.rdoc +40 -2
- data/License.txt +0 -1
- data/README.rdoc +19 -19
- data/Rakefile +54 -4
- data/TODO.txt +5 -24
- data/Tasks +3 -0
- data/VERSION.yml +3 -3
- data/bin/rspec-i18n +4 -13
- data/cucumber.yml +1 -0
- data/examples/i18n/de/german_spec.rb +39 -0
- data/examples/i18n/pt/{person_spec.rb → portuguese_spec.rb} +39 -7
- data/features/command_line/list_languages.feature +113 -0
- data/features/support/env.rb +13 -0
- data/lib/spec-i18n/command_line/language_help_formatter.rb +64 -58
- data/lib/spec-i18n/command_line/main.rb +1 -6
- data/lib/spec-i18n/command_line/options.rb +31 -17
- data/lib/spec-i18n/dsl/main.rb +23 -4
- data/lib/spec-i18n/example.rb +1 -0
- data/lib/spec-i18n/example/before_and_after_hooks.rb +26 -8
- data/lib/spec-i18n/example/example_group_methods.rb +9 -6
- data/lib/spec-i18n/example/pending.rb +19 -0
- data/lib/spec-i18n/example/subject.rb +2 -4
- data/lib/spec-i18n/expectations/extensions/kernel.rb +6 -4
- data/lib/spec-i18n/languages.yml +88 -50
- data/lib/spec-i18n/matchers.rb +0 -2
- data/lib/spec-i18n/matchers/be.rb +36 -49
- data/lib/spec-i18n/matchers/method_missing.rb +33 -17
- data/lib/spec-i18n/matchers/register_all_matchers.rb +1 -2
- data/lib/spec-i18n/matchers/translate_basic_matchers.rb +40 -14
- data/lib/spec-i18n/parser/natural_language.rb +228 -27
- data/lib/spec-i18n/platform.rb +0 -2
- data/lib/spec-i18n/runner/configuration.rb +64 -6
- data/lib/spec-i18n/spec_language.rb +29 -2
- data/rspec-i18n.gemspec +30 -20
- data/spec/spec-i18n/command_line/language_help_formatter_spec.rb +74 -49
- data/spec/spec-i18n/command_line/options_spec.rb +11 -2
- data/spec/spec-i18n/dsl/main_spec.rb +54 -12
- data/spec/spec-i18n/example/before_and_after_hooks_spec.rb +210 -88
- data/spec/spec-i18n/example/example_group_methods_spec.rb +26 -8
- data/spec/spec-i18n/example/pending_spec.rb +41 -0
- data/spec/spec-i18n/example/subject_spec.rb +27 -41
- data/spec/spec-i18n/expectations/kernel_spec.rb +29 -15
- data/spec/spec-i18n/matchers/be_close_spec.rb +7 -5
- data/spec/spec-i18n/matchers/be_instance_of_spec.rb +4 -5
- data/spec/spec-i18n/matchers/be_kind_of_spec.rb +3 -6
- data/spec/spec-i18n/matchers/be_spec.rb +255 -89
- data/spec/spec-i18n/matchers/eql_spec.rb +4 -6
- data/spec/spec-i18n/matchers/equal_spec.rb +28 -7
- data/spec/spec-i18n/matchers/exist_spec.rb +4 -5
- data/spec/spec-i18n/matchers/have_spec.rb +1 -1
- data/spec/spec-i18n/matchers/include_spec.rb +6 -8
- data/spec/spec-i18n/matchers/match_spec.rb +4 -5
- data/spec/spec-i18n/matchers/raise_error_spec.rb +5 -4
- data/spec/spec-i18n/matchers/satisfy_spec.rb +4 -5
- data/spec/spec-i18n/parser/natural_language_spec.rb +420 -58
- data/spec/spec-i18n/runner/{runner_spec.rb → rspec_i18n_language_spec.rb} +0 -0
- data/spec/spec-i18n/runner/{configuration_spec.rb → rspec_i18n_spec.rb} +28 -7
- data/spec/spec-i18n/spec_examples/pt/pessoa_spec.rb +63 -5
- data/spec/spec-i18n/spec_language_spec.rb +24 -10
- data/spec/spec.opts +1 -2
- data/spec/spec_helper.rb +26 -18
- metadata +102 -44
data/lib/spec-i18n/languages.yml
CHANGED
@@ -6,48 +6,118 @@
|
|
6
6
|
|
7
7
|
# The English language => Just for example all the keywords
|
8
8
|
"en":
|
9
|
-
name:
|
10
|
-
native:
|
11
|
-
describe:
|
12
|
-
it:
|
13
|
-
its:
|
14
|
-
|
15
|
-
|
9
|
+
name: English
|
10
|
+
native: English
|
11
|
+
describe:
|
12
|
+
it:
|
13
|
+
its:
|
14
|
+
pending:
|
15
|
+
subject:
|
16
|
+
shared_examples_for:
|
17
|
+
share_as:
|
18
|
+
it_should_behave_like:
|
19
|
+
should:
|
16
20
|
should_not:
|
17
21
|
before:
|
18
22
|
after:
|
19
|
-
hooks:
|
23
|
+
hooks:
|
20
24
|
each:
|
21
25
|
all:
|
22
26
|
suite:
|
23
|
-
matchers:
|
27
|
+
matchers:
|
24
28
|
be:
|
25
|
-
true_word:
|
29
|
+
true_word:
|
26
30
|
false_word:
|
27
31
|
nil_word:
|
28
32
|
empty_word:
|
29
|
-
be_a_kind_of:
|
33
|
+
be_a_kind_of:
|
30
34
|
be_close:
|
31
35
|
be_an_instance_of:
|
32
36
|
eql:
|
33
37
|
equal:
|
34
|
-
exist:
|
38
|
+
exist:
|
35
39
|
have:
|
36
|
-
have_exactly:
|
40
|
+
have_exactly:
|
37
41
|
have_at_least:
|
38
|
-
have_at_most:
|
42
|
+
have_at_most:
|
39
43
|
include:
|
40
44
|
match:
|
41
|
-
raise_error:
|
45
|
+
raise_error:
|
42
46
|
satisfy:
|
43
47
|
|
48
|
+
"ar":
|
49
|
+
name: Arabic
|
50
|
+
native: العربية
|
51
|
+
|
52
|
+
"de":
|
53
|
+
name: German
|
54
|
+
native: Deutsch
|
55
|
+
describe: beschreibe|kontext
|
56
|
+
it: es
|
57
|
+
its:
|
58
|
+
pending:
|
59
|
+
subject: subjekt
|
60
|
+
share_as:
|
61
|
+
shared_examples_for:
|
62
|
+
it_should_behave_like:
|
63
|
+
should: sollte
|
64
|
+
should_not: sollte_nicht
|
65
|
+
before: vorher
|
66
|
+
after: nachher
|
67
|
+
hooks:
|
68
|
+
each: von_jeder
|
69
|
+
all: von_alle
|
70
|
+
suite: suite
|
71
|
+
matchers:
|
72
|
+
be: sein
|
73
|
+
true_word: wahr*
|
74
|
+
false_word: falsch*
|
75
|
+
nil_word: null*
|
76
|
+
empty_word: leer*
|
77
|
+
be_a_kind_of: ein_typ*sein
|
78
|
+
be_close: nahe_liegen*
|
79
|
+
be_an_instance_of:
|
80
|
+
eql: glc
|
81
|
+
equal: gleich
|
82
|
+
exist: wesen
|
83
|
+
have: haben
|
84
|
+
have_exactly: genau_haben*
|
85
|
+
have_at_least: mindestens_haben*
|
86
|
+
have_at_most: maximal_haben*
|
87
|
+
include: beinhalten*
|
88
|
+
match: passen*
|
89
|
+
raise_error:
|
90
|
+
satisfy: erfüllen*
|
91
|
+
|
92
|
+
# Please put the right words for this languages! =D
|
93
|
+
|
94
|
+
"es":
|
95
|
+
name: Spanish
|
96
|
+
native: Español
|
97
|
+
|
98
|
+
"en-au":
|
99
|
+
name: Australian
|
100
|
+
native: Australian
|
101
|
+
|
102
|
+
"fr":
|
103
|
+
name: French
|
104
|
+
native: Français
|
105
|
+
|
106
|
+
"ko":
|
107
|
+
name: Korean
|
108
|
+
native: 한국어
|
109
|
+
|
44
110
|
"pt":
|
45
111
|
name: Portuguese
|
46
|
-
native:
|
112
|
+
native: Português
|
47
113
|
describe: descreva|contexto
|
48
114
|
it: isso|isto|especificar|exemplo
|
49
115
|
its: exemplo_do_assunto # I don't know about this word
|
116
|
+
pending: pendente
|
50
117
|
subject: assunto
|
118
|
+
shared_examples_for: exemplos_distribuidos|exemplo_distribuido
|
119
|
+
share_as: distribua_como
|
120
|
+
it_should_behave_like: deve_se_comportar_como
|
51
121
|
should: deve
|
52
122
|
should_not: nao_deve
|
53
123
|
before: antes
|
@@ -76,37 +146,5 @@
|
|
76
146
|
match: corresponder
|
77
147
|
raise_error: mostrar_erro|mostrar_excessao
|
78
148
|
satisfy: satisfazer
|
79
|
-
|
80
|
-
|
81
|
-
"es":
|
82
|
-
name: Spanish
|
83
|
-
native: español
|
84
|
-
describe: describir
|
85
|
-
it: ejemplo
|
86
|
-
its: ejemplo_asunto # I don't know about this word
|
87
|
-
subject: asunto|tema
|
88
|
-
should: deberia
|
89
|
-
should_not: no_debe
|
90
|
-
before: antes
|
91
|
-
after: despues
|
92
|
-
hooks:
|
93
|
-
each: de_cada_ejemplo
|
94
|
-
all: de_todos_ejemplo
|
95
|
-
suite: suite
|
96
|
-
matchers:
|
97
|
-
be:
|
98
|
-
true:
|
99
|
-
be_a_kind_of:
|
100
|
-
be_close:
|
101
|
-
be_an_instance_of:
|
102
|
-
eql:
|
103
|
-
equal:
|
104
|
-
exist:
|
105
|
-
have:
|
106
|
-
have_exactly:
|
107
|
-
have_at_least:
|
108
|
-
have_at_most:
|
109
|
-
include:
|
110
|
-
match:
|
111
|
-
raise_error:
|
112
|
-
satisfy:
|
149
|
+
|
150
|
+
|
data/lib/spec-i18n/matchers.rb
CHANGED
@@ -2,70 +2,57 @@ require 'spec/matchers/dsl'
|
|
2
2
|
|
3
3
|
module Spec
|
4
4
|
module Matchers
|
5
|
-
|
6
|
-
|
7
|
-
def register_be_matcher
|
8
|
-
language = SpecI18n.natural_language
|
9
|
-
be_matcher = language.keywords['matchers']['be']
|
10
|
-
|
11
|
-
# TODO: working with warnings
|
12
|
-
return unless be_matcher
|
5
|
+
|
6
|
+
class << self
|
13
7
|
|
14
|
-
|
15
|
-
|
16
|
-
end
|
17
|
-
end
|
8
|
+
def translate_be_matcher
|
9
|
+
natural_language.keywords_of_be_word.collect { |be_value| alias_method be_value, :be }
|
18
10
|
end
|
19
11
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
!!actual
|
12
|
+
def translate_be_true
|
13
|
+
matcher_be_some(:true).each do |matcher|
|
14
|
+
Spec::Matchers.define(matcher) do
|
15
|
+
match do |actual|
|
16
|
+
!!actual
|
17
|
+
end
|
27
18
|
end
|
28
19
|
end
|
29
20
|
end
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
21
|
+
|
22
|
+
def translate_be_false
|
23
|
+
matcher_be_some(:false).each do |matcher|
|
24
|
+
Spec::Matchers.define(matcher) do
|
25
|
+
match do |actual|
|
26
|
+
!actual
|
27
|
+
end
|
37
28
|
end
|
38
29
|
end
|
39
30
|
end
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
31
|
+
|
32
|
+
def translate_be_nil
|
33
|
+
matcher_be_some(:nil).each do |matcher|
|
34
|
+
Spec::Matchers.define(matcher) do
|
35
|
+
match do |actual|
|
36
|
+
actual.nil?
|
37
|
+
end
|
47
38
|
end
|
48
39
|
end
|
49
40
|
end
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
41
|
+
|
42
|
+
def translate_be_empty
|
43
|
+
matcher_be_some(:empty).each do |matcher|
|
44
|
+
Spec::Matchers.define(matcher) do
|
45
|
+
match do |actual|
|
46
|
+
actual.empty?
|
47
|
+
end
|
57
48
|
end
|
58
49
|
end
|
59
50
|
end
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
end
|
66
|
-
|
67
|
-
def language
|
68
|
-
SpecI18n.natural_language
|
51
|
+
|
52
|
+
def matcher_be_some(option)
|
53
|
+
natural_language.word_be(option.to_s).collect { |word| word.to_sym}
|
54
|
+
end
|
55
|
+
|
69
56
|
end
|
70
57
|
|
71
58
|
end
|
@@ -1,25 +1,41 @@
|
|
1
1
|
module Spec
|
2
2
|
module Matchers
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
return Matchers::
|
13
|
-
|
14
|
-
|
3
|
+
|
4
|
+
# Method Missing that returns Predicate for the respective sym word
|
5
|
+
# Search the translate be word in the languages.yml for the rspec-i18n try
|
6
|
+
# to comunicate with the Rspec
|
7
|
+
#
|
8
|
+
def method_missing(sym, *args, &block) # :nodoc:\
|
9
|
+
matchers = natural_language.keywords['matchers']
|
10
|
+
be_word = matchers['be'] if matchers
|
11
|
+
sym = be_to_english(sym, be_word)
|
12
|
+
return Matchers::BePredicate.new(sym, *args, &block) if be_predicate?(sym)
|
13
|
+
return Matchers::Has.new(sym, *args, &block) if have_predicate?(sym)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Return something true(equivalent) for Be Predicate
|
17
|
+
#
|
18
|
+
def be_predicate?(sym)
|
19
|
+
sym.to_s =~ /^be_/
|
20
|
+
end
|
21
|
+
|
22
|
+
# Return something true(equivalent) for Have predicate
|
23
|
+
#
|
24
|
+
def have_predicate?(sym)
|
25
|
+
sym.to_s =~ /^have_/
|
15
26
|
end
|
16
27
|
|
17
|
-
#
|
18
|
-
#
|
28
|
+
# Transform the word in be for rspec work properly
|
29
|
+
#
|
30
|
+
# be_to_english(:ser_feliz, :ser) # => :be_feliz
|
31
|
+
# be_to_english(:estar_incluso, :estar) # => :be_incluso
|
32
|
+
# be_to_english(:ser_feliz, 'ser|estar') # => :be_feliz
|
33
|
+
#
|
19
34
|
def be_to_english(sym, be_word)
|
20
|
-
be_word = be_word || 'be'
|
21
|
-
|
35
|
+
be_word = be_word || 'be'
|
22
36
|
sym.to_s.gsub(/#{be_word}/, 'be').to_sym
|
23
37
|
end
|
24
|
-
|
38
|
+
alias :to_english :be_to_english
|
39
|
+
|
40
|
+
end
|
25
41
|
end
|
@@ -2,8 +2,7 @@ module Spec
|
|
2
2
|
module Matchers
|
3
3
|
|
4
4
|
def self.register_all_matchers
|
5
|
-
|
6
|
-
["true", "false", "nil", "empty"].each do |matcher|
|
5
|
+
["true", "false", "nil", "empty", "matcher"].each do |matcher|
|
7
6
|
class_eval <<-BE_WORD
|
8
7
|
translate_be_#{matcher}
|
9
8
|
BE_WORD
|
@@ -2,27 +2,53 @@ module Spec
|
|
2
2
|
module Matchers
|
3
3
|
class << self
|
4
4
|
|
5
|
-
RSPEC_MATCHERS = [
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
RSPEC_MATCHERS = [:be_close, :be_an_instance_of, :be_a_kind_of,
|
6
|
+
:eql, :equal, :exist, :have, :have_at_least,
|
7
|
+
:have_at_most, :have_exactly, :include, :match,
|
8
|
+
:raise_error, :satisfy ]
|
9
9
|
|
10
10
|
MATCHERS_WITH_QUESTIONS = [ :eql, :equal ]
|
11
11
|
|
12
|
+
# Translate all the basic matcher for the Natural Language
|
13
|
+
#
|
12
14
|
def translate_basic_matchers
|
13
|
-
language = SpecI18n.natural_language
|
14
15
|
RSPEC_MATCHERS.each do |rspec_matcher|
|
15
|
-
matcher =
|
16
|
-
|
17
|
-
# TODO: Generating warnings for the incomplete languages
|
18
|
-
next unless matcher
|
19
|
-
|
20
|
-
matcher.split('|').map do |matcher_value|
|
21
|
-
alias_method "#{matcher_value}?", "#{rspec_matcher}?" if MATCHERS_WITH_QUESTIONS.include?(rspec_matcher)
|
22
|
-
alias_method matcher_value, rspec_matcher
|
23
|
-
end
|
16
|
+
matcher = natural_language.find_matcher(rspec_matcher)
|
17
|
+
translate_matcher(matcher, rspec_matcher)
|
24
18
|
end
|
25
19
|
end
|
20
|
+
|
21
|
+
# Translate a matcher from a rspec_matcher
|
22
|
+
#
|
23
|
+
# Example:
|
24
|
+
# pt:
|
25
|
+
# matchers:
|
26
|
+
# be_close: estar_proximo
|
27
|
+
# equal: igual
|
28
|
+
#
|
29
|
+
# rspec_matcher = :be_close -> matcher = { "be_close" => ['estar_proximo']}
|
30
|
+
#
|
31
|
+
# rspec_matcher = :equal -> matcher = { "equal" => ['igual']}
|
32
|
+
#
|
33
|
+
# and so on ...
|
34
|
+
#
|
35
|
+
def translate_matcher(matcher, rspec_matcher)
|
36
|
+
matcher[rspec_matcher.to_s].collect do |matcher_value|
|
37
|
+
translate_matcher_with_question(matcher_value, rspec_matcher)
|
38
|
+
alias_method matcher_value, rspec_matcher
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# Translate a method with the '?'
|
43
|
+
#
|
44
|
+
#
|
45
|
+
def translate_matcher_with_question(matcher_value, rspec_matcher)
|
46
|
+
Object.class_eval do
|
47
|
+
alias_method "#{matcher_value}?", "#{rspec_matcher}?" if MATCHERS_WITH_QUESTIONS.include?(rspec_matcher)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
26
51
|
end
|
52
|
+
|
27
53
|
end
|
28
54
|
end
|
@@ -1,83 +1,284 @@
|
|
1
1
|
module SpecI18n
|
2
2
|
module Parser
|
3
3
|
class NaturalLanguage
|
4
|
-
|
5
|
-
|
4
|
+
|
5
|
+
BASIC_KEYWORDS = %w{ name native describe before after it pending subject
|
6
|
+
shared_examples_for share_as it_should_behave_like its should should_not}
|
6
7
|
|
7
|
-
ADVANCED_KEYWORDS = %w{ hooks matchers}
|
8
|
+
ADVANCED_KEYWORDS = %w{ hooks matchers }
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
new(language)
|
12
|
-
end
|
10
|
+
def self.get(language)
|
11
|
+
new(language)
|
13
12
|
end
|
14
13
|
|
15
14
|
attr_reader :keywords
|
16
15
|
|
17
16
|
def initialize(language)
|
18
|
-
|
17
|
+
raise(LanguageNilNotFound, "Language -> nil Not Found") unless language
|
18
|
+
@keywords = NaturalLanguage.find_language(language)
|
19
19
|
raise(LanguageNotFound, "Language #{language.to_s} Not Supported") if @keywords.nil?
|
20
20
|
end
|
21
21
|
|
22
|
+
# Find the language in languages.yml and return all the keywords
|
23
|
+
#
|
24
|
+
def self.find_language(language)
|
25
|
+
SpecI18n::SPEC_LANGUAGES[language]
|
26
|
+
end
|
27
|
+
|
28
|
+
# Return true if the language don't have the basic keywords
|
29
|
+
# to work with rspec-i18n
|
30
|
+
#
|
31
|
+
# portuguese = NaturalLanguage.new('pt') # Assuming Have all the keywords
|
32
|
+
#
|
33
|
+
# portuguese.incomplete? # => false
|
34
|
+
#
|
22
35
|
def incomplete?
|
23
36
|
language_words = BASIC_KEYWORDS.collect { |key| keywords[key].nil? }
|
24
37
|
return true if language_words.include?(true)
|
25
38
|
false
|
26
39
|
end
|
27
40
|
|
41
|
+
# Return the describe word in the languages.yml
|
42
|
+
#
|
28
43
|
def dsl_keywords
|
29
44
|
spec_keywords("describe")
|
30
45
|
end
|
31
|
-
|
46
|
+
|
47
|
+
# Return the should and should_not words in the languages.yml
|
48
|
+
#
|
32
49
|
def expectation_keywords
|
33
|
-
|
34
|
-
language_adverbs.merge(spec_keywords("should_not"))
|
50
|
+
spec_keywords("should").merge(spec_keywords("should_not"))
|
35
51
|
end
|
36
52
|
|
53
|
+
# Return the before and after words in the languages.yml
|
54
|
+
#
|
37
55
|
def before_and_after_keywords
|
38
|
-
|
39
|
-
|
56
|
+
spec_keywords('before').merge(spec_keywords('after'))
|
57
|
+
end
|
58
|
+
|
59
|
+
# Return All the Hooks in the languages.yml
|
60
|
+
# If not have hooks return a empty Hash
|
61
|
+
#
|
62
|
+
# The hooks in the rspec is the argument for before and after method
|
63
|
+
#
|
64
|
+
# hook hook
|
65
|
+
# \ /
|
66
|
+
# before(:each) after(:all)
|
67
|
+
#
|
68
|
+
def hooks
|
69
|
+
keywords['hooks'] || {}
|
40
70
|
end
|
41
71
|
|
72
|
+
# Return all the hooks words in the languages.yml in a Hash of Arrays
|
73
|
+
#
|
42
74
|
def hooks_params_keywords
|
43
|
-
|
44
|
-
|
45
|
-
values = value
|
46
|
-
|
75
|
+
hooks_keywords = {}
|
76
|
+
hooks.each do |hook, value|
|
77
|
+
values = split_word(value)
|
78
|
+
hooks_keywords[hook] = values
|
47
79
|
end
|
48
|
-
|
80
|
+
hooks_keywords
|
49
81
|
end
|
50
82
|
|
83
|
+
# Returns the combination of before and after with hooks keywords
|
84
|
+
#
|
85
|
+
#
|
86
|
+
def hooks_permutation
|
87
|
+
permutation = {}
|
88
|
+
before_and_after_keywords.each do |before_keyword, before_translated|
|
89
|
+
hooks.each do |hook_keyword, hook_translated|
|
90
|
+
words = split_word(hook_translated)
|
91
|
+
translation = words.collect { |word| before_translated.collect { |keyword| "#{keyword}(:#{word})" } }.flatten
|
92
|
+
permutation["#{before_keyword}(:#{hook_keyword})"] = translation
|
93
|
+
end
|
94
|
+
end
|
95
|
+
permutation
|
96
|
+
end
|
97
|
+
|
98
|
+
# Return the it word in the languages.yml
|
99
|
+
#
|
51
100
|
def example_group_keywords
|
52
101
|
spec_keywords("it")
|
53
102
|
end
|
54
103
|
|
104
|
+
# Return the subject word in the languages.yml
|
105
|
+
#
|
55
106
|
def subject_keywords
|
56
107
|
adverbs = spec_keywords('subject')
|
57
108
|
end
|
58
109
|
|
110
|
+
# Return the its keywords in the languages.yml
|
111
|
+
#
|
59
112
|
def its_keywords
|
60
113
|
spec_keywords("its")
|
61
114
|
end
|
62
115
|
|
116
|
+
# Return All the Matchers in the languages.yml
|
117
|
+
#
|
118
|
+
def matchers
|
119
|
+
keywords["matchers"] || {}
|
120
|
+
end
|
121
|
+
|
122
|
+
# Return the shared examples for words in the languages.yml
|
123
|
+
#
|
124
|
+
def shared_examples_for_keywords
|
125
|
+
spec_keywords('shared_examples_for')
|
126
|
+
end
|
127
|
+
|
128
|
+
# Return the share_as words in the languages.yml
|
129
|
+
#
|
130
|
+
def share_as_keywords
|
131
|
+
spec_keywords('share_as')
|
132
|
+
end
|
133
|
+
|
134
|
+
# Return the it should behave like words in the languages.yml
|
135
|
+
#
|
136
|
+
def it_should_behave_like_keywords
|
137
|
+
spec_keywords('it_should_behave_like')
|
138
|
+
end
|
139
|
+
|
140
|
+
# Return the pending words in the languages.yml
|
141
|
+
#
|
142
|
+
def pending_keywords
|
143
|
+
spec_keywords('pending')
|
144
|
+
end
|
145
|
+
|
146
|
+
# Find the matcher and return the words in the languages.yml
|
147
|
+
#
|
148
|
+
# pt: matchers: equal: igual|igual_a
|
149
|
+
# NaturalLanguage.new('pt').find_matcher('equal') # => { 'equal' => ['igual', 'igual_a']}
|
150
|
+
#
|
151
|
+
def find_matcher(matcher)
|
152
|
+
matcher = matcher.to_s
|
153
|
+
matcher_and_values = {}
|
154
|
+
matcher_and_values[matcher] = split_word(matchers[matcher])
|
155
|
+
matcher_and_values
|
156
|
+
end
|
157
|
+
|
158
|
+
# Return the keywords of be_* matchers in the languages.yml
|
159
|
+
#
|
160
|
+
# pt:
|
161
|
+
# matchers:
|
162
|
+
# be: ser
|
163
|
+
# true_word: verdadeiro|verdade
|
164
|
+
#
|
165
|
+
# NaturalLanguage.new('pt').word_be('true') # => ['ser_verdadeiro', 'ser_verdade']
|
166
|
+
#
|
63
167
|
def word_be(ruby_type)
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
168
|
+
ruby_type_matchers = matchers ? split_word(matchers["#{ruby_type}_word"]) : []
|
169
|
+
words = keywords_of_be_word.collect do |matcher_be|
|
170
|
+
invert_or_not_ruby_type_mathers(matcher_be, ruby_type_matchers)
|
171
|
+
end
|
172
|
+
words.flatten
|
69
173
|
end
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
174
|
+
|
175
|
+
# Return the be words in the languages.yml
|
176
|
+
# If not have any matchers return a empty Array
|
177
|
+
#
|
178
|
+
def keywords_of_be_word
|
179
|
+
return split_word(matchers['be']) if matchers
|
180
|
+
end
|
181
|
+
|
182
|
+
# Return true if the keyword has the '*' character in the last position
|
183
|
+
#
|
184
|
+
# de:
|
185
|
+
# matchers:
|
186
|
+
# true_word: wahr*
|
187
|
+
#
|
188
|
+
# @germany = NaturalLanguage.new('de')
|
189
|
+
# @germany.invert_order_of_object_and_verbs?(matchers['true_word']) # => true
|
190
|
+
#
|
191
|
+
# pt:
|
192
|
+
# matchers:
|
193
|
+
# true_word: verdadeiro
|
194
|
+
#
|
195
|
+
# @portuguese = NaturalLanguage.new('pt')
|
196
|
+
# @portuguese.invert_order_of_object_and_verbs?(matchers['true_word']) # => false
|
197
|
+
#
|
198
|
+
def invert_order_of_object_and_verbs?(keyword)
|
199
|
+
return true if keyword.to_s.include?('*')
|
200
|
+
false
|
201
|
+
end
|
202
|
+
|
203
|
+
# PENDENCIA - SPEC THIS
|
204
|
+
#
|
205
|
+
def invert_or_not_ruby_type_mathers(matcher_be, ruby_type_matchers)
|
206
|
+
ruby_type_matchers.collect do |matcher|
|
207
|
+
if invert_order_of_object_and_verbs?(matcher)
|
208
|
+
invert_order(:first => matcher, :second => matcher_be)
|
209
|
+
else
|
210
|
+
"#{matcher_be}_#{matcher}"
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
def invert_order(options={})
|
216
|
+
options.each { |key, value| options[key] = value.delete('*') }
|
217
|
+
"#{options[:first]}_#{options[:second]}"
|
218
|
+
end
|
219
|
+
|
220
|
+
# Return the values from keywords
|
221
|
+
#
|
222
|
+
# @pt.values_from_keywords('hooks') # => {'all'=>'todos','each'=>'cada'}
|
223
|
+
#
|
224
|
+
def values_from_keywords(keyword)
|
225
|
+
unless keywords[keyword]
|
226
|
+
{}
|
227
|
+
else
|
228
|
+
keywords[keyword]
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
def basic_keywords
|
233
|
+
keywords.reject { |keyword, translated| include_in_advanced_keywords?(keyword) }
|
234
|
+
end
|
235
|
+
|
236
|
+
def advanced_keywords
|
237
|
+
keywords.reject { |keyword, translated| not_include_in_advanced_keywords?(keyword) }
|
238
|
+
end
|
239
|
+
|
240
|
+
# Return the words of languages.yml in a Hash with Array values
|
241
|
+
#
|
242
|
+
# pt:
|
243
|
+
# describe: descreva|descrevendo
|
244
|
+
#
|
245
|
+
# NaturalLanguage.new('pt').spec_keywords('describe') # => { 'describe' => ['descreva', 'descrevendo']}
|
246
|
+
#
|
247
|
+
# fr:
|
248
|
+
# should:
|
249
|
+
#
|
250
|
+
# NaturalLanguage.new('fr').spec_keywords('should') # => { 'should' => [] }
|
251
|
+
#
|
252
|
+
#
|
253
|
+
# NaturalLanguage.new('es').spec_keywords('key_not_found') # => RuntimeError: "No key_not_found in #{keywords}"
|
254
|
+
#
|
255
|
+
def spec_keywords(key)
|
256
|
+
return { key => [] } unless keywords[key]
|
257
|
+
values = split_word(keywords[key])
|
74
258
|
{ key => values }
|
75
259
|
end
|
260
|
+
|
261
|
+
private
|
262
|
+
|
263
|
+
def split_word(word)
|
264
|
+
word.to_s.split("|")
|
265
|
+
end
|
266
|
+
|
267
|
+
def include_in_advanced_keywords?(keyword)
|
268
|
+
ADVANCED_KEYWORDS.include?(keyword)
|
269
|
+
end
|
270
|
+
|
271
|
+
def not_include_in_advanced_keywords?(keyword)
|
272
|
+
!ADVANCED_KEYWORDS.include?(keyword)
|
273
|
+
end
|
76
274
|
|
77
275
|
end
|
78
276
|
|
79
277
|
class LanguageNotFound < StandardError
|
80
278
|
end
|
279
|
+
|
280
|
+
class LanguageNilNotFound < StandardError
|
281
|
+
end
|
81
282
|
|
82
283
|
end
|
83
284
|
end
|