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
@@ -7,23 +7,65 @@ describe Main do
7
7
  @pt = SpecI18n::Parser::NaturalLanguage.get("pt")
8
8
  @es = SpecI18n::Parser::NaturalLanguage.get("es")
9
9
  @languages = {"pt" => @pt,"es" => @es}
10
- @pt_keywords = {"describe" => "descreva"}
11
- @es_keywords = {"describe" => "descreva"}
12
- @pt.stub!(:keywords).and_return(@pt_keywords)
13
- @es.stub!(:keywords).and_return(@es_keywords)
14
10
  end
15
11
 
16
12
  describe 'the manipulation of methods of the domain specific language' do
13
+ before(:each) do
14
+ @pt_keywords = {"describe" => "descreva|contexto"}
15
+ @es_keywords = {"describe" => "descreba|describir"}
16
+ @pt.stub!(:keywords).and_return(@pt_keywords)
17
+ @es.stub!(:keywords).and_return(@es_keywords)
18
+ end
17
19
 
18
- it "should have the methods of the dsl keywords of the language specified" do
19
- @languages.each do |lang, language|
20
- SpecI18n.stub!(:natural_language).and_return(language)
21
- Spec::DSL::Main.register_adverbs
22
- language.dsl_keywords.values.flatten.each do |keyword|
23
- Main.methods.should include(keyword)
24
- end
25
- end
20
+ it "should have the methods of the dsl keywords of the language specified" do
21
+ mock_natural_language(@pt)
22
+ Main.register_adverbs
23
+ [:descreva, :contexto].each do |keyword|
24
+ Main.methods.all_to_symbols.should include(keyword)
26
25
  end
26
+ end
27
+
28
+ it "should have the method for other language" do
29
+ mock_natural_language(@es)
30
+ Main.register_adverbs
31
+ [:descreba, :describir].each do |keyword|
32
+ Main.methods.all_to_symbols.should include(keyword)
33
+ end
34
+ end
35
+
36
+ end
37
+
38
+ describe "the manipulation of shared examples for" do
39
+
40
+ before(:each) do
41
+ @keywords = { "shared_examples_for" => "exemplos_distribuidos|exemplos_distribuidos_para" }
42
+ stub_language!("pt", @keywords)
43
+ Main.translate_shared_examples_for
44
+ end
45
+
46
+ it "should register all the keywords for the shared examples for" do
47
+ [:exemplos_distribuidos, :exemplos_distribuidos_para].each do |keyword|
48
+ Main.methods.to_symbols.should include(keyword)
49
+ end
50
+ end
51
+
52
+ end
53
+
54
+ describe "when translate share_as" do
55
+
56
+ before(:each) do
57
+ @keywords = { "share_as" => 'distribua|distribua_como' }
58
+ stub_language!('pt', @keywords)
59
+ Main.translate_share_as_keywords
60
+ end
61
+
62
+ it "should include the translate methods" do
63
+ main_methods = Main.methods.to_symbols
64
+ [:distribua, :distribua_como].each do |method_name|
65
+ main_methods.should include(method_name)
66
+ end
67
+ end
68
+
27
69
  end
28
70
 
29
71
  end
@@ -3,82 +3,205 @@ require 'spec_helper'
3
3
  module Spec
4
4
  module Example
5
5
  describe BeforeAndAfterHooks do
6
-
7
- before(:each) do
8
- @pt = SpecI18n::Parser::NaturalLanguage.get("pt")
9
- @es = SpecI18n::Parser::NaturalLanguage.get("es")
10
- @pt_keywords = {"before" => "antes", "after" => "antes",
11
- "hooks" => {"each" => "cada", "all" => "todos",
12
- "suite" => "suite"}}
13
- @es_keywords = { "before" => "antes", "after" => "antes",
14
- "hooks" => {"each" => "cada", "all" => "tudo",
15
- "suite" => "suite"}}
16
- @pt.stub!(:keywords).and_return(@pt_keywords)
17
- @es.stub!(:keywords).and_return(@es_keywords)
18
- @languages = {"pt" => @pt, "es" => @es}
19
- end
20
-
21
- it "should include all i18n methods to Before and After Hooks" do
22
- @languages.each do |lang, language|
23
- SpecI18n.stub!(:natural_language).and_return(language)
24
- Spec::Example::BeforeAndAfterHooks.register_hooks
25
- language.before_and_after_keywords.keys.map do |keyword|
26
- BeforeAndAfterHooks.methods.should include(keyword)
6
+
7
+ describe 'when translate the hooks' do
8
+
9
+ context 'when portuguese' do
10
+
11
+ before(:each) do
12
+ @keywords = { 'before' => 'antes|anterior', 'after' => 'depois|posterior' }
13
+ stub_language!('pt', @keywords)
14
+ Spec::Example::BeforeAndAfterHooks.register_hooks
15
+ end
16
+
17
+ it "should include all i18n methods to Before Hooks" do
18
+ name_methods = BeforeAndAfterHooks.methods.to_symbols
19
+ [:antes, :anterior].each do |translated_method|
20
+ name_methods.should include(translated_method)
21
+ end
22
+ end
23
+
24
+ it "should include all i18n methods to After Hooks" do
25
+ name_methods = BeforeAndAfterHooks.methods.to_symbols
26
+ [:depois, :posterior].each do |translated_method|
27
+ name_methods.should include(translated_method)
28
+ end
27
29
  end
