Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Migrate tests to RSpec. Also remove Jeweler dependency in favor of Bu…

…ndler.
  • Loading branch information...
commit 6435fa0a6bfbc49a6d2f154864efb65f20db6ccd 1 parent d6d915e
@fnando authored
View
2  Gemfile
@@ -0,0 +1,2 @@
+source :rubygems
+gemspec
View
48 Gemfile.lock
@@ -0,0 +1,48 @@
+PATH
+ remote: .
+ specs:
+ i18n-js (0.1.6)
+ i18n
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ activesupport (3.0.1)
+ archive-tar-minitar (0.5.2)
+ columnize (0.3.1)
+ diff-lcs (1.1.2)
+ fakeweb (1.3.0)
+ i18n (0.4.1)
+ linecache19 (0.5.11)
+ ruby_core_source (>= 0.1.4)
+ rspec (2.0.0)
+ rspec-core (= 2.0.0)
+ rspec-expectations (= 2.0.0)
+ rspec-mocks (= 2.0.0)
+ rspec-core (2.0.0)
+ rspec-expectations (2.0.0)
+ diff-lcs (>= 1.1.2)
+ rspec-mocks (2.0.0)
+ rspec-core (= 2.0.0)
+ rspec-expectations (= 2.0.0)
+ ruby-debug-base19 (0.11.24)
+ columnize (>= 0.3.1)
+ linecache19 (>= 0.5.11)
+ ruby_core_source (>= 0.1.4)
+ ruby-debug19 (0.11.6)
+ columnize (>= 0.3.1)
+ linecache19 (>= 0.5.11)
+ ruby-debug-base19 (>= 0.11.19)
+ ruby_core_source (0.1.4)
+ archive-tar-minitar (>= 0.5.2)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ activesupport (>= 3.0.0)
+ fakeweb
+ i18n
+ i18n-js!
+ rspec (>= 2.0.0)
+ ruby-debug19
View
8 README.rdoc
@@ -237,9 +237,15 @@ Please respect the indentation rules. And use tabs, not spaces (on the JavaScrip
=== Running tests
+To run Ruby tests, you need to install http://github.com/rspec/rspec
+
+ gem install rspec
+
To run JavaScript tests, you need to install http://github.com/fnando/spec-js
-Then just run `rake`.
+ gem install specjs
+
+Then just run `rake spec`.
== License
View
48 Rakefile
@@ -1,47 +1,13 @@
-require 'rake'
-require 'rake/testtask'
-require 'rake/rdoctask'
-require 'spec_js/rake_task'
-require File.dirname(__FILE__) + '/lib/i18n-js/version'
-
-desc 'Default: run unit tests.'
-task :default => [:test, :"spec:js"]
+require "bundler"
+Bundler::GemHelper.install_tasks
+require "spec_js/rake_task"
SpecJs::RakeTask.new do |t|
t.env_js = false
end
-desc 'Test the i18n-js plugin.'
-Rake::TestTask.new(:test) do |t|
- t.libs << 'lib'
- t.libs << 'test'
- t.pattern = 'test/**/*_test.rb'
- t.verbose = true
-end
-
-desc 'Generate documentation for the i18n-js plugin.'
-Rake::RDocTask.new(:rdoc) do |rdoc|
- rdoc.rdoc_dir = 'doc'
- rdoc.title = 'I18n for JavaScript'
- rdoc.options << '--line-numbers' << '--inline-source'
- rdoc.rdoc_files.include('README.rdoc')
- rdoc.rdoc_files.include('lib/**/*.rb')
-end
+require "rspec/core/rake_task"
+RSpec::Core::RakeTask.new(:"spec:ruby")
-begin
- require 'jeweler'
-
- JEWEL = Jeweler::Tasks.new do |gem|
- gem.name = "i18n-js"
- gem.email = "fnando.vieira@gmail.com"
- gem.homepage = "http://github.com/fnando/i18n-js"
- gem.authors = ["Nando Vieira"]
- gem.version = SimplesIdeias::I18n::Version::STRING
- gem.summary = "It's a small library to provide the Rails I18n translations on the Javascript."
- gem.files = FileList["README.rdoc", "init.rb", "install.rb", "{lib,test,source}/**/*", "Rakefile"]
- end
-
- Jeweler::GemcutterTasks.new
-rescue LoadError => e
- puts "[JEWELER] You can't build a gem until you install jeweler with `gem install jeweler`"
-end
+desc "Run all specs"
+task :spec => [:"spec:ruby", :"spec:js"]
View
72 i18n-js.gemspec
@@ -1,61 +1,25 @@
-# Generated by jeweler
-# DO NOT EDIT THIS FILE DIRECTLY
-# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "i18n-js/version"
Gem::Specification.new do |s|
- s.name = %q{i18n-js}
- s.version = "0.1.6"
+ s.name = "i18n-js"
+ s.version = SimplesIdeias::I18n::Version::STRING
+ s.platform = Gem::Platform::RUBY
+ s.authors = ["Nando Vieira"]
+ s.email = ["fnando.vieira@gmail.com"]
+ s.homepage = "http://rubygems.org/gems/i18n-js"
+ s.summary = "It's a small library to provide the Rails I18n translations on the Javascript."
+ s.description = s.summary
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
- s.authors = ["Nando Vieira"]
- s.date = %q{2010-09-23}
- s.email = %q{fnando.vieira@gmail.com}
- s.extra_rdoc_files = [
- "README.rdoc"
- ]
- s.files = [
- "README.rdoc",
- "Rakefile",
- "init.rb",
- "install.rb",
- "lib/i18n-js.rb",
- "lib/i18n-js/railtie.rb",
- "lib/i18n-js/version.rb",
- "lib/tasks/i18n-js_tasks.rake",
- "source/i18n-js.yml",
- "source/i18n.js",
- "test/i18n-test.html",
- "test/i18n-test.js",
- "test/i18n_js_test.rb",
- "test/jsunittest/jsunittest.js",
- "test/jsunittest/unittest.css",
- "test/resources/custom_path.yml",
- "test/resources/default.yml",
- "test/resources/locales.yml",
- "test/resources/multiple_files.yml",
- "test/resources/no_scope.yml",
- "test/resources/simple_scope.yml",
- "test/test_helper.rb"
- ]
- s.homepage = %q{http://github.com/fnando/i18n-js}
- s.rdoc_options = ["--charset=UTF-8"]
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
- s.rubygems_version = %q{1.3.7}
- s.summary = %q{It's a small library to provide the Rails I18n translations on the Javascript.}
- s.test_files = [
- "test/i18n_js_test.rb",
- "test/test_helper.rb"
- ]
- if s.respond_to? :specification_version then
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
- s.specification_version = 3
-
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
- else
- end
- else
- end
+ s.add_dependency "i18n"
+ s.add_development_dependency "fakeweb"
+ s.add_development_dependency "activesupport", ">= 3.0.0"
+ s.add_development_dependency "rspec", ">= 2.0.0"
+ s.add_development_dependency "ruby-debug19"
end
-
View
0  spec/i18n.spec.js → spec/i18n_spec.js
File renamed without changes
View
163 spec/i18n_spec.rb
@@ -0,0 +1,163 @@
+require "spec_helper"
+
+if File.basename(Rails.root) != "tmp"
+ warn <<-TXT
+\e[31;5m
+WARNING: That will remove your project!
+Please go to #{File.expand_path(File.dirname(__FILE__) + "/..")} and run `rake spec`\e[0m
+TXT
+ exit 1
+end
+
+describe SimplesIdeias::I18n do
+ before do
+ # Remove temporary directory if already present
+ FileUtils.rm_r(Rails.root) if File.exist?(Rails.root)
+
+ # Create temporary directory to test the files generation
+ %w( config public/javascripts ).each do |path|
+ FileUtils.mkdir_p Rails.root.join(path)
+ end
+
+ # Overwrite defaut locales path to use fixtures
+ I18n.load_path = [File.dirname(__FILE__) + "/resources/locales.yml"]
+ end
+
+ after do
+ # Remove temporary directory
+ FileUtils.rm_r(Rails.root)
+ end
+
+ it "copies the configuration file" do
+ File.should_not be_file(SimplesIdeias::I18n.config_file)
+ SimplesIdeias::I18n.setup!
+ File.should be_file(SimplesIdeias::I18n.config_file)
+ end
+
+ it "keeps existing configuration file" do
+ File.open(SimplesIdeias::I18n.config_file, "w+") {|f| f << "ORIGINAL"}
+ SimplesIdeias::I18n.setup!
+
+ File.read(SimplesIdeias::I18n.config_file).should == "ORIGINAL"
+ end
+
+ it "copies JavaScript library" do
+ path = Rails.root.join("public/javascripts/i18n.js")
+
+ File.should_not be_file(path)
+ SimplesIdeias::I18n.setup!
+ File.should be_file(path)
+ end
+
+ it "loads configuration file" do
+ SimplesIdeias::I18n.setup!
+
+ SimplesIdeias::I18n.config?.should be_true
+ SimplesIdeias::I18n.config.should be_kind_of(HashWithIndifferentAccess)
+ SimplesIdeias::I18n.config.should_not be_empty
+ end
+
+ it "exports messages to default path when configuration file doesn't exist" do
+ SimplesIdeias::I18n.export!
+ File.should be_file(Rails.root.join("public/javascripts/translations.js"))
+ end
+
+ it "exports messages using the default configuration file" do
+ set_config "default.yml"
+ SimplesIdeias::I18n.should_receive(:save).with(translations, "public/javascripts/translations.js")
+ SimplesIdeias::I18n.export!
+ end
+
+ it "exports messages using custom output path" do
+ set_config "custom_path.yml"
+ SimplesIdeias::I18n.should_receive(:save).with(translations, "public/javascripts/translations/all.js")
+ SimplesIdeias::I18n.export!
+ end
+
+ it "sets default scope to * when not specified" do
+ set_config "no_scope.yml"
+ SimplesIdeias::I18n.should_receive(:save).with(translations, "public/javascripts/no_scope.js")
+ SimplesIdeias::I18n.export!
+ end
+
+ it "exports to multiple files" do
+ set_config "multiple_files.yml"
+ SimplesIdeias::I18n.export!
+
+ File.should be_file(Rails.root.join("public/javascripts/all.js"))
+ File.should be_file(Rails.root.join("public/javascripts/tudo.js"))
+ end
+
+ it "filters translations using scope *.date.formats" do
+ result = SimplesIdeias::I18n.filter(translations, "*.date.formats")
+ result[:en][:date].keys.should == [:formats]
+ result[:fr][:date].keys.should == [:formats]
+ end
+
+ it "filters translations using scope [*.date.formats, *.number.currency.format]" do
+ result = SimplesIdeias::I18n.scoped_translations(["*.date.formats", "*.number.currency.format"])
+ result[:en].keys.collect(&:to_s).sort.should == %w[ date number ]
+ result[:fr].keys.collect(&:to_s).sort.should == %w[ date number ]
+ end
+
+ it "filters translations using multi-star scope" do
+ result = SimplesIdeias::I18n.scoped_translations("*.*.formats")
+
+ result[:en].keys.collect(&:to_s).sort.should == %w[ date time ]
+ result[:fr].keys.collect(&:to_s).sort.should == %w[ date time ]
+
+ result[:en][:date].keys.should == [:formats]
+ result[:en][:time].keys.should == [:formats]
+
+ result[:fr][:date].keys.should == [:formats]
+ result[:fr][:time].keys.should == [:formats]
+ end
+
+ it "filters translations using alternated stars" do
+ result = SimplesIdeias::I18n.scoped_translations("*.admin.*.title")
+
+ result[:en][:admin].keys.collect(&:to_s).sort.should == %w[ edit show ]
+ result[:fr][:admin].keys.collect(&:to_s).sort.should == %w[ edit show ]
+
+ result[:en][:admin][:show][:title].should == "Show"
+ result[:fr][:admin][:show][:title].should == "Visualiser"
+
+ result[:en][:admin][:edit][:title].should == "Edit"
+ result[:fr][:admin][:edit][:title].should == "Editer"
+ end
+
+ it "performs a deep merge" do
+ target = {:a => {:b => 1}}
+ result = SimplesIdeias::I18n.deep_merge(target, {:a => {:c => 2}})
+
+ result[:a].should == {:b => 1, :c => 2}
+ end
+
+ it "performs a banged deep merge" do
+ target = {:a => {:b => 1}}
+ SimplesIdeias::I18n.deep_merge!(target, {:a => {:c => 2}})
+
+ target[:a].should == {:b => 1, :c => 2}
+ end
+
+ it "updates the javascript library" do
+ FakeWeb.register_uri(:get, "http://github.com/fnando/i18n-js/raw/master/lib/i18n.js", :body => "UPDATED")
+
+ SimplesIdeias::I18n.setup!
+ SimplesIdeias::I18n.update!
+ File.read(SimplesIdeias::I18n.javascript_file).should == "UPDATED"
+ end
+
+ private
+ # Set the configuration as the current one
+ def set_config(path)
+ config = HashWithIndifferentAccess.new(YAML.load_file(File.dirname(__FILE__) + "/resources/#{path}"))
+ SimplesIdeias::I18n.should_receive(:config?).and_return(true)
+ SimplesIdeias::I18n.should_receive(:config).and_return(config)
+ end
+
+ # Shortcut to SimplesIdeias::I18n.translations
+ def translations
+ SimplesIdeias::I18n.translations
+ end
+end
View
0  test/resources/custom_path.yml → spec/resources/custom_path.yml
File renamed without changes
View
0  test/resources/default.yml → spec/resources/default.yml
File renamed without changes
View
0  test/resources/locales.yml → spec/resources/locales.yml
File renamed without changes
View
0  test/resources/multiple_files.yml → spec/resources/multiple_files.yml
File renamed without changes
View
0  test/resources/no_scope.yml → spec/resources/no_scope.yml
File renamed without changes
View
0  test/resources/simple_scope.yml → spec/resources/simple_scope.yml
File renamed without changes
View
19 test/test_helper.rb → spec/spec_helper.rb
@@ -1,14 +1,4 @@
-require "rubygems"
-gem "test-unit"
-require "test/unit"
-require "mocha"
-
-begin
- require "active_support/all"
-rescue LoadError
- require "active_support"
-end
-
+require "active_support/all"
require "active_support/version"
require "active_support/test_case"
require "ostruct"
@@ -21,6 +11,9 @@
# Stub Rails.root, so we don"t need to load the whole Rails environment.
# Be careful! The specified folder will be removed!
-Rails = OpenStruct.new(:root => Pathname.new(File.dirname(__FILE__) + "/tmp"), :version => "0")
+Rails = OpenStruct.new({
+ :root => Pathname.new(File.dirname(__FILE__) + "/tmp"),
+ :version => "0"
+})
-require File.dirname(__FILE__) + "/../lib/i18n-js"
+require "i18n-js"
View
160 test/i18n_js_test.rb
@@ -1,160 +0,0 @@
-require "test_helper"
-
-if File.basename(Rails.root) != "tmp"
- warn "Don't run i18n-js tests with `rake test:plugins`. That will remove your project!"
- warn "Please go to #{File.expand_path(File.dirname(__FILE__) + "/..")} and run `rake test`"
- exit 1
-end
-
-class I18nJSTest < ActiveSupport::TestCase
- setup do
- # Remove temporary directory if already present
- FileUtils.rm_r(Rails.root) if File.exist?(Rails.root)
-
- # Create temporary directory to test the files generation
- %w( config public/javascripts ).each do |path|
- FileUtils.mkdir_p Rails.root.join(path)
- end
-
- # Overwrite defaut locales path to use fixtures
- I18n.load_path = [File.dirname(__FILE__) + "/resources/locales.yml"]
- end
-
- teardown do
- # Remove temporary directory
- FileUtils.rm_r(Rails.root)
- end
-
- test "copy configuration file" do
- assert_equal false, File.file?(SimplesIdeias::I18n.config_file)
- SimplesIdeias::I18n.setup!
- assert File.file?(SimplesIdeias::I18n.config_file)
- end
-
- test "don't overwrite existing configuration file" do
- File.open(SimplesIdeias::I18n.config_file, "w+") {|f| f << "ORIGINAL"}
- SimplesIdeias::I18n.setup!
-
- assert_equal "ORIGINAL", File.read(SimplesIdeias::I18n.config_file)
- end
-
- test "copy JavaScript library" do
- path = Rails.root.join("public/javascripts/i18n.js")
-
- assert_equal false, File.file?(path)
- SimplesIdeias::I18n.setup!
- assert File.file?(path)
- end
-
- test "load configuration file" do
- SimplesIdeias::I18n.setup!
-
- assert SimplesIdeias::I18n.config?
- assert_kind_of HashWithIndifferentAccess, SimplesIdeias::I18n.config
- assert SimplesIdeias::I18n.config.any?
- end
-
- test "export messages to default path when configuration file doesn't exist" do
- SimplesIdeias::I18n.export!
- assert File.file?(Rails.root.join("public/javascripts/translations.js"))
- end
-
- test "export messages using the default configuration file" do
- set_config "default.yml"
- SimplesIdeias::I18n.expects(:save).with(translations, "public/javascripts/translations.js")
- SimplesIdeias::I18n.export!
- end
-
- test "export messages using custom output path" do
- set_config "custom_path.yml"
- SimplesIdeias::I18n.expects(:save).with(translations, "public/javascripts/translations/all.js")
- SimplesIdeias::I18n.export!
- end
-
- test "set default scope to * when not specified" do
- set_config "no_scope.yml"
- SimplesIdeias::I18n.expects(:save).with(translations, "public/javascripts/no_scope.js")
- SimplesIdeias::I18n.export!
- end
-
- test "export to multiple files" do
- set_config "multiple_files.yml"
- SimplesIdeias::I18n.export!
-
- assert File.file?(Rails.root.join("public/javascripts/all.js"))
- assert File.file?(Rails.root.join("public/javascripts/tudo.js"))
- end
-
- test "filtered translations using scope *.date.formats" do
- result = SimplesIdeias::I18n.filter(translations, "*.date.formats")
- assert_equal [:formats], result[:en][:date].keys
- assert_equal [:formats], result[:fr][:date].keys
- end
-
- test "filtered translations using scope [*.date.formats, *.number.currency.format]" do
- result = SimplesIdeias::I18n.scoped_translations(["*.date.formats", "*.number.currency.format"])
- assert_equal %w[ date number ], result[:en].keys.collect(&:to_s).sort
- assert_equal %w[ date number ], result[:fr].keys.collect(&:to_s).sort
- end
-
- test "filtered translations using multi-star scope" do
- result = SimplesIdeias::I18n.scoped_translations("*.*.formats")
-
- assert_equal %w[ date time ], result[:en].keys.collect(&:to_s).sort
- assert_equal %w[ date time ], result[:fr].keys.collect(&:to_s).sort
-
- assert_equal [:formats], result[:en][:date].keys
- assert_equal [:formats], result[:en][:time].keys
-
- assert_equal [:formats], result[:fr][:date].keys
- assert_equal [:formats], result[:fr][:time].keys
- end
-
- test "filtered translations using alternated stars" do
- result = SimplesIdeias::I18n.scoped_translations("*.admin.*.title")
-
- assert_equal %w[ edit show ], result[:en][:admin].keys.collect(&:to_s).sort
- assert_equal %w[ edit show ], result[:fr][:admin].keys.collect(&:to_s).sort
-
- assert_equal "Show", result[:en][:admin][:show][:title]
- assert_equal "Visualiser", result[:fr][:admin][:show][:title]
-
- assert_equal "Edit", result[:en][:admin][:edit][:title]
- assert_equal "Editer", result[:fr][:admin][:edit][:title]
- end
-
- test "deep merge" do
- target = {:a => {:b => 1}}
- result = SimplesIdeias::I18n.deep_merge(target, {:a => {:c => 2}})
-
- assert_equal result[:a], {:b => 1, :c => 2}
- end
-
- test "deep banged merge" do
- target = {:a => {:b => 1}}
- SimplesIdeias::I18n.deep_merge!(target, {:a => {:c => 2}})
-
- assert_equal target[:a], {:b => 1, :c => 2}
- end
-
- test "update javascript library" do
- FakeWeb.register_uri(:get, "http://github.com/fnando/i18n-js/raw/master/lib/i18n.js", :body => "UPDATED")
-
- SimplesIdeias::I18n.setup!
- SimplesIdeias::I18n.update!
- assert_equal "UPDATED", File.read(SimplesIdeias::I18n.javascript_file)
- end
-
- private
- # Set the configuration as the current one
- def set_config(path)
- config = HashWithIndifferentAccess.new(YAML.load_file(File.dirname(__FILE__) + "/resources/#{path}"))
- SimplesIdeias::I18n.expects(:config?).returns(true)
- SimplesIdeias::I18n.expects(:config).returns(config)
- end
-
- # Shortcut to SimplesIdeias::I18n.translations
- def translations
- SimplesIdeias::I18n.translations
- end
-end
Please sign in to comment.
Something went wrong with that request. Please try again.