Skip to content

Commit

Permalink
Merge pull request #3 from ninoseki/v0.2.1
Browse files Browse the repository at this point in the history
v0.2.1
  • Loading branch information
ninoseki committed Mar 21, 2019
2 parents 397b1d8 + a376d9d commit af5ab30
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 11 deletions.
12 changes: 2 additions & 10 deletions exe/kokki
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@
require "bundler/setup"
require "kokki"

input = ARGV.first
input = ARGV.first || gets

if input
begin
puts Kokki.flagize(input)
rescue Kokki::InvalidInputError => e
puts e.message
end
else
puts "Input not found: plase give a word to convert."
end
Kokki::CLI.start input
2 changes: 2 additions & 0 deletions lib/kokki.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
require "kokki/ip_address"
require "kokki/converter"

require "kokki/cli"

module Kokki
def self.flagize(input)
Converter.convert input
Expand Down
17 changes: 17 additions & 0 deletions lib/kokki/cli.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

module Kokki
class CLI
def self.start(input)
if input
begin
puts Kokki.flagize(input.chomp)
rescue Kokki::InvalidInputError => e
puts e.message
end
else
puts "Input not found: plase give a word to convert."
end
end
end
end
2 changes: 1 addition & 1 deletion lib/kokki/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Kokki
VERSION = "0.2.0"
VERSION = "0.2.1"
end
21 changes: 21 additions & 0 deletions spec/cli_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

RSpec.describe Kokki::CLI, :vcr do
subject { Kokki::CLI }

describe ".start" do
context "when given a valid input" do
it "should return a country flag of a given country" do
output = capture(:stdout) { subject.start "JP" }.chomp
expect(output).to eq("🇯🇵")
end
end

context "when given an invalid input" do
it "should return a country flag of a given country" do
output = capture(:stdout) { subject.start "hoge" }.chomp
expect(output).to eq("invalid input: hoge")
end
end
end
end
4 changes: 4 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

require "vcr"

require_relative "./support/helpers/helpers"

RSpec.configure do |config|
# Enable flags like --only-failures and --next-failure
config.example_status_persistence_file_path = ".rspec_status"
Expand All @@ -24,6 +26,8 @@
config.expect_with :rspec do |c|
c.syntax = :expect
end

config.include Spec::Support::Helpers
end

VCR.configure do |config|
Expand Down
19 changes: 19 additions & 0 deletions spec/support/helpers/helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

module Spec
module Support
module Helpers
def capture(stream)
begin
stream = stream.to_s
eval "$#{stream} = StringIO.new"
yield
result = eval("$#{stream}").string
ensure
eval("$#{stream} = #{stream.upcase}")
end
result
end
end
end
end

0 comments on commit af5ab30

Please sign in to comment.