rspec-i18n 1.0.0 → 1.1.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/History.rdoc CHANGED
@@ -1,3 +1,9 @@
1
+ ==== development in git:
2
+
3
+ * enhancements
4
+ * Refactored internal code and specs
5
+ * Translate nil, true, false and empty.
6
+
1
7
  === Version 1.0.0
2
8
 
3
9
  * enhancements
data/README.rdoc CHANGED
@@ -4,45 +4,74 @@
4
4
  * http://gemcutter.org/gems/rspec-i18n
5
5
  * http://rspec-i18n.lighthouseapp.com
6
6
 
7
+ == Install
8
+
9
+ [sudo] gem install rspec-i18n
10
+
11
+ Or if you use rvm(for example ruby 1.8.7):
12
+
13
+ rvm 1.8.7 gem install rspec-i18n
14
+
7
15
  == Description
8
16
 
9
- The Rspec-i18n gem provide a easy way to write specs in any language you
10
- prefer. The Rspec-i18n was created for the purpose of teaching people who are
17
+ The Rspec-i18n gem provide a easy way to write specs in any speaking language you
18
+ prefer - If don't have your speaking language, please make a fork =)
19
+ The Rspec-i18n was created for the purpose of teaching people who are
11
20
  starting to developing applications but also serves to Production use.
12
- I know that many people prefer to write code/specs in English =)
13
-
14
- But if you don't prefer that, you'll like the Rspec-i18n.
21
+ I know that many people prefer to write code/specs in English.
22
+ But if you don't prefer that, you'll like the Rspec-i18n. =)
15
23
 
16
24
  == Synopsis
17
25
 
18
- Rspec-i18n will supports any language you want
26
+ Rspec-i18n will supports some speaking language(If don't have your speaking language, please make a fork and send pull requests!)
19
27
  (See http://github.com/tomas-stefano/rspec-i18n/blob/master/lib/spec-i18n/languages.yml file).
20
- This is Portuguese(Brazil):
21
-
22
- require 'spec'
28
+ Here is a simple example of Portuguese(Brazil):
29
+
30
+ First your <b>spec_helper</b>:
31
+
32
+ # In spec/spec_helper
33
+
23
34
  require 'spec-i18n'
24
35
 
25
36
  Spec::Runner.configure do |config|
26
37
 
27
38
  config.spec_language :pt
28
39
 
29
- ...
40
+ # ...
30
41
  end
31
42
 
32
- # In spec/pessoa_spec.rb
43
+ Then you have <b>Translated -> Matchers, Before Hooks, After Hooks ...(etc)</b>
44
+ in Portuguese Language.
45
+ Start with a very very simple example in Portuguese:
46
+
47
+ # In spec/personagem_spec.rb
33
48
 
34
49
  require 'spec_helper'
35
50
 
36
- descreva Pessoa do
51
+ descreva Personagem do
52
+
37
53
  antes(:de_cada) do
38
- @nome = "Tomas"
39
- @pessoa = Pessoa.new(@nome)
54
+ @homer = Personagem.new("Homer Simpson", :desenho => :simpson)
55
+ @meggie = Personagem.new("Meggie Simpson", :desenho => :simpson)
40
56
  end
41
-
42
- exemplo "retornar o seu nome" do
43
- @pessoa.nome.deve == @nome
57
+
58
+ isto "deve retornar o desenho ao qual o personagem pertence" do
59
+ @homer.desenho.deve ser_igual_a(:simpson)
60
+ end
61
+
62
+ isto "deve ser personagem principal" do
63
+ @homer.deve ser_personagem_principal # look personagem_principal? method
64
+ end
65
+
66
+ isto "deve beber cerveja Duffy" do
67
+ @homer.bebe_cerveja_duffy?.deve ser_verdadeiro
68
+ end
69
+
70
+ isto "deve beber cerveja Duffy" do
71
+ @meggie.bebe_cerveja_duffy?.deve ser_falso
44
72
  end
45
- end
73
+
74
+ end
46
75
 
47
76
  == Examples
48
77
 
@@ -58,18 +87,23 @@ See more examples in http://github.com/tomas-stefano/rspec-i18n/blob/master/exam
58
87
 
59
88
  rspec-i18n --language es
60
89
 
61
- == Adding a new language or completing a existing one(based on Cucumber implementation)
90
+ == Adding a new language or completing a existing one
62
91
 
63
92
  1. Make a fork of Rspec-i18n and pull it down
64
93
  2. Add your language keywords to languages.yml
65
94
  3. Commit and push your changes - then send a pull request at Github
66
95
 
67
- ** OBS: Hints for better words in languages.yml are Welcome =D.
96
+ <b>OBS: Ideas for better words in languages.yml are Welcome =D.</b>
68
97
 
69
- == Install
98
+ == Tested Versions
70
99
 
71
- [sudo] gem install rspec-i18n
100
+ <b>ONLY Ruby 1.8</b>
101
+ <b>Rspec-i18n >= 1.0.0</b> supports <b>ONLY Rspec 1.3</b>
102
+
103
+ The older versions supports this versions: Rspec: 1.2.7, 1.2.8, 1.2.9
104
+
105
+ <b>Support for Rspec 2.0 and Ruby 1.9 come soon!</b>
72
106
 
73
107
  == TODO
74
108
 
75
- See the TODO.txt file and see more details
109
+ See the <b>TODO.txt</b> file and see more details
data/TODO.txt CHANGED
@@ -8,11 +8,9 @@
8
8
  == Future
9
9
 
10
10
  * Translate shared examples
11
- * Translate nil, true, false and empty.
12
- * Put a #language header in the spec_helper file (Cucumber Style) instead load from config(maintain the two options)
13
11
  * Create the directory features to test with Cucumber
14
- * Verifying if it's possible to translate error and success messages
15
- * Make the describe/it i18n available from a class
12
+ * Verifying if it's possible to translate error and success messages and documentation
13
+ * Make the describe/it i18n available from a class:
16
14
 
17
15
  Example:
18
16
  # class PilhaSpec < Spec::ExampleGroup
@@ -28,5 +26,5 @@
28
26
  #
29
27
  # end
30
28
 
31
- * Check a better way to manipulating the mocks and stubs for i18n (What do you think?)
29
+ * Check a better way to manipulating the mocks and stubs (What do you think?)
32
30
  * Verify the following matchers: simple_matcher, wrap_expectation, respond_to, change and match_unless_raises.
data/VERSION.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
2
  :major: 1
3
- :minor: 0
3
+ :minor: 1
4
4
  :build:
5
5
  :patch: 0
@@ -11,16 +11,31 @@ class Pessoa
11
11
  @nome = nome
12
12
  @sobrenome = sobrenome
13
13
  @idade = opcoes[:idade]
14
+ @filhos = opcoes[:filhos]
14
15
  end
15
16
 
16
17
  def nome_completo
17
18
  "#{@nome} #{@sobrenome}"
18
19
  end
19
-
20
+
21
+ def informacoes
22
+ return nil if nome_completo.strip.empty?
23
+ nome_completo
24
+ end
25
+
26
+ def filhos
27
+ @filhos || []
28
+ end
29
+
20
30
  def maior_de_idade?
21
31
  return true if @idade >= 18
22
32
  false
23
33
  end
34
+
35
+ def menor_de_idade?
36
+ return false if maior_de_idade?
37
+ true
38
+ end
24
39
 
25
40
  def pronto_para_votar?
26
41
  maior_de_idade?
@@ -35,7 +50,7 @@ class Pessoa
35
50
  end
36
51
  end
37
52
 
38
- # Silly Tests for show to you how to use this library in portuguese language
53
+ # Silly Tests for specifying the library in portuguese language
39
54
  descreva Pessoa do
40
55
 
41
56
  antes(:de_todos) do
@@ -58,28 +73,28 @@ descreva Pessoa do
58
73
  @pessoas = []
59
74
  end
60
75
 
61
- exemplo 'deve ser uma instancia da classe Pessoa' do
76
+ isto 'deve ser uma instancia da classe Pessoa' do
62
77
  @pessoa.deve ser_instancia_de(Pessoa)
63
78
  end
64
79
 
65
- exemplo 'deve incluir uma pessoa' do
80
+ isto 'deve incluir uma pessoa' do
66
81
  @pessoas.deve incluir(@pessoa)
67
82
  end
68
83
 
69
- exemplo 'deve ser do tipo Pessoa' do
84
+ isto 'deve ser do tipo Pessoa' do
70
85
  @pessoa.deve ser_do_tipo(Pessoa)
71
86
  end
72
87
 
73
- exemplo 'deve ter pelo menos uma pessoa' do
88
+ isto 'deve ter pelo menos uma pessoa' do
74
89
  @pessoas.deve ter_no_minimo(1).items
75
90
  end
76
91
 
77
- exemplo 'deve ter exatamente duas pessoas' do
92
+ isto 'deve ter exatamente duas pessoas' do
78
93
  @pessoas << @pessoa
79
94
  @pessoas.deve ter_exatamente(2).items
80
95
  end
81
96
 
82
- exemplo 'deve ter no maximo tres pessoas' do
97
+ isto 'deve ter no maximo tres pessoas' do
83
98
  @pessoas = []
84
99
  @pessoas.deve ter_no_maximo(3).items
85
100
  end
@@ -90,11 +105,11 @@ descreva Pessoa do
90
105
  @pessoa = Pessoa.new("Tomás", "D'Stefano")
91
106
  end
92
107
 
93
- exemplo "deve retornar o nome completo" do
108
+ isto "deve retornar o nome completo" do
94
109
  @pessoa.nome_completo.deve ==("Tomás D'Stefano")
95
110
  end
96
111
 
97
- exemplo 'nome completo não pode ser nulo' do
112
+ isto 'nome completo não pode ser nulo' do
98
113
  @pessoa.nome_completo.nao_deve ser_igual_a(nil)
99
114
  end
100
115
 
@@ -106,9 +121,28 @@ descreva Pessoa do
106
121
  @pessoa = Pessoa.new("Aaromn", "Monkey", :idade => 20)
107
122
  end
108
123
 
124
+ # Voce tambem pode usar a palavra especificar
109
125
  especificar "deve ser opcional" do
110
126
  @pessoa.idade.deve ser_igual_a(20)
111
127
  end
128
+
129
+ # Voce tambem pode usar a palavra exemplo
130
+ exemplo "deve retornar verdadeiro se for maior de idade" do
131
+ @pessoa.maior_de_idade?.deve ser_verdadeiro
132
+ end
133
+
134
+ exemplo "deve retornar falso se for menor de idade" do
135
+ @pessoa.menor_de_idade?.deve ser_falso
136
+ end
137
+
138
+ exemplo "deve retornar nulo caso nao tenha informacao" do
139
+ Pessoa.new("", "").informacoes.deve ser_nulo
140
+ end
141
+
142
+ exemplo "deve não ter nenhum filho" do
143
+ @pessoa.filhos.deve ser_vazio
144
+ end
145
+
112
146
  end
113
147
 
114
148
  contexto 'maior de idade' do
@@ -117,7 +151,7 @@ descreva Pessoa do
117
151
  exemplo "deve estar pronto para votar" do
118
152
  deve estar_pronto_para_votar
119
153
  end
120
-
154
+
121
155
  exemplo "deve ser maior de idade" do
122
156
  deve ser_maior_de_idade
123
157
  end
@@ -151,4 +185,4 @@ descreva Pessoa do
151
185
  end
152
186
  end
153
187
 
154
- end
188
+ end
@@ -14,9 +14,6 @@ module SpecI18n
14
14
  include Term::ANSIColor
15
15
  end
16
16
 
17
- # Cucumber print table is loading
18
- # because I don't want reiventing the wheel
19
- #
20
17
  def list_languages_and_exit(io)
21
18
  languages = list_languages
22
19
 
@@ -87,4 +84,4 @@ module SpecI18n
87
84
 
88
85
  end
89
86
  end
90
- end
87
+ end
@@ -5,14 +5,16 @@ module Spec
5
5
  def register_hooks
6
6
  language = SpecI18n.natural_language
7
7
  language.before_and_after_keywords.each do |key, values|
8
- values.map { |value| alias_method value, key }
8
+ values.map do |value|
9
+ alias_method value, key
10
+ end
9
11
  end
10
12
  end
11
13
 
12
14
  def before_parts(scope)
13
-
15
+
14
16
  scope = grep_language_and_scope(scope) || scope
15
-
17
+
16
18
  case scope
17
19
  when :each; before_each_parts
18
20
  when :all; before_all_parts
@@ -43,7 +45,6 @@ module Spec
43
45
  def grep_the_scope(scope, hooks)
44
46
  scopes = [:each, :all, :suite]
45
47
  return scope if scopes.include?(scope)
46
-
47
48
  hooks.each do |scope_in_english, language_hooks|
48
49
  return scope_in_english.to_sym if language_hooks.include?(scope.to_s)
49
50
  end
@@ -4,44 +4,48 @@
4
4
  # If you want several aliases for a keyword, just a separate them
5
5
  # with a | character. Make sure there are no ambiguities in the keywords
6
6
 
7
- # The English language => Just for example
7
+ # The English language => Just for example all the keywords
8
8
  "en":
9
- name: English
10
- native: English
11
- describe: describe
12
- it: it|specify
13
- its: exemplo_do_assunto # I don't know about this word
14
- subject: subject
15
- should: should
16
- should_not: should_not
17
- before: before
18
- after: after
19
- hooks:
20
- each: each
21
- all: all
22
- suite: suite
23
- matchers:
24
- be: be
25
- be_a_kind_of: be_a_kind_of
26
- be_close: be_close
27
- be_an_instance_of: be_an_instance_of
28
- eql: eql
29
- equal: equal
30
- exist: exist
31
- have: have
32
- have_exactly: have_exactly
33
- have_at_least: have_at_least
34
- have_at_most: have_at_most
35
- include: include
36
- match: match
37
- raise_error: raise_exception
38
- satisfy: satisfazer
9
+ name:
10
+ native:
11
+ describe:
12
+ it:
13
+ its:
14
+ subject:
15
+ should:
16
+ should_not:
17
+ before:
18
+ after:
19
+ hooks:
20
+ each:
21
+ all:
22
+ suite:
23
+ matchers:
24
+ be:
25
+ true_word:
26
+ false_word:
27
+ nil_word:
28
+ empty_word:
29
+ be_a_kind_of:
30
+ be_close:
31
+ be_an_instance_of:
32
+ eql:
33
+ equal:
34
+ exist:
35
+ have:
36
+ have_exactly:
37
+ have_at_least:
38
+ have_at_most:
39
+ include:
40
+ match:
41
+ raise_error:
42
+ satisfy:
39
43
 
40
44
  "pt":
41
45
  name: Portuguese
42
46
  native: português
43
47
  describe: descreva|contexto
44
- it: exemplo|especificar
48
+ it: isso|isto|especificar|exemplo
45
49
  its: exemplo_do_assunto # I don't know about this word
46
50
  subject: assunto
47
51
  should: deve
@@ -54,6 +58,10 @@
54
58
  suite: suite
55
59
  matchers:
56
60
  be: ser|estar
61
+ true_word: verdadeiro
62
+ false_word: falso
63
+ nil_word: nulo
64
+ empty_word: vazio
57
65
  be_a_kind_of: ser_do_tipo
58
66
  be_close: estar_perto|estar_proximo
59
67
  be_an_instance_of: ser_instancia_de
@@ -86,6 +94,19 @@
86
94
  all: de_todos_ejemplo
87
95
  suite: suite
88
96
  matchers:
89
- be:
90
- eql:
91
- equal:
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:
@@ -1,3 +1,5 @@
1
+ require 'spec/matchers/dsl'
2
+
1
3
  module Spec
2
4
  module Matchers
3
5
  class Be #:nodoc:
@@ -14,6 +16,57 @@ module Spec
14
16
  end
15
17
  end
16
18
  end
19
+
20
+ end
21
+
22
+ def translate_be_true
23
+ matcher_be_some(:true => true).each do |matcher|
24
+ Spec::Matchers.define matcher do
25
+ match do |actual|
26
+ !!actual
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ def translate_be_false
33
+ matcher_be_some(:false => true).each do |matcher|
34
+ Spec::Matchers.define matcher do
35
+ match do |actual|
36
+ !actual
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ def translate_be_nil
43
+ matcher_be_some(:nil => true).each do |matcher|
44
+ Spec::Matchers.define matcher do
45
+ match do |actual|
46
+ actual.nil?
47
+ end
48
+ end
49
+ end
50
+ end
51
+
52
+ def translate_be_empty
53
+ matcher_be_some(:empty => true).each do |matcher|
54
+ Spec::Matchers.define matcher do
55
+ match do |actual|
56
+ actual.empty?
57
+ end
58
+ end
59
+ end
60
+ end
61
+
62
+ def matcher_be_some(options={})
63
+ option = options.keys.select { |key| options[key] != nil }
64
+ language.word_be(option.to_s).map { |word| word.to_sym}
65
+ end
66
+
67
+ def language
68
+ SpecI18n.natural_language
17
69
  end
70
+
18
71
  end
19
- end
72
+ end
@@ -3,6 +3,11 @@ module Spec
3
3
 
4
4
  def self.register_all_matchers
5
5
  Spec::Matchers::Be.register_be_matcher
6
+ ["true", "false", "nil", "empty"].each do |matcher|
7
+ class_eval <<-BE_WORD
8
+ translate_be_#{matcher}
9
+ BE_WORD
10
+ end
6
11
  translate_basic_matchers
7
12
  end
8
13
 
@@ -59,9 +59,17 @@ module SpecI18n
59
59
  def its_keywords
60
60
  spec_keywords("its")
61
61
  end
62
+
63
+ def word_be(ruby_type)
64
+ matchers_be = keywords['matchers']['be'].to_s.split("|")
65
+ matcher_ruby_type = keywords['matchers']["#{ruby_type}_word"].to_s.split("|")
66
+ matchers_be.collect do |matcher_be|
67
+ matcher_ruby_type.collect { |matcher| "#{matcher_be}_#{matcher}" }
68
+ end.flatten
69
+ end
62
70
 
63
71
  def spec_keywords(key, space=false)
64
- raise "No #{key} in #{@keywords.inspect}" if @keywords[key].nil?
72
+ raise "No #{key} in #{keywords.inspect}" if keywords[key].nil?
65
73
  values = keywords[key].split('|')
66
74
  { key => values }
67
75
  end
data/rspec-i18n.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rspec-i18n}
8
- s.version = "1.0.0"
8
+ s.version = "1.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Tomas D'Stefano"]
12
- s.date = %q{2010-01-19}
12
+ s.date = %q{2010-03-13}
13
13
  s.default_executable = %q{rspec-i18n}
