Skip to content

Instantly share code, notes, and snippets.

@plagelao
plagelao / Banco.java
Created November 19, 2010 16:32
Intentando que el Token sea más explícito
public class Banco {
private final OperacionesBancarias operacionesBancarias;
private final InteresadoEnAccesoACuenta suscriptor;
public Banco(OperacionesBancarias operacionesBancarias,
InteresadoEnAccesoACuenta suscriptor) {
this.operacionesBancarias = operacionesBancarias;
this.suscriptor = suscriptor;
}
@plagelao
plagelao / Banco.java
Created November 23, 2010 20:12
Banco con credenciales
public class Banco {
private final OperacionesBancarias operacionesBancarias;
public Banco(OperacionesBancarias operacionesBancarias) {
this.operacionesBancarias = operacionesBancarias;
}
public Cuenta obtenerCuenta(Credenciales credenciales) {
Token token = operacionesBancarias.autenticar(credenciales);
@plagelao
plagelao / Banco.java
Created November 23, 2010 23:32
Banco que depende de Cajero
public class Banco {
private final OperacionesBancarias operacionesBancarias;
private final Cajero cajero;
public Banco(OperacionesBancarias operacionesBancarias,
Cajero cajero) {
this.operacionesBancarias = operacionesBancarias;
this.cajero = cajero;
}
@plagelao
plagelao / Cajero.java
Created November 23, 2010 23:38
Cajero que viola I
public class Cajero {
public void muestraLaPantallaPrincipal() {
Banco banco = new Banco(new OperacionesBancariasBancoManolito(),
this);
banco.obtenerCuenta(obtenCredenciales());
}
public void cuentaObtenida(Cuenta cuenta) {
muestraInformacionDeLacuenta(cuenta);
@plagelao
plagelao / locale.feature
Created December 13, 2010 19:38
¿Más expresivo?
#¿Posible escenario aún más expresivo?
Scenario: I visit the homepage with "es" set as preferred locale
Given I have selected "es" as preferred locale
When I request the home page
Then I should see the Spanish version of the site
@plagelao
plagelao / locale.feature
Created December 13, 2010 18:59
Some cucumber scenarios
#Mi escenario
Scenario: I visit the homepage with the spanish cookie
Given I have selected spanish as default language
When I request the home page
Then I should see "software que amarás"
#Escenario con Aimee
Scenario: I visit the homepage with the spanish cookie
Given I have selected "es" as default locale
When I request the home page
@plagelao
plagelao / middleware.rb
Created December 15, 2010 18:53
Menos legible y sin duplicación
def call(env)
set_variables(env)
call_haml_serve(env) do |response, preferred_locale|
set_preferred_locale_cookie(response, preferred_locale) if AVAILABLE_LOCALES.include?(preferred_locale)
end
end
def set_variables(env)
if has_language_cookie?(env)
@plagelao
plagelao / middleware.rb
Created December 15, 2010 18:54
Más legible pero con duplicación
def call(env)
set_user_language_variable(env)
set_include_language_banner_variable(env)
call_haml_serve(env) do |response, preferred_locale|
set_preferred_locale_cookie(response, preferred_locale) if AVAILABLE_LOCALES.include?(preferred_locale)
end
end
def set_user_language_variable(env)
if has_language_cookie?(env)
@plagelao
plagelao / StringCalculator.rb
Created January 6, 2011 01:05
StringCalculator recursivo
require 'rspec'
class StringCalculator
def add(string)
return add(string_without_last_summand(string)) + last_summand(string) if more_than_one_summand?(string)
string.to_i
end
def string_without_last_summand(string)
string[0...last_separator_index(string)]
end
def last_summand(string)
describe Order do
let(:product){stub(:product)}
let(:payment_gateway){stub(:payment_gateway)}
let(:order){Order.new(payment_gateway)}
it "confirm the order if the client has funds" do
product.stub(:price).and_return(50)
payment_gateway.stub(:user_has_funds).with(50).and_return(true)
order.buy(product).should be_true
end