Skip to content

Commit

Permalink
Better support for 1.9 encoding, and a little formatter flushing
Browse files Browse the repository at this point in the history
  • Loading branch information
aslakhellesoy committed Jan 24, 2009
1 parent 5e2cf45 commit 7c7cdc3
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 19 deletions.
2 changes: 1 addition & 1 deletion examples/i18n/Rakefile
Expand Up @@ -28,5 +28,5 @@ def supported?(lang)
end

def rake(args)
ruby(File.join(Gem.bindir, 'rake'), args)
ruby($0, args) rescue nil
end
@@ -1,8 +1,7 @@
# encoding: utf-8
# encoding: Shift_JIS
require 'spec/expectations'
$:.unshift(File.dirname(__FILE__) + '/../../lib') # This line is not needed in your own project
require 'cucumber/formatters/unicode'
$KCODE = 'e'
require 'calculator'

Before do
Expand Down
8 changes: 7 additions & 1 deletion lib/cucumber/cli.rb
Expand Up @@ -29,8 +29,14 @@ def parse(args)
FORMATS = %w{pretty profile progress html autotest}
DEFAULT_FORMAT = 'pretty'

def initialize(out_stream = STDOUT, error_stream = STDERR)
def initialize(out_stream = Kernel, error_stream = STDERR)
@out_stream = out_stream
if out_stream == Kernel
def Kernel.flush
STDOUT.flush
end
end

