Created
December 1, 2010 12:42
-
-
Save marcomoura/723424 to your computer and use it in GitHub Desktop.
Kata feito no CodingDojo na CN usando Ruby+BDD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# language: pt | |
# features/dicionario.feature | |
# @author Marco Moura <email at marcomoura.com> | |
# @author Luciana Mendes <super.luci at gmail.com> | |
# @author Rafael Salomao <rafaelgavazzi at gmail.com> | |
# @author Patricia Carvalho <patfcarv at gmail.com> | |
# @author Carlos Eduardo <kaddxxi at gmail.com> | |
Funcionalidade: Dicionary Replace | |
Kata para substituir string em um texto | |
Cenário: Entrada vazia | |
Dado que entrei "" | |
E entrei um dicionario "" | |
Então o software me retorna "" | |
Cenário: Texto 2 temporary | |
Dado que entrei "$temp$" | |
E entrei um dicionario ["temp", "temporary"] | |
Então o software me retorna "temporary" | |
Cenário: Com um parametro apenas diferente de temporario | |
Dado que entrei "$temp$" | |
E entrei um dicionario ["temp","hello world"] | |
Então o software me retorna "hello world" | |
Cenário: Texto 3.John Doe | |
Dado que entrei "$temp$ here comes the name $name$" | |
E entrei dois dicionario [["temp","temporary"],["name","John Doe"]] | |
Então o software me retorna "temporary here comes the name John Doe" | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# lib/dicionario.rb | |
# @author Marco Moura <email at marcomoura.com> | |
# @author Luciana Mendes <super.luci at gmail.com> | |
# @author Rafael Salomao <rafaelgavazzi at gmail.com> | |
# @author Patricia Carvalho <patfcarv at gmail.com> | |
# @author Carlos Eduardo <kaddxxi at gmail.com> | |
class Dicionario | |
@text | |
def set_text(t) | |
@text = t | |
end | |
@dict | |
def set_dict(dict) | |
@dict = dict | |
end | |
def replace() | |
if @dict == [""] | |
"" | |
else | |
@text.sub(/\$temp\$/, @dict.first['temp']) | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
# features/steps_definitions/dicionario_steps.rb | |
# @author Marco Moura <email at marcomoura.com> | |
# @author Luciana Mendes <super.luci at gmail.com> | |
# @author Rafael Salomao <rafaelgavazzi at gmail.com> | |
# @author Patricia Carvalho <patfcarv at gmail.com> | |
# @author Carlos Eduardo <kaddxxi at gmail.com> | |
Before do | |
@dic = Dicionario.new | |
end | |
Dado /^que entrei "([^"]*)"$/ do |text| | |
@dic.set_text(text) | |
end | |
Dado /^entrei um dicionario \["([^"]*)", "([^"]*)"\]$/ do |text, dict| | |
@dic.set_dict([text,dict]) | |
end | |
Dado /^entrei um dicionario "([^"]*)"$/ do |dict| | |
@dic.set_dict(dict) | |
end | |
Dado /^entrei dois dicionario \[\["([^"]*)","([^"]*)"\],\["([^"]*)","([^"]*)"\]\]$/ do |arg1, arg2, arg3, arg4| | |
temp = [arg1 = arg2, arg3 = arg4] | |
@dic.set_dict(temp) | |
end | |
Então /^o software me retorna "([^"]*)"$/ do |new_text| | |
replace = @dic.replace() | |
replace.should == new_text | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
# features/support/env.rb | |
begin require 'rspec/expectations'; rescue LoadError; require 'spec/expectations'; end | |
require 'cucumber/formatter/unicode' | |
$:.unshift(File.dirname(__FILE__) + '/../../lib') | |
require 'dicionario' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment