rspec-i18n 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.rdoc ADDED
@@ -0,0 +1,9 @@
1
+ === Version 0.1.0
2
+
3
+ This is the first preview release of Rspec-i18n, a Internacionalization Development library for Ruby.
4
+
5
+ * Added translation to all the base keywords(describe, it, should, should_not,
6
+ before(:each), before(:all), before(:suite), after(:each), after(:all),
7
+ after(:suite))
8
+ * Added a languages.yml. Will be translated to all languages.
9
+ * Added a simple parser for the read the languages in languages.yml.
data/License.txt ADDED
@@ -0,0 +1,23 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2009 Tomás D'Stefano
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+
data/README.rdoc ADDED
@@ -0,0 +1,64 @@
1
+ = Rspec-i18n
2
+
3
+ == Description
4
+
5
+ The Rspec-i18n gem provide a easy way to write specs in any language you
6
+ prefer. The Rspec-i18n was created for the purpose of teaching people who are
7
+ starting to developing applications but also serves to Production use.
8
+ I know that many people prefer to write code/specs in English =)
9
+
10
+ But if you don't prefer that, you'll like the Rspec-i18n.
11
+
12
+ == Synopsis
13
+
14
+ Rspec-i18n will supports any language you want(See languages.yml file). This is
15
+ Portuguese(Brazil):
16
+
17
+ require 'spec'
18
+ require 'spec-i18n'
19
+
20
+ Spec::Runner.configure do |config|
21
+
22
+ config.spec_language :pt
23
+
24
+ ...
25
+ end
26
+
27
+ # In spec/pessoa_spec.rb
28
+
29
+ require 'spec_helper'
30
+
31
+ descreva Pessoa do
32
+ antes(:de_cada) do
33
+ @nome = "Tomas"
34
+ @pessoa = Pessoa.new(@nome)
35
+ end
36
+
37
+ exemplo "retornar o seu nome" do
38
+ @pessoa.nome.deve == @nome
39
+ end
40
+ end
41
+
42
+ == Examples
43
+
44
+ See more examples in the examples folder
45
+
46
+ == Listing the available languages
47
+
48
+ spec-i18n --language help (NOT YET IMPLEMENTED)
49
+
50
+ == Adding a new language or completing a existing one(based on Cucumber implementation)
51
+
52
+ 1. Make a fork of Rspec-i18n and pull it down
53
+ 2. Add your language keywords to languages.yml
54
+ 3. Commit and push your changes - then send a pull request at Github
55
+
56
+ ** OBS: Hints for better words in languages.yml are Welcome =D.
57
+
58
+ == Install
59
+
60
+ [sudo] gem install rspec-i18n
61
+
62
+ == TODO
63
+
64
+ See the TODO.txt file and see more details
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ # encoding: utf-8
2
+ require 'rubygems'
3
+ require 'rake'
4
+
5
+ $:.unshift(File.dirname(__FILE__) + '/lib')
6
+
7
+ begin
8
+ require 'jeweler'
9
+ Jeweler::Tasks.new do |gemspec|
10
+ gemspec.name = "rspec-i18n"
11
+ gemspec.summary = "The internacionalization gem for Rspec"
12
+ gemspec.description = "A internacionalization tool written in Ruby"
13
+ gemspec.email = "tomasdestefi@gmail.com"
14
+ gemspec.homepage = "http://github.com/tomas-stefano/rspec-i18n"
15
+ gemspec.authors = ["Tomas D'Stefano"]
16
+
17
+ gemspec.add_dependency('rspec', '>= 1.2.9')
18
+
19
+ gemspec.add_development_dependency('rspec', '>= 1.2.9')
20
+ end
21
+ Jeweler::GemcutterTasks.new
22
+ rescue LoadError
23
+ puts("-" * 80)
24
+ puts "Jeweler not available. Install it with:
25
+ [sudo] gem install jeweler"
26
+ puts("-" * 80)
27
+ end
data/TODO.txt ADDED
@@ -0,0 +1,31 @@
1
+ == Refactoring
2
+
3
+ * The SpecI18n::Parser::NaturalLanguage.get(SpecI18n.spec_language) is duplicated in
4
+ some places - check a better way to implement this
5
+ * Simplified more and more tests!
6
+ * Find the right module for the example group specs(it/example) (I think =>
7
+ Spec::Example::ExampleGroupMethods but I think I was wrong)
8
+
9
+ == Future
10
+
11
+ * Translate all matchers
12
+ * Translate subjects
13
+ * Translate shared examples
14
+ * Put a #language header in the spec_helper file (Cucumber Style) instead load from config(maintain the two options)
15
+ * Create the directory features to test with Cucumber
16
+ * Make the describe/it i18n available from a class
17
+
18
+ Example:
19
+ # class StackSpec < Spec::ExampleGroup
20
+ # describe Stack, "with no elements"
21
+ #
22
+ # before
23
+ # @stack = Stack.new
24
+ # end
25
+ #
26
+ # it "should raise on pop" do
27
+ # lambda{ @stack.pop }.should raise_error
28
+ # end
29
+ # end
30
+
31
+ * Check a better way to manipulating the mocks and stubs for i18n (What do you think?)
data/VERSION.yml ADDED
@@ -0,0 +1,5 @@
1
+ ---
2
+ :patch: 0
3
+ :major: 0
4
+ :minor: 1
5
+ :build:
data/bin/rspec-i18n ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env ruby
2
+ rspec_i18n_dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
@@ -0,0 +1,47 @@
1
+ require 'spec-i18n'
2
+
3
+ Spec::Runner.configure do |config|
4
+ config.spec_language :pt
5
+ end
6
+
7
+ class Pessoa
8
+ attr_reader :idade
9
+ def initialize(nome, sobrenome, idade=0)
10
+ @nome = nome
11
+ @sobrenome = sobrenome
12
+ @idade = idade
13
+ end
14
+
15
+ def nome_completo
16
+ "#{@nome} #{@sobrenome}"
17
+ end
18
+ end
19
+
20
+ # Silly Tests
21
+ descreva Pessoa do
22
+
23
+ antes(:de_todos) do
24
+ @pessoa = Pessoa.new("Tomás", "D'Stefano")
25
+ end
26
+
27
+ antes(:de_cada) do
28
+ @pessoas = [@pessoa]
29
+ end
30
+
31
+ depois(:de_todos) do
32
+ @outras_pessoas = @pessoas.dup
33
+ end
34
+
35
+ depois(:de_cada) do
36
+ @outras_pessoas = []
37
+ end
38
+
39
+ exemplo "deve retornar o nome completo" do
40
+ @pessoa.nome_completo.deve == "Tomás D'Stefano"
41
+ end
42
+
43
+ especificar "a idade é opcional" do
44
+ Pessoa.new("Aaromn", "Monkey", 20).idade.deve == 20
45
+ end
46
+
47
+ end
@@ -0,0 +1,22 @@
1
+ module Spec
2
+ module DSL
3
+ module Main
4
+
5
+ # Register adverbs for the dsl keywords
6
+ #
7
+ # { "describe" => ["descreva", "contexto"]}
8
+ #
9
+ # Register alias for the language specified
10
+ def register_adverbs
11
+ language = SpecI18n::Parser::NaturalLanguage.get(SpecI18n.spec_language)
12
+ @adverbs = language.dsl_keywords
13
+ @adverbs.each do |key, values|
14
+ values.map { |value| alias_method value, key }
15
+ end
16
+ end
17
+
18
+ end
19
+ end
20
+ end
21
+
22
+ include Spec::DSL::Main
@@ -0,0 +1,2 @@
1
+ require 'spec-i18n/spec_language'
2
+ require 'spec-i18n/dsl/main'
@@ -0,0 +1,51 @@
1
+ module Spec
2
+ module Example
3
+ module BeforeAndAfterHooks
4
+
5
+ def register_hooks
6
+ language = SpecI18n::Parser::NaturalLanguage.get(SpecI18n.spec_language)
7
+ language.before_and_after_keywords.each do |key, values|
8
+ values.map { |value| alias_method value, key }
9
+ end
10
+ end
11
+
12
+ def before_parts(scope)
13
+ if SpecI18n.spec_language
14
+ language = SpecI18n::Parser::NaturalLanguage.get(SpecI18n.spec_language)
15
+ scope = grep_the_scope(scope, language.hooks_params_keywords)
16
+ end
17
+ case scope
18
+ when :each; before_each_parts
19
+ when :all; before_all_parts
20
+ when :suite; before_suite_parts
21
+ end
22
+ end
23
+
24
+ def after_parts(scope)
25
+ if SpecI18n.spec_language
26
+ language = SpecI18n::Parser::NaturalLanguage.get(SpecI18n.spec_language)
27
+ scope = grep_the_scope(scope, language.hooks_params_keywords)
28
+ end
29
+ case scope
30
+ when :each; after_each_parts
31
+ when :all; after_all_parts
32
+ when :suite; after_suite_parts
33
+ end
34
+ end
35
+
36
+ # Receive a String Scope and return the scope in english for
37
+ # the rspec run the right method
38
+ def grep_the_scope(scope, hooks)
39
+ scopes = [:each, :all, :suite]
40
+ return scope if scopes.include?(scope)
41
+
42
+ hooks.each do |scope_in_english, language_hooks|
43
+ return scope_in_english.to_sym if language_hooks.include?(scope.to_s)
44
+ end
45
+ end
46
+
47
+ end
48
+ end
49
+ end
50
+
51
+ include Spec::Example::BeforeAndAfterHooks
@@ -0,0 +1,17 @@
1
+ module Spec
2
+ module Example
3
+ module ExampleGroupMethods
4
+
5
+ def self.register_example_adverbs
6
+ language = SpecI18n::Parser::NaturalLanguage.get(SpecI18n.spec_language)
7
+ @adverbs = language.example_group_keywords
8
+ @adverbs.each do |key, values|
9
+ values.map do |value|
10
+ alias_method value, key
11
+ end
12
+ end
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,2 @@
1
+ require 'spec-i18n/example/before_and_after_hooks'
2
+ require 'spec-i18n/example/example_group_methods'
@@ -0,0 +1,9 @@
1
+ module Kernel
2
+ def register_expectations_keywords
3
+ language = SpecI18n::Parser::NaturalLanguage.get(SpecI18n.spec_language)
4
+ @adverbs = language.expectation_keywords
5
+ @adverbs.each do |key, values|
6
+ values.map { |value| alias_method value, key }
7
+ end
8
+ end
9
+ end
@@ -0,0 +1 @@
1
+ require 'spec-i18n/expectations/extensions/kernel'
@@ -0,0 +1 @@
1
+ require 'spec-i18n/expectations/extensions'
@@ -0,0 +1,54 @@
1
+ # encoding: utf-8
2
+ #
3
+ # (based on Cucumber implementation)
4
+ # If you want several aliases for a keyword, just a separate them
5
+ # with a | character. Make sure there are no ambiguities in the keywords
6
+
7
+ "en":
8
+ name: English
9
+ nativo: English
10
+ describe: describe
11
+ it: it|specify
12
+ should: should
13
+ should_not: should_not
14
+ before: before
15
+ after: after
16
+ hooks:
17
+ each: each
18
+ all: all
19
+ suite: suite
20
+ matchers:
21
+ be_equal: be_equal
22
+
23
+ "pt":
24
+ name: Portuguese
25
+ nativo: português
26
+ describe: descreva|contexto
27
+ it: exemplo|especificar
28
+ should: deve
29
+ should_not: nao_deve
30
+ before: antes
31
+ after: depois
32
+ hooks:
33
+ each: de_cada|de_cada_exemplo
34
+ all: de_todos|de_todos_exemplos
35
+ suite: suite
36
+ matchers:
37
+ be_equal: ser_igual_a
38
+
39
+ # Please put the right words for this language! =D
40
+ "es":
41
+ name: Spanish
42
+ native: español
43
+ describe: describir
44
+ it: ejemplo
45
+ should: deberia
46
+ should_not: no_debe
47
+ before: antes
48
+ after: despues
49
+ hooks:
50
+ each: de_cada_ejemplo
51
+ all: de_todos_ejemplo
52
+ suite: suite
53
+ matchers:
54
+ be_equal: ser_igual_a
@@ -0,0 +1,63 @@
1
+ module SpecI18n
2
+ module Parser
3
+ class NaturalLanguage
4
+ KEYWORDS_LANGUAGE = %w{ name native describe before after it should}
5
+
6
+ class << self
7
+ def get(language)
8
+ new(language)
9
+ end
10
+
11
+ def all
12
+ SpecI18n::SPEC_LANGUAGES.keys.sort.map { |language| get(language) }
13
+ end
14
+ end
15
+
16
+ attr_reader :keywords
17
+
18
+ def initialize(language)
19
+ @keywords = SpecI18n::SPEC_LANGUAGES[language]
20
+ raise(LanguageNotFound, "Language #{language} Not Supported") if @keywords.nil?
21
+ @parser = nil
22
+ end
23
+
24
+ def dsl_keywords
25
+ spec_keywords("describe")
26
+ end
27
+
28
+ def expectation_keywords
29
+ language_adverbs = spec_keywords("should")
30
+ language_adverbs.merge(spec_keywords("should_not"))
31
+ end
32
+
33
+ def before_and_after_keywords
34
+ adverbs = spec_keywords("before")
35
+ adverbs.merge(spec_keywords("after"))
36
+ end
37
+
38
+ def hooks_params_keywords
39
+ hooks = {}
40
+ keywords['hooks'].each do |hook, value|
41
+ values = value.split('|')
42
+ hooks[hook] = values
43
+ end
44
+ hooks
45
+ end
46
+
47
+ def example_group_keywords
48
+ spec_keywords("it")
49
+ end
50
+
51
+ def spec_keywords(key, space=false)
52
+ raise "No #{key} in #{@keywords.inspect}" if @keywords[key].nil?
53
+ values = keywords[key].split('|')
54
+ { key => values }
55
+ end
56
+
57
+ end
58
+
59
+ class LanguageNotFound < StandardError
60
+ end
61
+
62
+ end
63
+ end
@@ -0,0 +1,2 @@
1
+ require 'spec-i18n/platform'
2
+ require 'spec-i18n/parser/natural_language'
@@ -0,0 +1,8 @@
1
+ require 'yaml'
2
+
3
+ module SpecI18n
4
+ version = YAML.load_file(File.dirname(__FILE__) + '/../../VERSION.yml')
5
+ SPEC_I18n_VERSION = [version[:major], version[:minor], version[:build]].compact.join(".")
6
+ SPEC_LANGUAGE_FILE = File.expand_path(File.dirname(__FILE__) + '/languages.yml')
7
+ SPEC_LANGUAGES = YAML.load_file(SPEC_LANGUAGE_FILE)
8
+ end
@@ -0,0 +1,27 @@
1
+ module Spec
2
+ module Runner
3
+ class Configuration
4
+ def spec_language(language)
5
+ @spec_language = language ? language.to_s : "en"
6
+ load_language
7
+ @spec_language
8
+ end
9
+
10
+ def language
11
+ @spec_language
12
+ end
13
+
14
+ # Load all Modules and Classes for the language specified
15
+ def load_language
16
+ Spec::DSL::Main.register_adverbs
17
+ Kernel.register_expectations_keywords
18
+ Spec::Example::ExampleGroupMethods.register_example_adverbs
19
+ Spec::Example::BeforeAndAfterHooks.register_hooks
20
+ end
21
+ end
22
+
23
+ class UndefinedLanguageError < StandardError
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,2 @@
1
+ require 'spec-i18n/runner/configuration'
2
+
@@ -0,0 +1,7 @@
1
+ module SpecI18n
2
+ def spec_language
3
+ Spec::Runner.configuration.language
4
+ end
5
+ end
6
+
7
+ include SpecI18n
data/lib/spec-i18n.rb ADDED
@@ -0,0 +1,10 @@
1
+
2
+ require 'yaml'
3
+ require 'spec'
4
+ require 'spec-i18n/platform'
5
+ require 'spec-i18n/runner'
6
+ require 'spec-i18n/spec_language'
7
+ require 'spec-i18n/parser'
8
+ require 'spec-i18n/example'
9
+ require 'spec-i18n/expectations'
10
+ require 'spec-i18n/dsl'
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+ include Spec::DSL
3
+
4
+ describe Main do
5
+
6
+ before(:each) do
7
+ @languages = ["en", "pt", "es"]
8
+ end
9
+
10
+ describe 'the manipulation of methods of the domain specific language' do
11
+
12
+ 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)
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ end
@@ -0,0 +1,129 @@
1
+ require 'spec_helper'
2
+
3
+ module Spec
4
+ module Example
5
+ describe BeforeAndAfterHooks do
6
+
7
+ before(:each) do
8
+ @languages = ["pt", "en", "es"]
9
+ end
10
+
11
+ 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)
15
+ language.before_and_after_keywords.keys.map do |keyword|
16
+ BeforeAndAfterHooks.methods.should be_include(keyword)
17
+ end
18
+ end
19
+ end
20
+
21
+ context "the before hook" do
22
+
23
+ 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)
27
+ scope = language.hooks_params_keywords["each"].first
28
+ self.should_receive(:before_each_parts)
29
+ before_parts(scope)
30
+ end
31
+ end
32
+
33
+ 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)
37
+ scope = language.hooks_params_keywords["all"].first
38
+ self.should_receive(:before_all_parts)
39
+ before_parts(scope)
40
+ end
41
+ end
42
+
43
+ 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
48
+ self.should_receive(:before_suite_parts)
49
+ before_parts(scope)
50
+ end
51
+ end
52
+ end
53
+
54
+ context "the after hook" do
55
+ 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
60
+ self.should_receive(:after_all_parts)
61
+ after_parts(scope)
62
+ end
63
+ end
64
+ end
65
+
66
+ context "grep the scope and call the hook" do
67
+
68
+ before(:each) do
69
+ @pt = Spec::Runner.configuration.spec_language(:pt)
70
+ @language = SpecI18n::Parser::NaturalLanguage.get(@pt)
71
+ @hooks = @language.hooks_params_keywords
72
+ end
73
+
74
+ it "should return the same scope if scope is in English" do
75
+ [:each, :all, :suite].each do |scope|
76
+ grep_the_scope(scope, @hooks).should == scope
77
+ end
78
+ end
79
+
80
+ it "should grep the scope each" do
81
+ scopes = @hooks["each"]
82
+ scopes.each do |scope|
83
+ grep_the_scope(scope, @hooks).should == :each
84
+ end
85
+ end
86
+
87
+ it "should grep the scope all" do
88
+ scopes = @hooks["all"]
89
+ scopes.each do |scope|
90
+ grep_the_scope(scope, @hooks).should == :all
91
+ end
92
+ end
93
+
94
+ it "should grep the scope suite" do
95
+ scopes = @hooks["suite"]
96
+ scopes.each do |scope|
97
+ grep_the_scope(scope, @hooks).should == :suite
98
+ end
99
+ end
100
+
101
+ context "with Symbol scopes" do
102
+
103
+ it "should grep the scope :each" do
104
+ scopes = @hooks["each"].map { |hook| hook.to_sym }
105
+ scopes.each do |scope|
106
+ grep_the_scope(scope, @hooks).should == :each
107
+ end
108
+ end
109
+
110
+ it "should grep the scope :all" do
111
+ scopes = @hooks["all"].map { |hook| hook.to_sym }
112
+ scopes.each do |scope|
113
+ grep_the_scope(scope, @hooks).should == :all
114
+ end
115
+ end
116
+
117
+ it "should grep the scope :suite" do
118
+ scopes = @hooks["suite"].map { |hook| hook.to_sym }
119
+ scopes.each do |scope|
120
+ grep_the_scope(scope, @hooks).should == :suite
121
+ end
122
+ end
123
+
124
+ end
125
+ end
126
+
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,22 @@
1
+ require "spec_helper"
2
+
3
+ module Spec
4
+ module Example
5
+ describe ExampleGroupMethods do
6
+
7
+ before(:each) do
8
+ @languages = ["pt", "es", "en"]
9
+ end
10
+
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)"
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,47 @@
1
+ require 'spec-i18n'
2
+
3
+ Spec::Runner.configure do |config|
4
+ config.spec_language :pt
5
+ end
6
+
7
+ class Pessoa
8
+ attr_reader :idade
9
+ def initialize(nome, sobrenome, idade=0)
10
+ @nome = nome
11
+ @sobrenome = sobrenome
12
+ @idade = idade
13
+ end
14
+
15
+ def nome_completo
16
+ "#{@nome} #{@sobrenome}"
17
+ end
18
+ end
19
+
20
+ # Silly Tests
21
+ descreva Pessoa do
22
+
23
+ antes(:de_todos) do
24
+ @pessoa = Pessoa.new("Tomás", "D'Stefano")
25
+ end
26
+
27
+ antes(:de_cada) do
28
+ @pessoas = [@pessoa]
29
+ end
30
+
31
+ depois(:de_todos) do
32
+ @outras_pessoas = @pessoas.dup
33
+ end
34
+
35
+ depois(:de_cada) do
36
+ @outras_pessoas = []
37
+ end
38
+
39
+ exemplo "deve retornar o nome completo" do
40
+ @pessoa.nome_completo.deve == "Tomás D'Stefano"
41
+ end
42
+
43
+ especificar "a idade é opcional" do
44
+ Pessoa.new("Aaromn", "Monkey", 20).idade.deve == 20
45
+ end
46
+
47
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe Object, "#should and #should_not" do
4
+
5
+ before(:each) do
6
+ @languages = ["pt", "en", "es"]
7
+ end
8
+
9
+ 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
+ language.expectation_keywords.values.flatten.each do |keyword|
14
+ Kernel.methods.should be_include(keyword)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,123 @@
1
+ require 'spec_helper'
2
+
3
+ module SpecI18n
4
+ module Parser
5
+ describe NaturalLanguage do
6
+
7
+ before(:each) do
8
+ @pt = NaturalLanguage.get('pt')
9
+ @es = NaturalLanguage.get('es')
10
+ @en = NaturalLanguage.get('en')
11
+ end
12
+
13
+ context "get languages" do
14
+
15
+ it "should get the default language" do
16
+ NaturalLanguage.get("en").should_not be_nil
17
+ end
18
+
19
+ it "should raise for the non existing language" do
20
+ language = "non_existing"
21
+ lambda {
22
+ NaturalLanguage.new(language)
23
+ }.should raise_error(LanguageNotFound, "Language #{language} Not Supported")
24
+ end
25
+
26
+ end
27
+
28
+ %w(describe before after it should).each do |keyword|
29
+ it "should have the #{keyword} keyword" do
30
+ @pt.keywords.keys.should be_include(keyword)
31
+ end
32
+ end
33
+
34
+ context "of dsl keywords" do
35
+
36
+ it "should return all the dsl keywords" do
37
+ @pt.dsl_keywords.should == {"describe" => [ "descreva", "contexto"] }
38
+ end
39
+
40
+ it "should return the describe dsl keyword" do
41
+ lang = { "describe" => "descreva", :before => "antes" }
42
+ @pt.should_receive(:keywords).and_return(lang)
43
+ @pt.dsl_keywords.should == { "describe" => [ lang["describe"] ] }
44
+ end
45
+ end
46
+
47
+ context "of expectations keywords" do
48
+
49
+ before(:each) do
50
+ @keywords = { "should" => ["deve"], "should_not" => ["nao_deve"] }
51
+ end
52
+
53
+ it "should return the expectation keyword of the language" do
54
+ lang = {"describe" => "descreva", "should" => "deve", "should_not" => "nao_deve"}
55
+ @pt.should_receive(:keywords).twice.and_return(lang)
56
+ @pt.expectation_keywords.should == @keywords
57
+ end
58
+
59
+ it "should return the expectation keywords of the current language" do
60
+ keywords = { "should" => ["deberia"], "should_not" => ["no_debe"]}
61
+ @es.expectation_keywords.should == keywords
62
+ end
63
+ end
64
+
65
+ context "of before and after keywords" do
66
+
67
+ it "should return the hooks for the current language" do
68
+ keywords = { "before" => ["before"], "after" => ["after"]}
69
+ @en.before_and_after_keywords.should == keywords
70
+ end
71
+
72
+ it "should return the hooks for the language" do
73
+ keywords = { "before" => ["antes"], "after" => ["depois"]}
74
+ @pt.before_and_after_keywords.should == keywords
75
+ end
76
+ end
77
+
78
+ context "of hooks keywords" do
79
+
80
+ it "should return the hooks parameters for the current language" do
81
+ keywords = { "each" => ["de_cada", "de_cada_exemplo"],
82
+ "all" => ["de_todos", "de_todos_exemplos"],
83
+ "suite" => ["suite"]}
84
+ @pt.hooks_params_keywords.should == keywords
85
+ end
86
+ end
87
+
88
+ context "of example group keywords" do
89
+
90
+ before(:each) do
91
+ @keywords = { "it" => ["exemplo", "especificar"] }
92
+ end
93
+
94
+ it "should return the example group keywords for the current language" do
95
+ @pt.example_group_keywords.should == @keywords
96
+ end
97
+
98
+ it "should return the example group for the portuguese language" do
99
+ @keywords = { "it" => ["it", "specify"]}
100
+ @en.example_group_keywords.should == @keywords
101
+ end
102
+ end
103
+
104
+ context "of all matchers" do
105
+ it "should parse all matchers"
106
+ end
107
+
108
+ context "splitting the keys" do
109
+ it "should raise no found key" do
110
+ lambda {
111
+ @pt.spec_keywords("no_found")
112
+ }.should raise_error(RuntimeError)
113
+ end
114
+
115
+ it "should split correctly the keys" do
116
+ lang = { "describe" => "descreva|contexto" }
117
+ NaturalLanguage.instance_variable_set(:@keywords, lang["describe"])
118
+ @pt.spec_keywords("describe").should == { "describe" => ["descreva", "contexto"] }
119
+ end
120
+ end
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+
3
+ module Spec
4
+ module Runner
5
+ describe Configuration do
6
+ with_sandboxed_options do
7
+ with_sandboxed_config do
8
+ describe "#spec_language" do
9
+
10
+ it "should default a english language for nil" do
11
+ config.spec_language(nil).should == "en"
12
+ end
13
+
14
+ it "should return a pt language" do
15
+ config.spec_language(:pt).should == "pt"
16
+ end
17
+
18
+ it "should return a es language using a Symbol" do
19
+ config.spec_language(:es).should == "es"
20
+ end
21
+
22
+ it "should return a en language for the nil parameter" do
23
+ config.spec_language(nil)
24
+ config.language.should == "en"
25
+ end
26
+
27
+ it "should set the portuguese language" do
28
+ config.spec_language(:pt)
29
+ config.language.should == "pt"
30
+ end
31
+
32
+ it "should set the espanish language" do
33
+ config.spec_language(:es)
34
+ config.language.should == "es"
35
+ end
36
+
37
+ end
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
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ module Spec
4
+ describe Runner do
5
+
6
+ describe "the right language for the specs" do
7
+
8
+ before(:each) do
9
+ @language = :pt
10
+ end
11
+
12
+ it "should assign the spec_language" do
13
+ Spec::Runner.configure do |config|
14
+ config.spec_language @language
15
+ end
16
+ Spec::Runner.configuration.language.should == @language.to_s
17
+ end
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,16 @@
1
+ require "spec_helper"
2
+
3
+ describe SpecI18n do
4
+
5
+ before(:each) do
6
+ include SpecI18n
7
+ end
8
+
9
+ it "should assign the spec language constant" do
10
+ languages = ["pt", "es"]
11
+ languages.each do |language|
12
+ Spec::Runner.configuration.spec_language(language)
13
+ spec_language.should == language
14
+ end
15
+ end
16
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,3 @@
1
+ --colour
2
+ --diff
3
+ --format specdoc
@@ -0,0 +1,40 @@
1
+ require 'rubygems'
2
+ require 'ruby-debug'
3
+ require 'spec'
4
+ require 'spec-i18n'
5
+
6
+ $:.unshift(File.dirname(__FILE__), '../lib')
7
+
8
+ def with_sandboxed_options
9
+ attr_reader :options
10
+
11
+ before(:each) do
12
+ @original_rspec_options = ::Spec::Runner.options
13
+ ::Spec::Runner.use(@options = ::Spec::Runner::Options.new(StringIO.new, StringIO.new))
14
+ end
15
+
16
+ after(:each) do
17
+ ::Spec::Runner.use(@original_rspec_options)
18
+ end
19
+
20
+ yield
21
+ end
22
+
23
+ def with_sandboxed_config
24
+ attr_reader :config
25
+
26
+ before(:each) do
27
+ @config = ::Spec::Runner::Configuration.new
28
+ @original_configuration = ::Spec::Runner.configuration
29
+ spec_configuration = @config
30
+ ::Spec::Runner.instance_eval {@configuration = spec_configuration}
31
+ end
32
+
33
+ after(:each) do
34
+ original_configuration = @original_configuration
35
+ ::Spec::Runner.instance_eval {@configuration = original_configuration}
36
+ ::Spec::Example::ExampleGroupFactory.reset
37
+ end
38
+
39
+ yield
40
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec-i18n
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tomas D'Stefano
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-12-27 00:00:00 -02:00
13
+ default_executable: rspec-i18n
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.2.9
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.2.9
34
+ version:
35
+ description: A internacionalization tool written in Ruby
36
+ email: tomasdestefi@gmail.com
37
+ executables:
38
+ - rspec-i18n
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - README.rdoc
43
+ files:
44
+ - History.rdoc
45
+ - License.txt
46
+ - README.rdoc
47
+ - Rakefile
48
+ - TODO.txt
49
+ - VERSION.yml
50
+ - bin/rspec-i18n
51
+ - examples/person_spec.rb
52
+ - lib/spec-i18n.rb
53
+ - lib/spec-i18n/dsl.rb
54
+ - lib/spec-i18n/dsl/main.rb
55
+ - lib/spec-i18n/example.rb
56
+ - lib/spec-i18n/example/before_and_after_hooks.rb
57
+ - lib/spec-i18n/example/example_group_methods.rb
58
+ - lib/spec-i18n/expectations.rb
59
+ - lib/spec-i18n/expectations/extensions.rb
60
+ - lib/spec-i18n/expectations/extensions/kernel.rb
61
+ - lib/spec-i18n/languages.yml
62
+ - lib/spec-i18n/parser.rb
63
+ - lib/spec-i18n/parser/natural_language.rb
64
+ - lib/spec-i18n/platform.rb
65
+ - lib/spec-i18n/runner.rb
66
+ - lib/spec-i18n/runner/configuration.rb
67
+ - lib/spec-i18n/spec_language.rb
68
+ - spec/spec-i18n/dsl/main_spec.rb
69
+ - spec/spec-i18n/example/before_and_after_hooks_spec.rb
70
+ - spec/spec-i18n/example/example_group_methods_spec.rb
71
+ - spec/spec-i18n/example_spec.rb
72
+ - spec/spec-i18n/expectations/kernel_spec.rb
73
+ - spec/spec-i18n/parser/natural_language_spec.rb
74
+ - spec/spec-i18n/runner/configuration_spec.rb
75
+ - spec/spec-i18n/runner/runner_spec.rb
76
+ - spec/spec-i18n/spec_language_spec.rb
77
+ - spec/spec.opts
78
+ - spec/spec_helper.rb
79
+ has_rdoc: true
80
+ homepage: http://github.com/tomas-stefano/rspec-i18n
81
+ licenses: []
82
+
83
+ post_install_message:
84
+ rdoc_options:
85
+ - --charset=UTF-8
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: "0"
93
+ version:
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: "0"
99
+ version:
100
+ requirements: []
101
+
102
+ rubyforge_project:
103
+ rubygems_version: 1.3.5
104
+ signing_key:
105
+ specification_version: 3
106
+ summary: The internacionalization gem for Rspec
107
+ test_files:
108
+ - spec/spec-i18n/dsl/main_spec.rb
109
+ - spec/spec-i18n/example/before_and_after_hooks_spec.rb
110
+ - spec/spec-i18n/example/example_group_methods_spec.rb
111
+ - spec/spec-i18n/example_spec.rb
112
+ - spec/spec-i18n/expectations/kernel_spec.rb
113
+ - spec/spec-i18n/parser/natural_language_spec.rb
114
+ - spec/spec-i18n/runner/configuration_spec.rb
115
+ - spec/spec-i18n/runner/runner_spec.rb
116
+ - spec/spec-i18n/spec_language_spec.rb
117
+ - spec/spec_helper.rb
118
+ - examples/person_spec.rb