@error_stream = error_stream
@paths = []
@options = {
Expand Down
6 changes: 5 additions & 1 deletion lib/cucumber/formatter/console.rb
Expand Up @@ -43,6 +43,7 @@ def print_elements(io, elements, status, kind)
if elements.any?
io.puts(format_string("(::) #{status} #{kind} (::)", status))
io.puts
io.flush
end

elements.each_with_index do |element, i|
Expand All @@ -52,6 +53,7 @@ def print_elements(io, elements, status, kind)
io.puts(format_string(element.backtrace_line, status))
end
io.puts
io.flush
end
end

Expand All @@ -62,6 +64,7 @@ def print_counts(io, features)
if features.steps[status].any?
count_string = dump_count(features.steps[status].length, "step", status.to_s)
io.puts format_string(count_string, status)
io.flush
end
end
end
Expand All @@ -83,7 +86,8 @@ def print_snippets(io, features, options)

text = "\nYou can implement step definitions for missing steps with these snippets:\n\n"
text += snippets.join("\n\n")
@io.puts format_string(text, :undefined)
io.puts format_string(text, :undefined)
io.flush
end

private
Expand Down
26 changes: 20 additions & 6 deletions lib/cucumber/formatter/pretty.rb
Expand Up @@ -13,7 +13,7 @@ class Pretty < Ast::Visitor

def initialize(step_mother, io, options, delim='|')
super(step_mother)
@io = (io == STDOUT) ? Kernel : io
@io = io
@options = options
@delim = delim
end
Expand All @@ -33,38 +33,48 @@ def visit_comment(comment)
end

def visit_comment_line(comment_line)
@io.puts(comment_line.indent(@indent)) unless comment_line.blank?
unless comment_line.blank?
@io.puts(comment_line.indent(@indent))
@io.flush
end
end

def visit_tags(tags)
tags.accept(self)
@io.puts if @indent == 1
if @indent == 1
@io.puts
@io.flush
end
end

def visit_tag_name(tag_name)
tag = format_string("@#{tag_name}", :tag).indent(@indent)
@io.print(tag)
@io.flush
@indent = 1
end

def visit_feature_name(name)
@io.puts(name)
@io.puts
@io.flush
end

def visit_feature_element(feature_element)
@indent = 2
@last_undefined = feature_element.undefined?
feature_element.accept(self)
@io.puts
@io.flush
end

def visit_examples(examples)
examples.accept(self)
end

def visit_examples_name(keyword, name)
@io.print("\n #{keyword} #{name}\n")
@io.puts("\n #{keyword} #{name}")
@io.flush
@indent = 4
end

Expand All @@ -77,6 +87,7 @@ def visit_scenario_name(keyword, name, file_line, source_indent)
@io.print(format_string(line_comment, :comment))
end
@io.puts
@io.flush
end

def visit_step(step)
Expand All @@ -88,7 +99,8 @@ def visit_step(step)
def visit_step_name(keyword, step_name, status, step_definition, source_indent)
source_indent = nil unless @options[:source]
formatted_step_name = format_step(keyword, step_name, status, step_definition, source_indent)
@io.print(" " + formatted_step_name + "\n")
@io.puts(" " + formatted_step_name)
@io.flush
end

def visit_multiline_arg(multiline_arg, status)
Expand All @@ -104,7 +116,8 @@ def visit_table_row(table_row, status)

def visit_py_string(string, status)
s = "\"\"\"\n#{string}\n\"\"\"".indent(@indent)
@io.print(format_string(s, status) + "\n")
@io.puts(format_string(s, status))
@io.flush
end

def visit_table_cell(table_cell, status)
Expand All @@ -113,6 +126,7 @@ def visit_table_cell(table_cell, status)

def visit_table_cell_value(value, width, status)
@io.print(' ' + format_string((value || '').ljust(width), status) + " #{@delim}")
@io.flush
end

private
Expand Down
5 changes: 2 additions & 3 deletions lib/cucumber/formatter/progress.rb
Expand Up @@ -7,8 +7,7 @@ class Progress < Ast::Visitor

def initialize(step_mother, io, options)
super(step_mother)
@io = (io == STDOUT) ? Kernel : io
@flushable = @io.respond_to?(:flush) ? @io : STDOUT
@io = io
@options = options
end

Expand Down Expand Up @@ -59,7 +58,7 @@ def print_summary(io, features)
def progress(status)
char = CHARS[status]
@io.print(format_string(char, status))
@flushable.flush
@io.flush
end

end
Expand Down
26 changes: 26 additions & 0 deletions lib/cucumber/languages.yml
@@ -1,9 +1,11 @@
# encoding: UTF-8
# We use the codes here (prefer 2 letters when possible)
# http://en.wikipedia.org/wiki/List_of_ISO_639-2_codes
#
"en":
name: English
native: English
encoding: UTF-8
feature: Feature
background: Background
scenario: Scenario
Expand All @@ -23,6 +25,7 @@
"ar":
name: Arabic
native: العربية
encoding: UTF-8
feature: خاصية
scenario: سيناريو
given: بفرض
Expand All @@ -33,6 +36,7 @@
"cy":
name: Welsh
native: Cymraeg
encoding: UTF-8
feature: Arwedd
scenario: Scenario
examples: Enghreifftiau
Expand All @@ -44,6 +48,7 @@
"da":
name: Danish
native: dansk
encoding: UTF-8
feature: Egenskab
background: Baggrund
scenario: Scenarie
Expand All @@ -56,6 +61,7 @@
"de":
name: German
native: Deutsch
encoding: UTF-8
feature: Funktionalität
scenario: Szenario
scenario_outline: Szenariogrundriss
Expand All @@ -68,6 +74,7 @@
"en-lol":
name: LOLCAT
native: LOLCAT
encoding: UTF-8
feature: OH HAI
background: B4
scenario: MISHUN
Expand All @@ -81,6 +88,7 @@
"en-tx":
name: Texan
native: Texan
encoding: UTF-8
feature: Feature
scenario: Scenario
scenario_outline: Scenario Outline
Expand All @@ -93,6 +101,7 @@
"es":
name: Spanish
native: español
encoding: UTF-8
feature: Característica
scenario: Escenario
given: Dado
Expand All @@ -103,6 +112,7 @@
"et":
name: Estonian
native: eesti keel
encoding: UTF-8
feature: Omadus
scenario: Stsenaarium
scenario_outline: Scenario Outline
Expand All @@ -115,6 +125,7 @@
"fi":
name: Finnish
native: suomi
encoding: UTF-8
feature: Ominaisuus
scenario: Tapaus
scenario_outline: Tapausaihio
Expand All @@ -127,6 +138,7 @@
"fr":
name: French
native: français
encoding: UTF-8
feature: Fonctionnalité
scenario: Scénario
scenario_outline: Scénario esquisse
Expand All @@ -139,6 +151,7 @@
"id":
name: Indonesian
native: Bahasa Indonesia
encoding: UTF-8
feature: Fitur
scenario: Skenario
scenario_outline: Skenario konsep
Expand All @@ -151,6 +164,7 @@
"it":
name: Italian
native: italiano
encoding: UTF-8
feature: Funzionalità
scenario: Scenario
more_examples: Più esempi
Expand All @@ -162,6 +176,7 @@
"ja":
name: Japanese
native: 日本語
encoding: Shift_JIS
feature: フィーチャ
scenario: シナリオ
more_examples: 他のサンプル
Expand All @@ -173,6 +188,7 @@
"lt":
name: Lithuanian
native: lietuvių kalba
encoding: UTF-8
feature: Sąvybė
scenario: Scenarijus
examples: Pavyzdžių
Expand All @@ -184,6 +200,7 @@
"nl":
name: Dutch
native: Nederlands
encoding: UTF-8
feature: Functionaliteit
scenario: Scenario
given: Gegeven
Expand All @@ -194,6 +211,7 @@
"no":
name: Norwegian
native: norsk
encoding: UTF-8
feature: Egenskap
background: Bakgrunn
scenario: Scenario
Expand All @@ -207,6 +225,7 @@
"pl":
name: Polish
native: polski
encoding: UTF-8
feature: Właściwość
scenario: Scenariusz
given: Dane
Expand All @@ -217,6 +236,7 @@
"pt":
name: Portuguese
native: português
encoding: UTF-8
feature: Característica
scenario: Cenário
given: Dado
Expand All @@ -227,6 +247,7 @@
"ro":
name: Romanian
native: română
encoding: UTF-8
feature: Functionalitate
scenario: Scenariu
given: Daca
Expand All @@ -237,6 +258,7 @@
"ro2":
name: Romanian (diacritical)
native: română (diacritical)
encoding: UTF-8
feature: Funcționalitate
scenario: Scenariu
given: Dacă
Expand All @@ -247,6 +269,7 @@
"ru":
name: Russian
native: русский язык
encoding: UTF-8
feature: Функционал
scenario: Сценарий
given: Сначала
Expand All @@ -257,6 +280,7 @@
"se":
name: Swedish
native: Svenska
encoding: UTF-8
feature: Egenskap
background: Bakgrund
scenario: Scenario
Expand All @@ -268,6 +292,7 @@
"zh-CN":
name: Chinese simplified
native: 中文
encoding: UTF-8
feature: 功能
scenario: 场景
given: 假如
Expand All @@ -278,6 +303,7 @@
"ko":
name: Korean
native: 한국어
encoding: UTF-8
feature: 기능
scenario:
given: 조건
Expand Down

0 comments on commit 7c7cdc3

Please sign in to comment.