14
14
  s.description = %q{A internacionalization tool written in Ruby for the Rspec Framework}
15
15
  s.email = %q{tomasdestefi@gmail.com}
@@ -87,7 +87,7 @@ Gem::Specification.new do |s|
87
87
  --------------------------------------------------------------------------------
88
88
  U P G R A D I N G
89
89
 
90
- Thank you for installing rspec-i18n-1.0.0
90
+ Thank you for installing rspec-i18n-1.1.0
91
91
  Please be sure to read http://wiki.github.com/tomas-stefano/rspec-i18n/upgrading
92
92
  for information about this release.
93
93
 
@@ -52,20 +52,13 @@ module SpecI18n
52
52
  @language_keywords = LanguageHelpFormatter.list_basic_keywords(@pt)
53
53
  end
54
54
 
55
- # TODO: It's 3 a.m in the morning ... Ugly Specs ... #FIXME
56
-
57
55
  it "should return all basic keywords for a language" do
58
56
  words = %w(name native describe before after it should should_not)
59
57
  words.each do |word|
60
58
  @language_keywords.flatten.should include(word)
61
59
  end
62
60
  end
63
-
64
- it "should return the example keyword for the portuguese language" do
65
- example = @language_keywords.map { |array| array if array.include?("it") }.compact.flatten
66
- example.should == ["it", "exemplo / especificar"]
67
- end
68
-
61
+
69
62
  describe 'the advanced keywords' do
