Index: lib/spec/story/runner/story_parser.rb =================================================================== --- lib/spec/story/runner/story_parser.rb (revision 7) +++ lib/spec/story/runner/story_parser.rb (working copy) @@ -26,13 +26,20 @@ def process_line(line) line.strip! case line - when /^Story: / then @state.story(line) - when /^Scenario: / then @state.scenario(line) - when /^Given:? / then @state.given(line) - when /^GivenScenario:? / then @state.given_scenario(line) - when /^When:? / then @state.event(line) - when /^Then:? / then @state.outcome(line) - when /^And:? / then @state.one_more_of_the_same(line) + when /^#{Spec::Runner.configuration.story_template_words[:story]}: /: + @state.story(line) + when /^#{Spec::Runner.configuration.story_template_words[:scenario]}: /: + @state.scenario(line) + when /^#{Spec::Runner.configuration.story_template_words[:given]}:? /: + @state.given(line) + when /^#{Spec::Runner.configuration.story_template_words[:given_scenario]}:? /: + @state.given_scenario(line) + when /^#{Spec::Runner.configuration.story_template_words[:when]}:? /: + @state.event(line) + when /^#{Spec::Runner.configuration.story_template_words[:then]}:? /: + @state.outcome(line) + when /^#{Spec::Runner.configuration.story_template_words[:and]}:? /: + @state.one_more_of_the_same(line) else @state.other(line) end end @@ -48,13 +55,17 @@ def create_story() unless @current_story_lines.empty? - @story_mediator.create_story(@current_story_lines[0].gsub("Story: ",""), @current_story_lines[1..-1].join("\n")) + @story_mediator.create_story( + @current_story_lines[0].gsub( + "#{Spec::Runner.configuration.story_template_words[:story]}: ",""), + @current_story_lines[1..-1].join("\n")) @current_story_lines.clear end end def create_scenario(title) - @story_mediator.create_scenario(title.gsub("Scenario: ","")) + @story_mediator.create_scenario(title.gsub( + "#{Spec::Runner.configuration.story_template_words[:scenario]}: ","")) end def create_given(name) @@ -126,8 +137,9 @@ def remove_tag_from(tag, line) tokens = line.split # validation of tag can go here - tokens[0].downcase.match(/#{tag.to_s}:?/) ? - (tokens[1..-1].join(' ')) : line + tokens[0].downcase.match( + /#{Spec::Runner.configuration.story_template_words[tag].downcase}:?/) ? + (tokens[1..-1].join(' ')) : line end def eof Index: lib/spec/example/configuration.rb =================================================================== --- lib/spec/example/configuration.rb (revision 7) +++ lib/spec/example/configuration.rb (working copy) @@ -124,7 +124,56 @@ ) example_group.append_after(scope, &proc) end + + # Let you write your stories in other languages. Example: + # + # Spec::Runner.configure do |config| + # config.with_story_template_words({ + # :story => "Relato", + # :scenario => 'Escenario', + # :given => 'Dado', + # :given_scenario => 'DadoElEscenario', + # :when => 'Cuando', + # :then => 'Entonces', + # :and => 'Y' + # }) + # end + # + # And then write your story in spanish, for example: + # + # Relato: La portada de Mi Sitio en La Red + # + # Como un usuario de La Red + # Quiero ver la portada de Mi Sitio + # Para ver que contenidos y servicios me ofrece + # + # Escenario: usuario sin sesión + # Dado un usuario sin sesión iniciada + # + # Cuando visita http://www.example.com/ + # + # Entonces puede ver el formulario para iniciar sesión + # Y el enlace para crear su cuenta + # + + STORY_TEMPLATE_WORDS = { + :story => 'Story', + :scenario => 'Scenario', + :given => 'Given', + :given_scenario => 'GivenScenario', + :when => 'When', + :then => 'Then', + :and => 'And' + } + def with_story_template_words(template_words) + @template_words = STORY_TEMPLATE_WORDS.merge(template_words) + end + + def story_template_words + @template_words ||= STORY_TEMPLATE_WORDS + end + private def scope_and_options(*args) Index: lib/spec/runner/formatter/story/plain_text_formatter.rb =================================================================== --- lib/spec/runner/formatter/story/plain_text_formatter.rb (revision 7) +++ lib/spec/runner/formatter/story/plain_text_formatter.rb (working copy) @@ -21,7 +21,7 @@ def story_started(title, narrative) @current_story_title = title - @output.puts "Story: #{title}\n\n" + @output.puts "#{Spec::Runner.configuration.story_template_words[:story]}: #{title}\n\n" narrative.each_line do |line| @output.print " " @output.print line @@ -36,7 +36,7 @@ def scenario_started(story_title, scenario_name) @current_scenario_name = scenario_name @scenario_already_failed = false - @output.print "\n\n Scenario: #{scenario_name}" + @output.print "\n\n #{Spec::Runner.configuration.story_template_words[:scenario]}: #{scenario_name}" @scenario_ok = true end @@ -110,9 +110,9 @@ desc_string = description.step_name arg_regexp = description.arg_regexp text = if(type == @previous_type) - "\n And " + "\n #{Spec::Runner.configuration.story_template_words[:and]} " else - "\n\n #{type.to_s.capitalize} " + "\n\n #{Spec::Runner.configuration.story_template_words[type]} " end i = -1 text << desc_string.gsub(arg_regexp) { |param| args[i+=1] }