30
+
28
31
  end
32
+
29
33
  end
30
34
 
31
- context "the before hook" do
35
+ describe 'when hooks' do
32
36
 
33
- it "should translate the :each parameters and parse options" do
34
- @languages.each do |lang, language|
35
- SpecI18n.stub!(:spec_language).and_return(lang)
36
- SpecI18n.stub!(:natural_language).and_return(language)
37
- scope = language.hooks_params_keywords["each"].first
38
- self.should_receive(:before_each_parts)
39
- before_parts(scope)
40
- end
37
+ before(:each) do
38
+ SpecI18n.stub!(:spec_language).and_return('pt')
39
+ @keywords = { 'hooks' => { 'each' => 'cada|de_cada', 'all' => 'todos|de_todos', 'suite' => 'suite|da_suite'}}
40
+ stub_language!('pt', @keywords)
41
41
  end
42
-
43
- it "should translate the :all scope and call the right method" do
44
- @languages.each do |lang, language|
45
- SpecI18n.stub!(:spec_language).and_return(lang)
46
- SpecI18n.stub!(:natural_language).and_return(language)
47
- scope = language.hooks_params_keywords["all"].first
48
- self.should_receive(:before_all_parts)
49
- before_parts(scope)
42
+
43
+ describe "the before hook" do
44
+
45
+ context 'when :each' do
46
+
47
+ it "should translate the :each parameters and parse options" do
48
+ [:cada, :de_cada].each do |scope|
49
+ BeforeAndAfterHooks.should_receive(:before_each_parts)
50
+ BeforeAndAfterHooks.before_parts(scope)
51
+ end
52
+ end
53
+
54
+ it "should not call the :all parameters for :each hook" do
55
+ BeforeAndAfterHooks.should_not_receive(:before_all_parts)
56
+ [:cada, :de_cada].each do |scope|
57
+ BeforeAndAfterHooks.before_parts(scope)
58
+ end
59
+ end
60
+
61
+ it "should not call the :suite parameters for :suite hook" do
62
+ BeforeAndAfterHooks.should_not_receive(:before_suite_parts)
63
+ [:cada, :de_cada].each do |scope|
64
+ BeforeAndAfterHooks.before_parts(scope)
65
+ end
66
+ end
50
67
  end
51
- end
52
-
53
- it "should translate the :suite scope and call the right method" do
54
- @languages.each do |lang, language|
55
- SpecI18n.stub!(:spec_language).and_return(lang)
56
- SpecI18n.stub!(:natural_language).and_return(language)
57
- scope = language.hooks_params_keywords["suite"].first
58
- self.should_receive(:before_suite_parts)
59
- before_parts(scope)
68
+
69
+ context 'when :all' do
70
+
71
+ it "should translate the :all parameter" do
72
+ [:todos, :de_todos].each do |scope|
73
+ BeforeAndAfterHooks.should_receive(:before_all_parts)
74
+ BeforeAndAfterHooks.before_parts(scope)
75
+ end
76
+ end
77
+
78
+ it "should not call the :each parameter" do
79
+ BeforeAndAfterHooks.should_not_receive(:before_each_parts)
80
+ [:todos, :de_todos].each do |scope|
81
+ BeforeAndAfterHooks.before_parts(scope)
82
+ end
83
+ end
84
+
85
+ it "should not call the :suite parameter" do
86
+ BeforeAndAfterHooks.should_not_receive(:before_suite_parts)
87
+ [:todos, :de_todos].each do |scope|
88
+ BeforeAndAfterHooks.before_parts(scope)
89
+ end
90
+ end
91
+
92
+ end
93
+
94
+ context 'when :suite' do
95
+
96
+ it "should translate the :suite parameter" do
97
+ [:suite, :da_suite].each do |scope|
98
+ BeforeAndAfterHooks.should_receive(:before_suite_parts)
99
+ BeforeAndAfterHooks.before_parts(scope)
100
+ end
101
+ end
102
+
103
+ it "should not call the :each parameter" do
104
+ BeforeAndAfterHooks.should_not_receive(:before_each_parts)
105
+ [:suite, :da_suite].each do |scope|
106
+ BeforeAndAfterHooks.before_parts(scope)
107
+ end
108
+ end
109
+
110
+ it "should not call the :all parameter" do
111
+ BeforeAndAfterHooks.should_not_receive(:before_all_parts)
112
+ [:suite, :da_suite].each do |scope|
113
+ BeforeAndAfterHooks.before_parts(scope)
114
+ end
115
+ end
116
+
60
117
  end