70
63
 
71
64
  before(:each) do
@@ -4,17 +4,23 @@ include Spec::DSL
4
4
  describe Main do
5
5
 
6
6
  before(:each) do
7
- @languages = ["en", "pt", "es"]
7
+ @pt = SpecI18n::Parser::NaturalLanguage.get("pt")
8
+ @es = SpecI18n::Parser::NaturalLanguage.get("es")
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)
8
14
  end
9
15
 
10
16
  describe 'the manipulation of methods of the domain specific language' do
11
17
 
12
18
  it "should have the methods of the dsl keywords of the language specified" do
13
- @languages.each do |language|
14
- Spec::Runner.configuration.spec_language(language)
15
- dsl_keywords = SpecI18n::Parser::NaturalLanguage.get(language).dsl_keywords
16
- dsl_keywords.values.flatten.each do |keyword|
17
- Main.methods.should be_include(keyword)
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)
18
24
  end
19
25
  end
20
26
  end
@@ -5,15 +5,25 @@ module Spec
5
5
  describe BeforeAndAfterHooks do
6
6
 
7
7
  before(:each) do
8
- @languages = ["pt", "en", "es"]
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}
9
19
  end
10
20
 
11
21
  it "should include all i18n methods to Before and After Hooks" do
12
- @languages.each do |language|
13
- Spec::Runner.configuration.spec_language(language)
14
- language = SpecI18n::Parser::NaturalLanguage.get(language)
22
+ @languages.each do |lang, language|
23
+ SpecI18n.stub!(:natural_language).and_return(language)
24
+ Spec::Example::BeforeAndAfterHooks.register_hooks
15
25
  language.before_and_after_keywords.keys.map do |keyword|
16
- BeforeAndAfterHooks.methods.should be_include(keyword)
26
+ BeforeAndAfterHooks.methods.should include(keyword)
17
27
  end
18
28
  end
19
29
  end
@@ -21,9 +31,9 @@ module Spec
21
31
  context "the before hook" do
22
32
 
23
33
  it "should translate the :each parameters and parse options" do
24
- @languages.each do |language|
25
- Spec::Runner.configuration.spec_language(language)
26
- language = SpecI18n::Parser::NaturalLanguage.get(language)
34
+ @languages.each do |lang, language|
35
+ SpecI18n.stub!(:spec_language).and_return(lang)
36
+ SpecI18n.stub!(:natural_language).and_return(language)
27
37
  scope = language.hooks_params_keywords["each"].first
