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
@@ -5,19 +5,17 @@ module Spec
5
5
  describe "eql" do
6
6
 
7
7
  before(:each) do
8
- @expected_matcher = {'matchers' => {'eql' => 'igl'}}
9
- portuguese_language(@expected_matcher)
8
+ @keywords = {'matchers' => {'eql' => 'igl'}}
9
+ stub_language!("pt", @keywords)
10
10
  Spec::Matchers.register_all_matchers
11
11
  end
12
12
 
13
13
  it "should have eql matchers translated" do
14
- eql_word = @expected_matcher['matchers']['eql']
15
- 1.methods.should be_include(eql_word)
14
+ methods.to_symbols.should include(:igl)
16
15
  end
17
16
 
18
17
  it "should have eql? matchers translated" do
19
- eql_word = @expected_matcher['matchers']['eql'] + '?'
20
- 1.methods.should be_include(eql_word)
18
+ methods.to_symbols.should include(:igl?)
21
19
  end
22
20
 
23
21
  it "should match when actual.eql?(expected)" do
@@ -2,25 +2,46 @@ require "spec_helper"
2
2
 
3
3
  module Spec
4
4
  module Matchers
5
+
5
6
  describe 'equal' do
7
+
6
8
  before(:each) do
7
- @expected_matcher = {'matchers' => {'equal' => 'igual|igual_a'}}
8
- portuguese_language(@expected_matcher)
9
+ @keywords = {'matchers' => {'equal' => 'igual|igual_a'}}
10
+ stub_language!("pt", @keywords)
9
11
  Spec::Matchers.register_all_matchers
10
12
  end
11
13
 
12
- it 'should register the methods for the value equal matcher' do
13
- values = @expected_matcher['matchers']['equal'].split('|')
14
- values.each { |method_name| Object.instance_methods.should be_include(method_name) }
14
+ it 'should translated the methods for the value equal matcher' do
15
+ [:igual, :igual_a].each do |translated_matcher|
16
+ methods.to_symbols.should include(translated_matcher)
17
+ end
18
+ end
19
+
20
+ it "should translated the methods with '?' char" do
21
+ [:igual?, :igual_a?].each do |translated_method|
22
+ methods.to_symbols.should include(translated_method)
23
+ end
15
24
  end
16
25
 
17
26
  it "should match when actual.equal?(expected)" do
18
27
  1.should igual(1)
19
28
  end
20
-
29
+
30
+ it "should be true when actual.equal?(expected) with ?" do
31
+ 1.igual?(1).should be_true
32
+ 1.should be_igual(1)
33
+ end
34
+
21
35
  it "should not match when !actual.equal?(expected)" do
22
- 1.should_not igual_a("1")
36
+ 1.should_not be_igual_a("1")
23
37
  end
38
+
39
+ it "should not match when !actual.equal?(expected) with ?" do
40
+ 1.igual_a?(1).should be_true
41
+ 1.should be_igual_a(1)
42
+ end
43
+
24
44
  end
45
+
25
46
  end
26
47
  end
@@ -17,17 +17,16 @@ module Spec
17
17
  describe "exist matcher" do
18
18
 
19
19
  before(:each) do
20
- @expected_matcher = {'matchers' => {'exist' => 'existir'}}
21
- portuguese_language(@expected_matcher)
20
+ @keywords = {'matchers' => {'exist' => 'existir|existe'}}
21
+ stub_language!("pt", @keywords)
22
22
  Spec::Matchers.register_all_matchers
23
23
  @real = Substance.new true, 'something real'
24
24
  @imaginary = Substance.new false, 'something imaginary'
25
25
  end
26
26
 
27
27
  it 'should register the exist method translated' do
28
- values = @expected_matcher['matchers']['exist'].split('|')
29
- values.each do |value_method|
30
- Object.instance_methods.should be_include(value_method)
28
+ [:existir, :existe].each do |translated_matcher|
29
+ methods.to_symbols.should include(translated_matcher)
31
30
  end
32
31
  end
33
32
 
@@ -7,7 +7,7 @@ describe 'have, have_exactly, have_at_least and have_at_most matcher' do
7
7
  'have_exactly' => 'ter_exatamente',
8
8
  'have_at_most' => 'ter_no_maximo'}
9
9
  @expected_matcher = {'matchers' => matchers}