118
+
61
119
  end
62
- end
63
120
 
64
- context "the after hook" do
65
- it "should translate the :all scope and call the right method" do
66
- @languages.each do |lang, language|
67
- SpecI18n.stub!(:spec_language).and_return(lang)
68
- SpecI18n.stub!(:natural_language).and_return(language)
69
- scope = language.hooks_params_keywords["all"].first
70
- self.should_receive(:after_all_parts)
71
- after_parts(scope)
121
+ context "the after hook" do
122
+
123
+ context 'when :each' do
124
+
125
+ it "should translate the :each parameters and parse options" do
126
+ [:cada, :de_cada].each do |scope|
127
+ BeforeAndAfterHooks.should_receive(:after_each_parts)
128
+ BeforeAndAfterHooks.after_parts(scope)
129
+ end
130
+ end
131
+
132
+ it "should not call the :all parameters for :each hook" do
133
+ BeforeAndAfterHooks.should_not_receive(:after_all_parts)
134
+ [:cada, :de_cada].each do |scope|
135
+ BeforeAndAfterHooks.after_parts(scope)
136
+ end
137
+ end
138
+
139
+ it "should not call the :suite parameters for :suite hook" do
140
+ BeforeAndAfterHooks.should_not_receive(:after_suite_parts)
141
+ [:cada, :de_cada].each do |scope|
142
+ BeforeAndAfterHooks.after_parts(scope)
143
+ end
144
+ end
145
+ end
146
+
147
+ context 'when :all' do
148
+
149
+ it "should translate the :all parameter" do
150
+ [:todos, :de_todos].each do |scope|
151
+ BeforeAndAfterHooks.should_receive(:after_all_parts)
152
+ BeforeAndAfterHooks.after_parts(scope)
153
+ end
154
+ end
155
+
156
+ it "should not call the :each parameter" do
157
+ BeforeAndAfterHooks.should_not_receive(:after_each_parts)
158
+ [:todos, :de_todos].each do |scope|
159
+ BeforeAndAfterHooks.after_parts(scope)
160
+ end
161
+ end
162
+
163
+ it "should not call the :suite parameter" do
164
+ BeforeAndAfterHooks.should_not_receive(:after_suite_parts)
165
+ [:todos, :de_todos].each do |scope|
166
+ BeforeAndAfterHooks.after_parts(scope)
167
+ end
168
+ end
169
+
72
170
  end
171
+
172
+ context 'when :suite' do
173
+
174
+ it "should translate the :suite parameter" do
175
+ [:suite, :da_suite].each do |scope|
176
+ BeforeAndAfterHooks.should_receive(:after_suite_parts)
177
+ BeforeAndAfterHooks.after_parts(scope)
178
+ end
179
+ end
180
+
181
+ it "should not call the :each parameter" do
182
+ BeforeAndAfterHooks.should_not_receive(:after_each_parts)
183
+ [:suite, :da_suite].each do |scope|
184
+ BeforeAndAfterHooks.after_parts(scope)
185
+ end
186
+ end
187
+
188
+ it "should not call the :all parameter" do
189
+ BeforeAndAfterHooks.should_not_receive(:after_all_parts)
190
+ [:suite, :da_suite].each do |scope|
191
+ BeforeAndAfterHooks.after_parts(scope)
192
+ end
193
+ end
194
+
195
+ end
196
+
73
197
  end
198
+
74
199
  end
75
200
 
76
201
  context "grep the scope and call the hook" do
77
202
 
78
203
  before(:each) do
79
- @pt = Spec::Runner.configuration.spec_language(:pt)
80
- @language = SpecI18n::Parser::NaturalLanguage.get(@pt)
81
- @hooks = @language.hooks_params_keywords
204
+ @hooks = { 'each' => 'cada|de_cada', 'all' => 'todos|de_todos', 'suite' => 'suite|da_suite' }
82
205
  end
83
206
 
84
207
  it "should return the same scope if scope is in English" do
@@ -87,51 +210,50 @@ module Spec
87
210
  end
88
211
  end
89
212
 
