Skip to content

Commit

Permalink
Gem Refactor.
Browse files Browse the repository at this point in the history
Test not working :(.
  • Loading branch information
albertogg committed Apr 20, 2013
1 parent 43c1dde commit 3bc2fa6
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 61 deletions.
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ require 'rake/testtask'

Rake::TestTask.new do |t|
t.libs << 'test'
t.verbose = true
end

desc "Run tests"
Expand Down
23 changes: 22 additions & 1 deletion bin/hola_albertogg
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
#!/usr/bin/env ruby

require 'optparse'
require 'hola_albertogg'

puts Hola::Say.hi
options = {
:Translation => 'english'
}

option_parser = OptionParser.new("", 24, ' ') do |opts|
opts.on('-t', '--translate [TRANSLATION]', 'Write down the language') do |translations|
options[:Translation] = translations
end
opts.on('-v', '--version', 'show version') do
puts "hola_albertogg version #{Hola::VERSION}"
exit
end
opts.on('-h', '--help', 'display help') do
puts opts
exit
end

opts.parse! ARGV
end

Hola::Translator.new("#{options[:Translation]}").hi
4 changes: 3 additions & 1 deletion hola_albertogg.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ Gem::Specification.new do |s|
bin/hola_albertogg
lib/hola_albertogg.rb
lib/hola_albertogg/translator.rb
lib/hola_albertogg/command_line.rb
lib/hola_albertogg/const.rb
hola_albertogg.gemspec
]
s.homepage = 'https://github.com/albertogg/albertogggem'
s.require_paths = %w[lib]
end
13 changes: 3 additions & 10 deletions lib/hola_albertogg.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
require 'hola_albertogg/translator'
require 'hola_albertogg/command_line'

module Hola

VERSION = "0.1.0" # keep it in sync with gemspec.

class Say
def self.hi
cli = CommandLine.new
cli.parse_options
end
end
end

require 'hola_albertogg/translator'
require 'hola_albertogg/const'
42 changes: 0 additions & 42 deletions lib/hola_albertogg/command_line.rb

This file was deleted.

5 changes: 5 additions & 0 deletions lib/hola_albertogg/const.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Hola

VERSION = "0.1.0" unless defined?(Hola::VERSION)# keep it in sync with gemspec.

end
8 changes: 4 additions & 4 deletions lib/hola_albertogg/translator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ def initialize(language)
def hi
case @language
when "spanish"
"hola mundo"
puts "hola mundo"
when "italian"
"ciao mondo"
puts "ciao mondo"
when "french"
"bonjour tout le monde"
puts "bonjour tout le monde"
else
"hello world"
puts "hello world"
end
end
end
Expand Down
12 changes: 12 additions & 0 deletions test/test_command_line.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require 'minitest/autorun'
require 'hola_albertogg'

class CommandLineTest < MiniTest::Unit::TestCase
def test_help_menu
assert system('bin/hola_albertogg -h')
end

def test_version
assert system('bin/hola_albertogg --version')
end
end
6 changes: 3 additions & 3 deletions test/test_hola_albertogg.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
require 'minitest/autorun'
require 'hola_albertogg'

class SayTest < MiniTest::Unit::TestCase
class HelloTest < MiniTest::Unit::TestCase
def test_english_hi
assert_equal "hello world", Hola::Say.hi
assert_equal "hello world", Hola::Translator.new("english").hi
end

def test_spanish_hi
assert_equal "hola mundo", Hola::Say.hi("spanish")
assert_equal "hola mundo", Hola::Translator.new("spanish").hi
end

def test_not_equal
Expand Down

0 comments on commit 3bc2fa6

Please sign in to comment.