Permalink
Browse files

Add a test suite and an .each iterator on Language class.

  • Loading branch information...
Matt Colyer
Matt Colyer committed Nov 5, 2010
1 parent 1764870 commit f80deb195f9e1e304e4c30099619ff2c2ab85b7d
Showing with 45 additions and 0 deletions.
  1. +10 −0 lib/speakeasy/language.rb
  2. +32 −0 spec/language_spec.rb
  3. +3 −0 spec/spec_helper.rb
View
@@ -14,6 +14,16 @@ def self.supported_language_ids
end
end
+ # Public: Iterates over all supported languages
+ #
+ # Returns an enumator over the list of supported languages
+ def self.each(&block)
+ languages = Dir.glob("#{DATA_DIR}/*").map do |file|
+ Language.new(File.basename(file))
+ end
+ languages.each(&block)
+ end
+
def initialize(language)
filename = File.join(DATA_DIR, language)
View
@@ -0,0 +1,32 @@
+require File.dirname(__FILE__) + "/spec_helper"
+
+describe "A Language" do
+ SupportedLanguages = 15
+
+ it "can list the supported language ids" do
+ Speakeasy::Language.supported_language_ids.size.should == SupportedLanguages
+ end
+
+ it "can iterate over all supported languages" do
+ Speakeasy::Language.each.to_a.size.should == SupportedLanguages
+ end
+
+ context "(German)"
+ subject do
+ Speakeasy::Language.new("de")
+ end
+ it "has codepoints" do
+ subject.respond_to? :codepoints
+ subject.codepoints.is_a? Array
+ end
+
+ it "has a native name" do
+ subject.respond_to? :native_name
+ subject.native_name.should == "Deutsch"
+ end
+
+ it "has a anglicized name" do
+ subject.respond_to? :anglicized_name
+ subject.anglicized_name.should == "German"
+ end
+end
View
@@ -0,0 +1,3 @@
+require 'rubygems'
+require File.dirname(__FILE__)+'/../lib/speakeasy'
+require 'rspec'

0 comments on commit f80deb1

Please sign in to comment.