10
- portuguese_language(@expected_matcher)
10
+ stub_language!("pt", @expected_matcher)
11
11
  Spec::Matchers.register_all_matchers
12
12
  end
13
13
 
@@ -1,19 +1,17 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "should include(expected)" do
4
+
4
5
  before(:each) do
5
- @expected_matcher = {'matchers' => { 'include' => 'incluir'} }
6
- portuguese_language(@expected_matcher)
7
- Spec::Matchers.register_all_matchers
6
+ @keywords = { 'matchers' => {'include' => 'incluir|incluso'} }
7
+ stub_language!("pt", @keywords)
8
+ Spec::Matchers.translate_basic_matchers
8
9
  end
9
10
 
10
11
  it "should translated the include matcher" do
11
- values = @expected_matcher['matchers']['include'].split('|')
12
-
13
- values.each do |value_method|
14
- Object.instance_methods.should be_include(value_method)
12
+ ["incluir", "incluso"].each do |value_method|
13
+ methods.all_to_symbols.should be_include(value_method.to_sym)
15
14
  end
16
-
17
15
  end
18
16
 
19
17
  it "should pass if target includes expected" do
@@ -2,15 +2,14 @@ require 'spec_helper'
2
2
 
3
3
  describe "should match(expected)" do
4
4
  before(:each) do
5
- @expected_matcher = {'matchers' => { 'match' => 'corresponder'} }
6
- portuguese_language(@expected_matcher)
5
+ @expected_matcher = {'matchers' => { 'match' => 'corresponder|corresponde'} }
6
+ stub_language!("pt", @expected_matcher)
7
7
  Spec::Matchers.register_all_matchers
8
8
  end
9
9
 
10
10
  it "should translated the include matcher" do
11
- values = @expected_matcher['matchers']['match'].split('|')
12
- values.each do |value_method|
13
- Object.instance_methods.should be_include(value_method)
11
+ [:corresponder, :corresponde].each do |translated_matcher|
12
+ methods.to_symbols.should include(translated_matcher)
14
13
  end
15
14
  end
16
15
 
@@ -3,14 +3,15 @@ require 'spec_helper'
3
3
  describe "should raise_error" do
4
4
 
5
5
  before(:each) do
6
- @expected_matcher = {'matchers' => {'raise_error' => 'mostrar_erro'}}
7
- portuguese_language(@expected_matcher)
6
+ @expected_matcher = {'matchers' => {'raise_error' => 'mostrar_erro|mostrar_excessao'}}
7
+ stub_language!("pt", @expected_matcher)
8
8
  Spec::Matchers.register_all_matchers
9
9
  end
10
10
 
11
11
  it 'should register the methods for the value equal matcher' do
12
- values = @expected_matcher['matchers']['raise_error'].split('|')
13
- values.each { |method_name| Object.instance_methods.should be_include(method_name) }
12
+ [:mostrar_erro, :mostrar_excessao].each do |translated_matcher|
13
+ methods.to_symbols.should include(translated_matcher)
14
+ end
14
15
  end
15
16
 
16
17
  it "should pass if anything is raised" do
@@ -3,15 +3,14 @@ require 'spec_helper'
3
3
  describe "should satisfy { block }" do
4
4
 
5
5
  before(:each) do
6
- @expected_matcher = { 'matchers' => { 'satisfy' => 'satisfazer'} }
7
- portuguese_language(@expected_matcher)
6
+ @keywords = { 'matchers' => { 'satisfy' => 'satisfazer|satisfaz'} }
7
+ stub_language!("pt", @keywords)
8
8
  Spec::Matchers.register_all_matchers
9
9
  end
10
10
 
11
11
  it 'should trasnlate the satisfy matcher' do
12
- values = @expected_matcher['matchers']['satisfy'].split('|')
13
- values.each do |value_method|
14
- Object.instance_methods.should be_include(value_method)
12
+ [:satisfazer, :satisfazer].each do |translated_matcher|
13
+ methods.to_symbols.should include(translated_matcher)
15
14
  end
16
15
  end
17
16
 
@@ -5,18 +5,14 @@ module SpecI18n
5
5
  describe NaturalLanguage do
6
6
 
7
7
  before(:each) do