90
- it "should grep the scope each" do
91
- scopes = @hooks["each"]
92
- scopes.each do |scope|
93
- grep_the_scope(scope, @hooks).should == :each
213
+ context 'with String scope parameters' do
214
+
215
+ it "should grep the scope each in translated values" do
216
+ ['cada', 'de_cada'].each do |scope|
217
+ grep_the_scope(scope, @hooks).should == :each
218
+ end
94
219
  end
95
- end
96
-
97
- it "should grep the scope all" do
98
- scopes = @hooks["all"]
99
- scopes.each do |scope|
100
- grep_the_scope(scope, @hooks).should == :all
220
+
221
+ it "should grep the scope all in translated values" do
222
+ ['todos', 'de_todos'].each do |scope|
223
+ grep_the_scope(scope, @hooks).should == :all
224
+ end
101
225
  end
102
- end
103
-
104
- it "should grep the scope suite" do
105
- scopes = @hooks["suite"]
106
- scopes.each do |scope|
107
- grep_the_scope(scope, @hooks).should == :suite
226
+
227
+ it "should grep the scope suite in translated values" do
228
+ ['suite', 'da_suite'].each do |scope|
229
+ grep_the_scope(scope, @hooks).should == :suite
230
+ end
108
231
  end
232
+
109
233
  end
110
234
 
111
- context "with Symbol scopes" do
235
+ context "with Symbol scope parameters" do
112
236
 
113
- it "should grep the scope :each" do
114
- scopes = @hooks["each"].map { |hook| hook.to_sym }
115
- scopes.each do |scope|
116
- grep_the_scope(scope, @hooks).should == :each
237
+ it "should grep the scope each in translated values" do
238
+ [:cada, :de_cada].each do |scope|
239
+ grep_the_scope(scope, @hooks).should == :each
117
240
  end
118
241
  end
119
242
 
120
- it "should grep the scope :all" do
121
- scopes = @hooks["all"].map { |hook| hook.to_sym }
122
- scopes.each do |scope|
243
+ it "should grep the scope all in translated values" do
244
+ [:todos, :de_todos].each do |scope|
123
245
  grep_the_scope(scope, @hooks).should == :all
124
246
  end
125
247
  end
126
-
127
- it "should grep the scope :suite" do
128
- scopes = @hooks["suite"].map { |hook| hook.to_sym }
129
- scopes.each do |scope|
130
- grep_the_scope(scope, @hooks).should == :suite
248
+
249
+ it "should grep the scope suite in translated values" do
250
+ [:suite, :da_suite].each do |scope|
251
+ grep_the_scope(scope, @hooks).should == :suite
131
252
  end
132
253
  end
133
254
 
134
255
  end
256
+
135
257
  end
136
258
 
137
259
  end
@@ -4,19 +4,37 @@ module Spec
4
4
  module Example
5
5
  describe ExampleGroupMethods do
6
6
 
7
- before(:each) do
8
- @languages = ["pt", "es", "en"]
7
+ context 'when it keywords' do
8
+ before(:each) do
9
+ @keywords = {"it" => "isto|especificar"}
10
+ stub_language!("pt", @keywords)
11
+ Spec::Example::ExampleGroupMethods.register_example_adverbs
12
+ end
13
+
14
+ it "should include the example translated methods" do
15
+ example_group_methods = Spec::Example::ExampleGroup.methods.to_symbols
16
+ [:isto, :especificar].each do |example_method|
17
+ example_group_methods.should include(example_method)
18
+ end
19
+ end
9
20
  end
10
21
 
11
- it "should include #it example translated methods" do
12
- @languages.each do |language|
13
- Spec::Runner.configuration.spec_language(language)
14
- language = SpecI18n::Parser::NaturalLanguage.get(language)
15
- language.example_group_keywords.values.flatten.each do |keyword|
16
- pending "I don't know wich module is included the keywords (Is 2:43 AM - I'll relaxing in my couch)"
22
+ context 'when it should behave like keywords' do
23
+ before(:each) do
24
+ @keywords = { 'it_should_behave_like' => 'deve_se_comportar_como|deve_se_comportar'}
25
+ stub_language!('pt', @keywords)
26
+ Spec::Example::ExampleGroupMethods.translate_it_should_behave_like
27
+ end
28
+
29
+ it 'should include the it should behave like method translated' do
30
+ example_group_methods = Spec::ExampleGroup.methods.to_symbols
31
+ [:deve_se_comportar_como, :deve_se_comportar].each do |translated_method|
32
+ example_group_methods.should include(translated_method)
17
33
  end
18
34
  end
35
+
19
36
  end
37
+
20
38
  end
21
39
  end
22
40
  end