28
38
  self.should_receive(:before_each_parts)
29
39
  before_parts(scope)
@@ -31,9 +41,9 @@ module Spec
31
41
  end
32
42
 
33
43
  it "should translate the :all scope and call the right method" do
34
- @languages.each do |language|
35
- Spec::Runner.configuration.spec_language(language)
36
- language = SpecI18n::Parser::NaturalLanguage.get(language)
44
+ @languages.each do |lang, language|
45
+ SpecI18n.stub!(:spec_language).and_return(lang)
46
+ SpecI18n.stub!(:natural_language).and_return(language)
37
47
  scope = language.hooks_params_keywords["all"].first
38
48
  self.should_receive(:before_all_parts)
39
49
  before_parts(scope)
@@ -41,10 +51,10 @@ module Spec
41
51
  end
42
52
 
43
53
  it "should translate the :suite scope and call the right method" do
44
- @languages.each do |language|
45
- Spec::Runner.configuration.spec_language(language)
46
- language = SpecI18n::Parser::NaturalLanguage.get(language)
47
- scope = language.hooks_params_keywords["suite"].first.to_sym
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
48
58
  self.should_receive(:before_suite_parts)
49
59
  before_parts(scope)
50
60
  end
@@ -53,10 +63,10 @@ module Spec
53
63
 
54
64
  context "the after hook" do
55
65
  it "should translate the :all scope and call the right method" do
56
- @languages.each do |language|
57
- Spec::Runner.configuration.spec_language(language)
58
- language = SpecI18n::Parser::NaturalLanguage.get(language)
59
- scope = language.hooks_params_keywords["all"].first.to_sym
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
60
70
  self.should_receive(:after_all_parts)
61
71
  after_parts(scope)
62
72
  end
@@ -1,19 +1,25 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Object, "#should and #should_not" do
4
-
4
+
5
5
  before(:each) do
6
- @languages = ["pt", "en", "es"]
6
+ @pt = SpecI18n::Parser::NaturalLanguage.get("pt")
7
+ @es = SpecI18n::Parser::NaturalLanguage.get("es")
8
+ @languages = {"pt" => @pt,"es" => @es}
9
+ @pt_keywords = {"should" => "deve", "should_not" => "nao_deve"}
10
+ @es_keywords = {"should" => "debe", "should_not" => "no_debe"}
11
+ @pt.stub!(:keywords).and_return(@pt_keywords)
12
+ @es.stub!(:keywords).and_return(@es_keywords)
7
13
  end
8
14
 
9
15
  it "should have the 'should' and 'should_not' methods translated" do
10
- @languages.each do |language|
11
- Spec::Runner.configuration.spec_language(language)
12
- language = SpecI18n::Parser::NaturalLanguage.get(language)
13
-
14
- language.expectation_keywords.values.flatten.each do |keyword|
15
- Kernel.methods.should be_include(keyword)
16
+ @languages.each do |lang, language|
17
+ SpecI18n.stub!(:natural_language).and_return(language)
18
+ Kernel.register_expectations_keywords
19
+ language.expectation_keywords.values.to_a.flatten.each do |keyword|
20
+ Kernel.methods.should include(keyword)
16
21
  end
17
22
  end
18
23
  end
24
+
19
25
  end
@@ -3,59 +3,164 @@ require 'spec_helper'
3
3
  describe "should be_predicate" do
4
4
 
5
5
  before(:each) do
6
- portuguese_language({"matchers" => {"be" => "ser"}})
6
+ portuguese_language({"matchers" => {"be" => "ser"}, "true" => "verdadeiro"})
7
7
  Spec::Matchers.register_all_matchers
8
8
  end
9
9
 
10
- it "should pass with be language translated" do
11
- atual = stub("atual", :feliz? => true)
12
- atual.should ser_feliz
13
- end
10
+ context "be predicate" do
11
+
12
+ it "should pass with be language translated" do
13
+ atual = stub("atual", :feliz? => true)
14
+ atual.should ser_feliz
15
+ end
14
16
 
15
- it "should fail when actual returns false for :predicate?" do
17
+ it "should fail when actual returns false for :predicate?" do
18
+
19
+ pending('verify rspec 1.3')
16
20
 
21
+ atual = stub("atual", :feliz? => false)
22
+ lambda {
23
+ atual.should be_feliz
24
+ }.should fail_with("expected feliz? to return true, got false")
25
+ end
26
+
27
+ it "should fail when actual returns false for :predicate?" do
17
28
 
18
- pending('verify rspec 1.3')
29
+ pending('verify rspec 1.3')
19
30
 
20
- atual = stub("atual", :feliz? => false)
21
- lambda {
22
- atual.should be_feliz
23
- }.should fail_with("expected feliz? to return true, got false")
31
+ atual = stub("atual", :feliz? => nil)
32
+ lambda {
33
+ atual.should be_feliz
34
+ }.should fail_with("expected feliz? to return true, got nil")
35
+ end
24
36
  end
25
37
 