8
- @pt = NaturalLanguage.get('pt')
9
- @es = NaturalLanguage.get('es')
10
- @en = NaturalLanguage.get('en')
8
+ @pt = NaturalLanguage.new('pt')
9
+ @es = NaturalLanguage.new('es')
10
+ @en = NaturalLanguage.new('en')
11
+ @germany = NaturalLanguage.new('de')
12
+ @portuguese = @pt
13
+ @spanish = @es
11
14
  end
12
-
13
- %w(describe before after it should name native).each do |keyword|
14
- it "should have the #{keyword} keyword" do
15
- portuguese_keys = @pt.keywords.keys
16
- portuguese_keys.should include(keyword)
17
- end
18
- end
19
-
15
+
20
16
  context "get languages" do
21
17
 
22
18
  it "should get the default language" do
@@ -27,7 +23,13 @@ module SpecI18n
27
23
  language = "non_existing"
28
24
  lambda {
29
25
  NaturalLanguage.new(language)
30
- }.should raise_error(LanguageNotFound, "Language #{language} Not Supported")
26
+ }.should raise_exception(LanguageNotFound, "Language #{language} Not Supported")
27
+ end
28
+
29
+ it "should raise a error for the NIL language" do
30
+ lambda {
31
+ NaturalLanguage.new(nil)
32
+ }.should raise_exception(LanguageNilNotFound, "Language -> nil Not Found")
31
33
  end
32
34
 
33
35
  end
@@ -39,19 +41,29 @@ module SpecI18n
39
41
  end
40
42
 
41
43
  it "should return true for the incomplete language" do
42
- @pt.stub!(:keywords).and_return({ :name => []})
44
+ @pt.stub!(:keywords).and_return({})
43
45
  @pt.incomplete?.should be_true
44
46
  end
45
-
47
+
46
48
  end
47
49
 
48
50
  context "of dsl keywords" do
49
51
 
50
52
  it "should return the describe dsl keyword" do
51
- lang = { "describe" => "descreva", :before => "antes" }
52
- @pt.should_receive(:keywords).at_least(:once).and_return(lang)
53
- @pt.dsl_keywords.should == { "describe" => [ lang["describe"] ] }
53
+ stub_keywords!(@portuguese, { "describe" => "descreva", :before => "antes" })
54
+ @portuguese.dsl_keywords.should == { "describe" => [ 'descreva' ] }
55
+ end
56
+
57
+ it "should return a empty Array whe dont have keywords" do
58
+ stub_keywords!(@portuguese, {})
59
+ @portuguese.dsl_keywords.should == { 'describe' => [] }
60
+ end
61
+
62
+ it "should return a empty Array when describe keyword is nil" do
63
+ stub_keywords!(@portuguese, { 'describe' => nil})
64
+ @portuguese.dsl_keywords.should == {'describe' => []}
54
65
  end
66
+
55
67
  end
56
68
 
57
69
  context "of expectations keywords" do
@@ -67,32 +79,33 @@ module SpecI18n
67
79
  end
68
80
 
69
81
  it "should return the expectation keywords of the current language" do
70
- keywords = { "should" => ["deberia"], "should_not" => ["no_debe"]}
71
- @es.expectation_keywords.should == keywords
82
+ keywords = { "should" => "deberia", "should_not" => "no_debe"}
83
+ @es.should_receive(:keywords).at_least(:once).and_return(keywords)
84
+ @es.expectation_keywords.should == { 'should' => ['deberia'], 'should_not' => ['no_debe']}
72
85
  end
86
+
73
87
  end
74
88
 
75
- context "of before and after keywords" do
76
-
77
- before(:each) do
78
- @language = { "before" => "before", "after" => "after"}
79
- end
80
-
89
+ describe "#before_and_after_keywords" do
90
+
81
91
  it "should return the hooks for the current language" do
82
- @en.should_receive(:keywords).at_least(:once).and_return(@language)
83
- keywords = { "before" => ["before"], "after" => ["after"]}
84
- @en.before_and_after_keywords.should == keywords
92
+ stub_keywords!(@en, { "before" => "before", "after" => "after"})
93
+ @en.before_and_after_keywords.should == { "before" => ["before"], "after" => ["after"]}
85
94
  end
86
95
 
87
96
  it "should return the hooks for the language" do
88
- language = {"before" => "antes", "after" => "depois"}
89
- keywords = { "before" => ["antes"], "after" => ["depois"]}
90
- @pt.stub!(:keywords).and_return(language)
91
- @pt.before_and_after_keywords.should == keywords
97
+ stub_keywords!(@portuguese, {"before" => "antes", "after" => "depois"})
98
+ @portuguese.before_and_after_keywords.should == { "before" => ["antes"], "after" => ["depois"]}
99
+ end
100
+
101
+ it "should not raise a error when not have before and after keyword" do
102
+ stub_keywords!(@portuguese, {})
103
+ @portuguese.before_and_after_keywords.should == {'before' => [], 'after' => []}
92
104
  end
105
+
93
106
  end
94
107
 
95
- context "of hooks keywords" do
108
+ context "#hooks" do
96
109
 
97
110
  before(:each) do
98
111
  @lang = { "hooks" => {"each" => "de_cada|de_cada_exemplo",
@@ -104,11 +117,56 @@ module SpecI18n
104
117
  end
105
118
 
106
119
  it "should return the hooks parameters for the current language" do
107
- @pt.stub!(:keywords).and_return(@lang)
108
- @pt.hooks_params_keywords.should == @keywords
120
+ stub_keywords!(@portuguese, @lang)
121
+ @portuguese.hooks_params_keywords.should == @keywords
122
+ end
123
+
124
+ it "should return something when not have hooks" do
125
+ stub_keywords!(@portuguese, {})
126
+ @portuguese.hooks_params_keywords.should == {}
109
127
  end
128
+
110
129
  end
111
130
 
131
+ describe "#hooks_permutation" do
132
+
133
+ it "should return a Hash of possibilities" do
134
+ stub_keywords!(@portuguese, {'before' => 'antes', 'hooks' => {'each' => 'cada|de_cada'}})
135
+ @portuguese.hooks_permutation.should include({ 'before(:each)' => ['antes(:cada)', 'antes(:de_cada)']})
136
+ end
137
+
138
+ it "should return a before in Hash keys" do
139
+ stub_keywords!(@portuguese, {'before' => 'antes', 'hooks' => {'each' => 'de_cada' , 'all' => 'de_todos'}})
140
+ @portuguese.hooks_permutation.should include({ 'before(:each)' => ['antes(:de_cada)'], 'before(:all)' => ['antes(:de_todos)'] })
141
+ end
142
+
143
+ it "should return a after in Hash" do
144
+ stub_keywords!(@portuguese, { 'after' => 'depois', 'hooks' => {'each' => 'cada'} })
145
+ @portuguese.hooks_permutation.should include({ 'after(:each)' => ['depois(:cada)'] })
146
+ end
147
+
148
+ it "should return a empty Hash when not have hooks" do
149
+ stub_keywords!(@portuguese, {'after' => 'depois', 'before' => 'antes'})
150
+ @portuguese.hooks_permutation.should == {}
151
+ end
152
+
153
+ it "should return a various keys for varius before words" do
154
+ stub_keywords!(@portuguese, {'after' => 'depois|ah_depois', 'hooks' => {'each' => 'cada'}})
155
+ @portuguese.hooks_permutation.should include({'after(:each)' => ['depois(:cada)', 'ah_depois(:cada)']})
156
+ end
157
+
158
+ it "should return a empty Hash when not have before and after keywords" do
159
+ stub_keywords!(@portuguese, {})
160
+ @portuguese.hooks_permutation.should == {}
161
+ end
162
+
163
+ it "should return a empty Hash when have nil values for before and after keywords" do
164
+ stub_keywords!(@portuguese, {'before' => nil, 'after' => nil})
165
+ @portuguese.hooks_permutation.should == {}
166
+ end
167
+
168
+ end
169
+
112
170
  context "of example group keywords" do
113
171
 
114
172
  before(:each) do
@@ -131,12 +189,12 @@ module SpecI18n
131
189
  end
132
190
 
133
191
  it 'should return the subject keywords' do
134
- @pt.stub!(:keywords).and_return(@keywords)
192
+ @pt.should_receive(:keywords).at_least(:once).and_return(@keywords)
135
193
  @pt.subject_keywords.should == {'subject' => ["assunto", "tema"]}
136
194
  end
137
195
 
138
196
  it 'should return the subject keywords for spanish language' do
139
- @spanish_keywords.stub!(:keywords).and_return(@spanish_keywords)
197
+ @es.should_receive(:keywords).at_least(:once).and_return(@spanish_keywords)
140
198
  @es.subject_keywords.should == { 'subject' => ['asunto', 'tema']}
141
199
  end
142
200
  end
@@ -159,12 +217,137 @@ module SpecI18n
159
217
  end
160
218
  end
161
219
 
220
+ context 'matchers' do
221
+
222
+ before(:each) do
223
+ @keywords = { "matchers" => { "be" => "ser",
224
+ "include" => "incluir|incluso", "be_close" => nil}}
225
+ end
226
+
227
+ it "should return an hash of matchers" do
228
+ stub_keywords!(@pt, @keywords)
229
+ @pt.matchers.should == @keywords["matchers"]
230
+ end
231
+
232
+ it "should return an empty hash for non exist matchers" do
233
+ stub_keywords!(@portuguese, {'name' => 'Portuguese'})
234
+ @portuguese.matchers.should eql({})
235
+ end
236
+
237
+ it "should find a matcher that exist" do
238
+ stub_keywords!(@pt, @keywords)
239
+ @pt.find_matcher(:include).should == { "include" => ["incluir", "incluso"]}
240
+ end
241
+
242
+ it "should return a hash with empty value for the empty value of matcher" do
243
+ stub_keywords!(@pt, @keywords)
244
+ @pt.find_matcher(:be_close).should == {"be_close" => []}
245
+ end
246
+
247
+ end
248
+
249
+ context 'hooks' do
250
+
251
+ it "should return a empty Hash when not have hooks" do
252
+ stub_keywords!(@portuguese, {'name' => 'Portuguese'})
253
+ @portuguese.hooks.should eql({})
254
+ end
255
+
256
+ it "should return all the hooks" do
257
+ stub_keywords!(@portuguese, {'hooks' => { 'each' => 'cada'}})
258
+ @portuguese.hooks.should eql({'each' => 'cada'})
259
+ end
260
+
261
+ it "should return the hooks with | separator in a string" do
262
+ stub_keywords!(@portuguese, {'hooks' => {'all' => 'todos|de_todos'}})
263
+ @portuguese.hooks.should eql({'all' => 'todos|de_todos'})
264
+ end
265
+
266
+ end
267
+
268
+ context 'shared examples keywords' do
269
+
270
+ before(:each) do
271
+ @keywords = { 'shared_examples_for' => 'exemplos_distribuidos|distribuido',
272
+ 'it_should_behave_like' => 'deve_se_comportar_como|deve_se_comportar',
273
+ 'share_as' => 'distribua|distribua_como' }
274
+ stub_keywords!(@pt, @keywords)
275
+ end
276
+
277
+ it "should return the words for shared examples for separated by '|'" do
278
+ expected = {"shared_examples_for" => ['exemplos_distribuidos', 'distribuido']}
279
+ @pt.shared_examples_for_keywords.should ==(expected)
280
+ end
281
+
282
+ it "should return the words for it should behave like keyword" do
283
+ expected = {"it_should_behave_like" => ['deve_se_comportar_como', 'deve_se_comportar']}
284
+ @pt.it_should_behave_like_keywords.should ==(expected)
285
+ end
286
+
287
+ it "should return the words for shares as keyword" do
288
+ expected = { 'share_as' => ['distribua', 'distribua_como']}
289
+ @pt.share_as_keywords.should == expected
290
+ end
291
+
292
+ end
293
+
294
+ context 'when pending keywords' do
295
+
296
+ it "should return the pending keywords" do
297
+ @keywords = { 'pending' => 'pendente|pendencia' }
298
+ stub_keywords!(@pt, @keywords)
299
+ @pt.pending_keywords.should == { 'pending' => ['pendente', 'pendencia']}
300
+ end
301
+
302
+ it "should return the pending keywords for languages" do
303
+ @keywords = { 'pending' => 'spec_pendente'}
304
+ stub_keywords!(@es, @keywords)
305
+ @es.pending_keywords.should == { 'pending' => ['spec_pendente']}
306
+ end
307
+
308
+ end
309
+
310
+ context "be keyword" do
311
+
312
+ it "should return an array with values of be word" do
313
+ stub_keywords!(@pt, { "matchers" => { "be" => "ser|estar" }})
314
+ @pt.keywords_of_be_word.should == ["ser", "estar"]
315
+ end
316
+
317
+ it "should return a empty array for matchers withou be keyword" do
318
+ stub_keywords!(@portuguese, {'matchers' => { 'eql' => 'igl'}})
319
+ @portuguese.keywords_of_be_word.should == []
320
+ end
321
+
322
+ it "should return a empty array for non found keyword" do
323
+ stub_keywords!(@pt, {})
324
+ @pt.keywords_of_be_word.should == []
325
+ end
326
+
327
+ end
328
+
162
329
  context "splitting the keys" do
330
+
163
331
  it "should raise no found key" do
164
332
  lambda {
165
- @pt.spec_keywords("no_found")
333
+ @pt.spec_keywords("no_found")
334
+ }.should_not raise_exception(RuntimeError)
335
+ end
336
+
337
+ it "should raise exception for not found key" do
338
+ lambda {
166
339
  @pt.spec_keywords("Oh_MY_this_words_is_not_found!")
167
- }.should raise_error(RuntimeError)
340
+ }.should_not raise_exception(RuntimeError)
341
+ end
342
+
343
+ it "should return a Hash of Array values" do
344
+ @portuguese.spec_keywords('something_that_dont_exist').should == {'something_that_dont_exist' => []}
345
+ end
346
+
347
+ it "should not raise error for key found but key is nil" do
348
+ lang = { 'describe' => nil}
349
+ @pt.stub!(:keywords).and_return(lang)
350
+ @pt.spec_keywords("describe").should == { 'describe' => []}
168
351
  end
169
352
 
170
353
  it "should split correctly the keys" do
@@ -174,33 +357,212 @@ module SpecI18n
174
357
  end
175
358
  end
176
359
 
177
- context "be_true, be_false and be_nil" do
360
+ describe "when word be" do
178
361
 
179
- it "should return all the be_true possibilities" do
180
- lang = { "matchers" => { 'be' => 'ser|outro_ser', 'true_word' => 'verdade|verdadeiro'}}
181
- expected_words = ["ser_verdadeiro", "ser_verdade", "outro_ser_verdade","outro_ser_verdadeiro"]
182
- @pt.stub!(:keywords).and_return(lang)
183
- expected_words.each do |expected|
184
- @pt.word_be("true").should include expected
362
+ context 'when be true keyword' do
363
+
364
+ it "should return all the be_true possibilities" do
365
+ keywords = { "matchers" => { 'be' => 'ser|outro_ser', 'true_word' => 'verdade|verdadeiro'} }
366
+ stub_keywords!(@pt, keywords)
367
+ @pt.word_be("true").should eql(["ser_verdade", "ser_verdadeiro", "outro_ser_verdade","outro_ser_verdadeiro"])
368
+ end
369
+
370
+ it "should return all the be_true possibilities inverted" do
371
+ keywords = { 'matchers' => { 'be' => 'sein', 'true_word' => 'wahr*' }}
372
+ stub_keywords!(@germany, keywords)
373
+ @germany.word_be('true').should eql(['wahr_sein'])
374
+ end
375
+
376
+ it "should return a empty array for the non keyword" do
377
+ keywords = {}
378
+ stub_keywords!(@germany, keywords)
379
+ @germany.word_be('true').should eql []
380
+ end
381
+
382
+ it "should return a empty array for the nil be keyword" do
383
+ keywords = { 'matchers' => { 'be' => nil, 'true' => nil }}
384
+ stub_keywords!(@germany, keywords)
385
+ @germany.word_be('true').should eql []
185
386
  end
387
+
388
+ it "should return a empty array for the nil true keyword" do
389
+ keywords = { 'matchers' => { 'be' => 'sein', 'true' => nil}}
390
+ stub_keywords!(@germany, keywords)
391
+ @germany.word_be('true').should eql []
392
+ end
393
+
186
394
  end
187
395
 
188
- it "should return all the be_nil possibilities" do
189
- lang = { "matchers" => { 'be' => 'ser|outro_ser', 'nil_word' => 'nulo|muito_nulo'}}
190
- expected_words = ["ser_nulo", "ser_muito_nulo"]
191
- @pt.stub!(:keywords).and_return(lang)
192
- expected_words.each do |expected|
193
- @pt.word_be("nil").should include expected
396
+ context 'when be nil keyword' do
397
+
398
+ it "should return all the be_nil possibilities" do
399
+ @pt_keywords = { "matchers" => { 'be' => 'ser|outro_ser', 'nil_word' => 'nulo|muito_nulo'}}
400
+ stub_keywords!(@pt, @pt_keywords)
401
+ @pt.word_be("nil").should eql(["ser_nulo", "ser_muito_nulo", "outro_ser_nulo", "outro_ser_muito_nulo"])
402
+ end
403
+
404
+ it "should return all the be_nil possibilities for the inverted keyword" do
405
+ keywords = { 'matchers' => { 'be' => 'sein', 'nil_word' => "null*" }}
406
+ stub_keywords!(@germany, keywords)
407
+ @germany.word_be('nil').should eql(['null_sein'])
408
+ end
409
+
410
+ it "should return a empty array for the non matchers keyword" do
411
+ keywords = {}
412
+ stub_keywords!(@es, keywords)
413
+ @es.word_be('nil').should eql []
414
+ end
415
+
416
+ it "should return a empty array for the non be keyword" do
417
+ keywords = { 'matchers' => { 'be' => nil, 'nil' => nil }}
418
+ stub_keywords!(@en, keywords)
419
+ @en.word_be('nil').should eql []
194
420
  end
421
+
422
+ it "should return a empty array for the non nil keyword" do
423
+ keywords = { 'matchers' => { 'be' => 'ser', 'nil' => nil }}
424
+ stub_keywords!(@pt, keywords)
425
+ @pt.word_be('nil').should eql []
426
+ end
427
+
195
428
  end
196
429
 
197
- it "should return all the be_false possibilities" do
198
- lang = { "matchers" => { 'be' => 'ser|outro_ser', 'false_word' => 'falso|muito_falso'}}
199
- expected_words = ["ser_falso", "ser_muito_falso"]
200
- @pt.stub!(:keywords).and_return(lang)
201
- expected_words.each do |expected|
202
- @pt.word_be("false").should include expected
430
+ context 'when be false keyword' do
431
+
432
+ it "should return all the be_false possibilities" do
433
+ @pt_keywords = { 'matchers' => { 'be' => 'ser|outro_ser', 'false_word' => 'falso|muito_falso'}}
434
+ stub_keywords!(@pt, @pt_keywords)
435
+ @pt.word_be("false").should eql(["ser_falso", "ser_muito_falso", "outro_ser_falso", "outro_ser_muito_falso"])
436
+ end
437
+
438
+ it "should return all the be_false possibilities for the inverted keyword" do
439
+ keywords = { 'matchers' => { 'be' => 'sein', 'false_word' => 'falsch*' }}
440
+ stub_keywords!(@germany, keywords)
441
+ @germany.word_be('false').should eql(['falsch_sein'])
442
+ end
443
+
444
+ it 'should return a empty array for the non false keyword' do
445
+ keywords = {}
446
+ stub_keywords!(@en, keywords)
447
+ @en.word_be('false').should eql []
203
448
  end
449
+
450
+ it 'should return a empty array for the non false keyword' do
451
+ keywords = { 'matchers' => { 'be' => 'ser', 'false' => nil }}
452
+ stub_keywords!(@es, keywords)
453
+ @es.word_be('false').should eql []
454
+ end
455
+
456
+ end
457
+
458
+ context 'when be empty keyword' do
459
+
460
+ it "should return all the be empty possibilities" do
461
+ keywords = { 'matchers' => { 'be' => 'ser', 'empty_word' => 'vazio|muito_vazio'}}
462
+ stub_keywords!(@portuguese, keywords)
463
+ @portuguese.word_be('empty').should eql(['ser_vazio', 'ser_muito_vazio'])
464
+ end
465
+
466
+ it "should return the inverted be_empty keyword for keywords with '*' char" do
467
+ keywords = {'matchers' => { 'be' => 'sein', 'empty_word' => 'leer*'}}
468
+ stub_keywords!(@germany, keywords)
469
+ @germany.word_be('empty').should eql(['leer_sein'])
470
+ end
471
+
472
+ end
473
+
474
+ end
475
+
476
+ context 'when invert_order_of_object_and_verbs?' do
477
+
478
+ it "should return true if the keyword include '*' character" do
479
+ @germany.invert_order_of_object_and_verbs?('wahr*').should be_true
480
+ end
481
+
482
+ it "should return true if the keyword include '*' char" do
483
+ @portuguese.invert_order_of_object_and_verbs?('verdadeiro*').should be_true
484
+ end
485
+
486
+ it "should return true if one keyword include '*' char" do
487
+ @germany.invert_order_of_object_and_verbs?('wahr*|verdadeiro').should be_true
488
+ end
489
+
490
+ it "should return true if the two keywords include '*' char" do
491
+ @portuguese.invert_order_of_object_and_verbs?('wahr*|verdadeiro*').should be_true
492
+ end
493
+
494
+ it "should return false if the keyword not include '*' character" do
495
+ @portuguese.invert_order_of_object_and_verbs?('verdadeiro').should be_false
496
+ end
497
+
498
+ it "should return false if the keyword not include '*' char" do
499
+ @spanish.invert_order_of_object_and_verbs?('falso').should be_false
500
+ end
501
+
502
+ it "should return false if the keyword is nil" do
503
+ @germany.invert_order_of_object_and_verbs?(nil).should be_false
504
+ end
505
+
506
+ end
507
+
508
+ context 'when values from keywords' do
509
+
510
+ it "should return the empty Hash for non values of keyword" do
511
+ stub_keywords!(@portuguese, {})
512
+ @portuguese.values_from_keywords('hooks').should eql({})
513
+ end
514
+
515
+ it "should return the values for values fo keyword" do
516
+ stub_keywords!(@portuguese, { 'hooks' => { 'each' => 'cada|de_cada'}})
517
+ @portuguese.values_from_keywords('hooks').should eql({'each' => 'cada|de_cada'})
518
+ end
519
+
520
+ it "should return the empty values for non values of middle keyword" do
521
+ stub_keywords!(@germany, { 'hooks' => {}})
522
+ @germany.values_from_keywords('hooks').should eql({})
523
+ end
524
+
525
+ end
526
+
527
+ context '#basic_keywords' do
528
+
529
+ it "should ignore hooks from keywords" do
530
+ stub_keywords!(@portuguese, { 'subject' => 'assunto', 'hooks' => {'all' => 'todos'}})
531
+ @portuguese.basic_keywords.should eql({'subject' => 'assunto'})
532
+ end
533
+
534
+ it "should ignore matchers from keywords" do
535
+ stub_keywords!(@portuguese, { 'subject' => 'assunto', 'matchers' => {'be' => 'ser'}})
536
+ @portuguese.basic_keywords.should eql({'subject' => 'assunto'})
537
+ end
538
+
539
+ it "should ignore matchers and hooks" do
540
+ stub_keywords!(@portuguese, {'describe' => 'descreva', 'should' => 'deve', 'should_not' => 'nao_deve', 'matchers' => {'eql' => 'igl'}, 'hooks' => {'all' => 'todos'}})
541
+ @portuguese.basic_keywords.should eql({'describe' => 'descreva', 'should' => 'deve', 'should_not' => 'nao_deve'})
542
+ end
543
+
544
+ it "should include all the basic keywords" do
545
+ stub_keywords!(@portuguese, {'describe' => 'descreva', 'matchers' => { 'eql' => 'igual_a'}})
546
+ @portuguese.basic_keywords.should eql({'describe' => 'descreva'})
547
+ end
548
+
549
+ end
550
+
551
+ context '#advanced_keywords' do
552
+
553
+ it "should ignore all the basic keywords" do
554
+ stub_keywords!(@portuguese, {'describe' => 'descreva', 'matchers' => { 'equal' => 'igual' }})
555
+ @portuguese.advanced_keywords.should eql({'matchers' => {'equal' => 'igual'}})
556
+ end
557
+
558
+ it "should accept hooks keywords" do
559
+ stub_keywords!(@portuguese, {'subject' => 'assunto', 'it' => 'isto', 'hooks' => {'all' => 'todos'}})
560
+ @portuguese.advanced_keywords.should eql({'hooks' => {'all' => 'todos'}})
561
+ end
562
+
563
+ it "should accept hooks and matchers" do
564
+ stub_keywords!(@portuguese, {'subject' => 'assunto', 'hooks' => {'all' => 'todos'}, 'matchers' => { 'include' => 'inclua' }})
565
+ @portuguese.advanced_keywords.should eql({'hooks' => {'all' => 'todos'}, 'matchers' => {'include' => 'inclua'}})
204
566
  end
205
567
 
206
568
  end