26
- it "should fail when actual returns false for :predicate?" do
38
+ context "be words" do
39
+ before(:each) do
40
+ @pt = Parser::NaturalLanguage.get("pt")
41
+ @es = Parser::NaturalLanguage.get("es")
42
+ include Spec::Matchers
43
+ @pt_keywords = { "matchers" => {'be' => 'ser',
44
+ "true_word" => "verdadeiro", "empty_word" => "vazio",
45
+ "false_word" => "falso", 'nil_word' => 'nulo'}}
46
+ @pt.stub!(:keywords).and_return(@pt_keywords)
47
+ @es_keywords = { "matchers" => {'be' => 'ser',
48
+ "true_word" => "verdadero", "false_word" => "falso",
49
+ 'nil_word' => 'nulo', 'empty_word' => "vazio"}}
50
+ @es.stub!(:keywords).and_return(@es_keywords)
51
+ end
52
+
53
+ ['true', 'false', 'nil', 'empty'].each do |ruby_type|
54
+ context "be #{ruby_type}" do
55
+
56
+ it "should translate #{ruby_type} keyword for pt" do
57
+ SpecI18n.stub!(:natural_language).and_return(@pt)
58
+ matcher_be = "#{@pt_keywords['matchers']['be']}"
59
+ matcher = @pt_keywords['matchers']["#{ruby_type}_word"]
60
+ expected = "#{matcher_be}_#{matcher}"
61
+ eval <<-MATCHER
62
+ Be.matcher_be_some(:#{ruby_type} => true).should == [expected.to_sym ]
63
+ MATCHER
64
+ end
65
+
66
+ it "should translate #{ruby_type} keyword for es" do
67
+ SpecI18n.stub!(:natural_language).and_return(@es)
68
+ matcher_be = "#{@es_keywords['matchers']['be']}"
69
+ matcher = @es_keywords['matchers']["#{ruby_type}_word"]
70
+ expected = "#{matcher_be}_#{matcher}"
71
+ eval <<-MATCHER
72
+ Be.matcher_be_some(:#{ruby_type} => true).should == [expected.to_sym ]
73
+ MATCHER
74
+ end
75
+ end
76
+ end
77
+
78
+ context "be true predicate" do
79
+
80
+ it "should pass when actual equal?(true)" do
81
+ [@pt, @es].each do |language|
82
+ SpecI18n.stub!(:natural_language).and_return(language)
83
+ Be.translate_be_true
84
+ matcher_be_some(:true => true).each do |word_be_true|
85
+ eval <<-BE_TRUE
86
+ true.should #{word_be_true}
87
+ 1.should #{word_be_true}
88
+ BE_TRUE
89
+ end
90
+ end
91
+ end
92
+
93
+ end
94
+
95
+ context "be false predicate" do
96
+
97
+ it "should pass when actual equal?(true)" do
98
+ [@pt, @es].each do |language|
99
+ SpecI18n.stub!(:natural_language).and_return(language)
100
+ Be.translate_be_false
101
+ matcher_be_some(:false => true).each do |word_be_false|
102
+ eval <<-BE_FALSE
103
+ false.should #{word_be_false}
104
+ nil.should #{word_be_false}
105
+ BE_FALSE
106
+ end
107
+ end
108
+ end
109
+
110
+
111
+ end
27
112
 
28
- pending('verify rspec 1.3')
113
+ context "be nil predicate" do
114
+
115
+ it "should pass when actual is nil" do
116
+ [@pt, @es].each do |language|
117
+ SpecI18n.stub!(:natural_language).and_return(language)
118
+ Be.translate_be_nil
119
+ matcher_be_some(:nil => true).each do |word_be_nil|
120
+ eval <<-BE_NIL
121
+ nil.should #{word_be_nil}
122
+ BE_NIL
123
+ end
124
+ end
125
+ end
126
+ end
127
+
128
+ context "be empty predicate" do
129
+ it "should pass when actual is nil" do
130
+ [@pt, @es].each do |language|
131
+ SpecI18n.stub!(:natural_language).and_return(language)
132
+ Be.translate_be_empty
133
+ matcher_be_some(:empty => true).each do |word_be_nil|
134
+ eval <<-BE_EMPTY
135
+ [].should #{word_be_nil}
136
+ BE_EMPTY
137
+ end
138
+ end
139
+ end
140
+ end
29
141
 
30
- atual = stub("atual", :feliz? => nil)
31
- lambda {
32
- atual.should be_feliz
33
- }.should fail_with("expected feliz? to return true, got nil")
34
142
  end
35
143
 
36
- it 'should be true for the new :predicate' do
37
- atual = true
38
- pending("SHOULD translate true, false, nil, empty for the default MATCHERS")
39
- atual.should ser_true
40
- end
144
+ context "convert the be word" do
145
+ it 'should convert be word to english with two parameters' do
146
+ be_to_english(:ser_feliz, 'ser|estar').should == :be_feliz
147
+ end
41
148
 
42
- it 'should convert be word to english with two parameters' do
43
- be_to_english(:ser_feliz, 'ser|estar').should == :be_feliz
44
- end
149
+ it "should convert be word to english" do
150
+ be_to_english(:ser_feliz, :ser).should == :be_feliz
151
+ end
45
152
 
46
- it "should convert be word to english" do
47
- be_to_english(:ser_feliz, :ser).should == :be_feliz
48
- end
153
+ it "should keep the same word in english(don't break the rspec defaults)" do
154
+ be_to_english(:be_include, :be).should == :be_include
155
+ end
49
156
 
50
- it "should keep the same word in english(don't break the rspec defaults)" do
51
- be_to_english(:be_include, :be).should == :be_include
52
- end
157
+ it "should keep the same word for the non existing word" do
158
+ be_to_english(:be_include, :ser).should == :be_include
159
+ end
53
160
 
54
- it "should keep the same word for the non existing word" do
55
- be_to_english(:be_include, :ser).should == :be_include
161
+ it "should keep the same word for the nil be word" do
162
+ be_to_english(:be_include, nil).should == :be_include
163
+ end
56
164
  end
57
165
 
58
- it "should keep the same word for the nil be word" do
59
- be_to_english(:be_include, nil).should == :be_include
60
- end
61
166
  end
@@ -10,6 +10,13 @@ module SpecI18n
10
10
  @en = NaturalLanguage.get('en')
11
11
  end
12
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
+
13
20
  context "get languages" do
14
21
 
15
22
  it "should get the default language" do
@@ -38,22 +45,11 @@ module SpecI18n
38
45
 
39
46
  end
40
47
 
41
- %w(describe before after it should name native).each do |keyword|
42
- it "should have the #{keyword} keyword" do
43
- portuguese_keys = @pt.keywords.keys
44
- portuguese_keys.should include(keyword)
45
- end
46
- end
47
-
48
48
  context "of dsl keywords" do
49
49
 
50
- it "should return all the dsl keywords" do
51
- @pt.dsl_keywords.should == {"describe" => [ "descreva", "contexto"] }
52
- end
53
-
54
50
  it "should return the describe dsl keyword" do
55
51
  lang = { "describe" => "descreva", :before => "antes" }
56
- @pt.should_receive(:keywords).and_return(lang)
52
+ @pt.should_receive(:keywords).at_least(:once).and_return(lang)
57
53
  @pt.dsl_keywords.should == { "describe" => [ lang["describe"] ] }
58
54
  end
59
55
  end
@@ -66,7 +62,7 @@ module SpecI18n
66
62
 
67
63
  it "should return the expectation keyword of the language" do
68
64
  lang = {"describe" => "descreva", "should" => "deve", "should_not" => "nao_deve"}
69
- @pt.should_receive(:keywords).twice.and_return(lang)
65
+ @pt.should_receive(:keywords).at_least(:once).and_return(lang)
70
66
  @pt.expectation_keywords.should == @keywords
71
67
  end
72
68
 
@@ -78,24 +74,38 @@ module SpecI18n
78
74
 
79
75
  context "of before and after keywords" do
80
76
 
77
+ before(:each) do
78
+ @language = { "before" => "before", "after" => "after"}
79
+ end
80
+
81
81
  it "should return the hooks for the current language" do
82
+ @en.should_receive(:keywords).at_least(:once).and_return(@language)
82
83
  keywords = { "before" => ["before"], "after" => ["after"]}
83
84
  @en.before_and_after_keywords.should == keywords
84
85
  end
85
86
 
86
87
  it "should return the hooks for the language" do
88
+ language = {"before" => "antes", "after" => "depois"}
87
89
  keywords = { "before" => ["antes"], "after" => ["depois"]}
90
+ @pt.stub!(:keywords).and_return(language)
88
91
  @pt.before_and_after_keywords.should == keywords
89
92
  end
90
93
  end
91
94
 
92
95
  context "of hooks keywords" do
93
96
 
94
- it "should return the hooks parameters for the current language" do
95
- keywords = { "each" => ["de_cada", "de_cada_exemplo"],
97
+ before(:each) do
98
+ @lang = { "hooks" => {"each" => "de_cada|de_cada_exemplo",
99
+ "all" => "de_todos|de_todos_exemplos",
100
+ "suite" => "suite"}}
101
+ @keywords = { "each" => ["de_cada", "de_cada_exemplo"],
96
102
  "all" => ["de_todos", "de_todos_exemplos"],
97
103
  "suite" => ["suite"]}
98
- @pt.hooks_params_keywords.should == keywords
104
+ end
105
+
106
+ 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
99
109
  end
100
110
  end
101
111
 
@@ -106,13 +116,11 @@ module SpecI18n
106
116
  end
107
117
 
108
118
  it "should return the example group keywords for the current language" do
119
+ lang = { "it" => "exemplo|especificar", "describe" => "descreva" }
120
+ @pt.stub!(:keywords).and_return(lang)
109
121
  @pt.example_group_keywords.should == @keywords
110
122
  end
111
123
 
112
- it "should return the example group for the portuguese language" do
113
- @keywords = { "it" => ["it", "specify"]}
114
- @en.example_group_keywords.should == @keywords
115
- end
116
124
  end
117
125
 
118
126
  context 'of example subject keywords' do
@@ -150,6 +158,7 @@ module SpecI18n
150
158
  @es.its_keywords.should == { 'its' => ['ejemplos']}
151
159
  end
152
160
  end
161
+
153
162
  context "splitting the keys" do
154
163
  it "should raise no found key" do
155
164
  lambda {
@@ -164,6 +173,38 @@ module SpecI18n
164
173
  @pt.spec_keywords("describe").should == { "describe" => ["descreva", "contexto"] }
165
174
  end
166
175
  end
176
+
177
+ context "be_true, be_false and be_nil" do
178
+
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
185
+ end
186
+ end
187
+
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
194
+ end
195
+ end
196
+
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
203
+ end
204
+ end
205
+
206
+ end
207
+
167
208
  end
168
209
  end
169
210
  end
@@ -36,16 +36,24 @@ module Spec
36
36
 
37
37
  end
38
38
 
39
- describe "load language" do
40
- before(:each) do
41
- config.spec_language(:pt)
42
- end
43
- it "should load all the modules" do
44
- config.load_language.should be_true
45
- end
46
- end
47
39
  end
48
40
  end
49
41
  end
50
42
  end
51
43
  end
44
+
45
+ describe "load language" do
46
+ before(:each) do
47
+ @config = ::Spec::Runner::Configuration.new
48
+ end
49
+ it "should load all the modules" do
50
+ Spec::DSL::Main.should_receive(:register_adverbs)
51
+ Kernel.should_receive(:register_expectations_keywords)
52
+ Spec::Example::ExampleGroupMethods.should_receive(:register_example_adverbs)
53
+ Spec::Example::BeforeAndAfterHooks.should_receive(:register_hooks)
54
+ Spec::Matchers.should_receive(:register_all_matchers)
55
+ Spec::Example::Subject::ExampleGroupMethods.should_receive(:register_subjects)
56
+ Spec::Example::Subject::ExampleMethods.should_receive(:register_subjects)
57
+ @config.load_language
58
+ end
59
+ end
@@ -1,4 +1,4 @@
1
- require 'spec-i18n'
1
+ require File.expand_path(File.join(__FILE__, "../../../../spec_helper"))
2
2
 
3
3
  Spec::Runner.configure do |config|
4
4
  config.spec_language :pt
@@ -10,16 +10,31 @@ class Pessoa
10
10
  @nome = nome
11
11
  @sobrenome = sobrenome
12
12
  @idade = opcoes[:idade]
13
+ @filhos = opcoes[:filhos]
13
14
  end
14
15
 
15
16
  def nome_completo
16
17
  "#{@nome} #{@sobrenome}"
17
18
  end
18
-
19
+
20
+ def informacoes
21
+ return nil if nome_completo.strip.empty?
22
+ nome_completo
23
+ end
24
+
25
+ def filhos
26
+ @filhos || []
27
+ end
28
+
19
29
  def maior_de_idade?
20
30
  return true if @idade >= 18
21
31
  false
22
32
  end
33
+
34
+ def menor_de_idade?
35
+ return false if maior_de_idade?
36
+ true
37
+ end
23
38
 
24
39
  def pronto_para_votar?
25
40
  maior_de_idade?
@@ -57,28 +72,28 @@ descreva Pessoa do
57
72
  @pessoas = []
58
73
  end
59
74
 
60
- exemplo 'deve ser uma instancia da classe Pessoa' do
75
+ isto 'deve ser uma instancia da classe Pessoa' do
61
76
  @pessoa.deve ser_instancia_de(Pessoa)
62
77
  end
63
78
 
64
- exemplo 'deve incluir uma pessoa' do
79
+ isto 'deve incluir uma pessoa' do
65
80
  @pessoas.deve incluir(@pessoa)
66
81
  end
67
82
 
68
- exemplo 'deve ser do tipo Pessoa' do
83
+ isto 'deve ser do tipo Pessoa' do
69
84
  @pessoa.deve ser_do_tipo(Pessoa)
70
85
  end
71
86
 
72
- exemplo 'deve ter pelo menos uma pessoa' do
87
+ isto 'deve ter pelo menos uma pessoa' do
73
88
  @pessoas.deve ter_no_minimo(1).items
74
89
  end
75
90
 
76
- exemplo 'deve ter exatamente duas pessoas' do
91
+ isto 'deve ter exatamente duas pessoas' do
77
92
  @pessoas << @pessoa
78
93
  @pessoas.deve ter_exatamente(2).items
79
94
  end
80
95
 
81
- exemplo 'deve ter no maximo tres pessoas' do
96
+ isto 'deve ter no maximo tres pessoas' do
82
97
  @pessoas = []
83
98
  @pessoas.deve ter_no_maximo(3).items
84
99
  end
@@ -89,11 +104,11 @@ descreva Pessoa do
89
104
  @pessoa = Pessoa.new("Tomás", "D'Stefano")
90
105
  end
91
106
 
92
- exemplo "deve retornar o nome completo" do
107
+ isto "deve retornar o nome completo" do
93
108
  @pessoa.nome_completo.deve ==("Tomás D'Stefano")
94
109
  end
95
110
 
96
- exemplo 'nome completo não pode ser nulo' do
111
+ isto 'nome completo não pode ser nulo' do
97
112
  @pessoa.nome_completo.nao_deve ser_igual_a(nil)
98
113
  end
99
114
 
@@ -108,6 +123,23 @@ descreva Pessoa do
108
123
  especificar "deve ser opcional" do
109
124
  @pessoa.idade.deve ser_igual_a(20)
110
125
  end
126
+
127
+ exemplo "deve retornar verdadeiro se for maior de idade" do
128
+ @pessoa.maior_de_idade?.deve ser_verdadeiro
129
+ end
130
+
131
+ exemplo "deve retornar falso se for menor de idade" do
132
+ @pessoa.menor_de_idade?.deve ser_falso
133
+ end
134
+
135
+ exemplo "deve retornar nulo caso nao tenha informacao" do
136
+ Pessoa.new("", "").informacoes.deve ser_nulo
137
+ end
138
+
139
+ exemplo "deve não ter nenhum filho" do
140
+ @pessoa.filhos.deve ser_vazio
141
+ end
142
+
111
143
  end
112
144
 
113
145
  contexto 'maior de idade' do
@@ -116,7 +148,7 @@ descreva Pessoa do
116
148
  exemplo "deve estar pronto para votar" do
117
149
  deve estar_pronto_para_votar
118
150
  end
119
-
151
+
120
152
  exemplo "deve ser maior de idade" do
121
153
  deve ser_maior_de_idade
122
154
  end
data/spec/spec_helper.rb CHANGED
@@ -47,6 +47,7 @@ def with_sandboxed_config
47
47
 
48
48
  before(:each) do
49
49
  @config = ::Spec::Runner::Configuration.new
50
+ @config.should_receive(:load_language).at_least(:once).and_return(true)
50
51
  @original_configuration = ::Spec::Runner.configuration
51
52
  spec_configuration = @config
52
53
  ::Spec::Runner.instance_eval {@configuration = spec_configuration}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-i18n
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomas D'Stefano
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-19 00:00:00 -02:00
12
+ date: 2010-03-13 00:00:00 -03:00
13
13
  default_executable: rspec-i18n
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -153,7 +153,7 @@ post_install_message: |
153
153
  --------------------------------------------------------------------------------
154
154
  U P G R A D I N G
155
155
 
156
- Thank you for installing rspec-i18n-1.0.0
156
+ Thank you for installing rspec-i18n-1.1.0
157
157
  Please be sure to read http://wiki.github.com/tomas-stefano/rspec-i18n/upgrading
158
158
  for information about this release.
159
159