mundo-pepino 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +7 -0
- data/README_es.markdown +20 -21
- data/lib/mundo_pepino.rb +13 -1
- data/lib/mundo_pepino/base.rb +56 -0
- data/lib/mundo_pepino/en_US/definitions.rb +7 -5
- data/lib/mundo_pepino/en_US/mappings.rb +9 -11
- data/lib/mundo_pepino/es_ES/definitions.rb +47 -44
- data/lib/mundo_pepino/es_ES/mappings.rb +13 -12
- data/lib/mundo_pepino/implementations.rb +106 -48
- data/lib/mundo_pepino/implementations_api.rb +8 -2
- data/lib/mundo_pepino/resources_history.rb +17 -52
- data/lib/mundo_pepino/version.rb +1 -1
- metadata +2 -2
data/History.txt
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
== 0.1.9 2009-12-7
|
2
|
+
* Support for assignments in "has_one" child (of an explicit or refered
|
3
|
+
resource).
|
4
|
+
* Revisited exceptions: tests & fixes
|
5
|
+
* "Veo el _campo_ con _valor_" expanded (no need to use "el valor" or "el
|
6
|
+
texto" between de field and the value.
|
7
|
+
|
1
8
|
== 0.1.8 2009-11-24
|
2
9
|
* New page interpretation (es_ES):
|
3
10
|
* Page of a mentioned resource of a given model. Examples:
|
data/README_es.markdown
CHANGED
@@ -186,7 +186,7 @@ Convenciones generales:
|
|
186
186
|
* asignación de valores con el verbo **tener** en tercera persona (p.e. "Dado que dichas Acelgas **tienen** como variedad Amarilla de Lyon")
|
187
187
|
* todas las definiciones para "Cuando algo ocurre" (o *Then's*, ver más abajo) son válidas también como "Dado el contexto" incorporándoles el prefijo "que" (p.e. "Dado que visito la portada").
|
188
188
|
|
189
|
-
#### Estoy en una página (alias de *Solicitud de una página*)
|
189
|
+
#### Estoy en una página (alias de *Solicitud de una página*)
|
190
190
|
[ejemplos](/nando/mundo-pepino/tree/master/features/es_ES/cuando-visito-una-pagina.feature)
|
191
191
|
##### Página específica opcionalmente indicada con un nombre coloquial
|
192
192
|
Dado que estoy en la portada
|
@@ -263,6 +263,7 @@ Convenciones generales:
|
|
263
263
|
|
264
264
|
* frases escritas en tiempo presente en primera persona del singular
|
265
265
|
* todas las definiciones son válidas también para definir contexto (en "Dados" o "Givens") incorporándoles el prefijo "que" (p.e. "Dado que visito la portada").
|
266
|
+
|
266
267
|
#### Solicitud de página
|
267
268
|
[ejemplos](/nando/mundo-pepino/tree/master/features/es_ES/cuando-visito-una-pagina.feature)
|
268
269
|
##### Página específica opcionalmente indicada con un nombre coloquial
|
@@ -303,7 +304,7 @@ Convenciones generales:
|
|
303
304
|
##### Página relativa a una visitada con anterioridad
|
304
305
|
Cuando pulso el enlace a la siguiente página
|
305
306
|
|
306
|
-
#### Pincho/pulso un bóton (*submit*)
|
307
|
+
#### Pincho/pulso un bóton (*submit*)
|
307
308
|
Cuando pulso en el botón Enviar
|
308
309
|
[más ejemplos](/nando/mundo-pepino/tree/master/features/es_ES/cuando-pulso-el-boton.feature)
|
309
310
|
#### Pincho/pulso una serie de bótones y/o enlaces
|
@@ -312,16 +313,16 @@ Convenciones generales:
|
|
312
313
|
| galería de huertos |
|
313
314
|
| cultivos de regadío |
|
314
315
|
[más ejemplos](/nando/mundo-pepino/tree/master/features/es_ES/cuando-pulso-los-siguientes-enlaces-y-botones.feature)
|
315
|
-
#### Adjunto un fichero (*file*)
|
316
|
+
#### Adjunto un fichero (*file*)
|
316
317
|
Cuando adjunto el fichero "images/cucumber.jpg" en Fotografía actual
|
317
318
|
[más ejemplos](/nando/mundo-pepino/tree/master/features/es_ES/cuando-adjunto-el-fichero.feature)
|
318
|
-
#### Elijo una opción (*radiobutton*)
|
319
|
+
#### Elijo una opción (*radiobutton*)
|
319
320
|
Cuando elijo el color "VERDE"
|
320
321
|
[más ejemplos](/nando/mundo-pepino/tree/master/features/es_ES/cuando-elijo-de-radiobutton.feature)
|
321
|
-
#### Marco (o desmarco) una casilla (*checkbox*)
|
322
|
+
#### Marco (o desmarco) una casilla (*checkbox*)
|
322
323
|
Cuando marco "color verde"
|
323
324
|
[más ejemplos](/nando/mundo-pepino/tree/master/features/es_ES/cuando-marco-el-checkbox.feature)
|
324
|
-
#### Relleno/completo un campo con un texto (*text* o *textarea*)
|
325
|
+
#### Relleno/completo un campo con un texto (*text* o *textarea*)
|
325
326
|
Cuando completo 'nombre' con 'Wadus'
|
326
327
|
[más ejemplos](/nando/mundo-pepino/tree/master/features/es_ES/cuando-relleno-el-campo.feature)
|
327
328
|
#### Relleno/completo un campo (*text* o *textarea*) de un atributo anidado
|
@@ -334,23 +335,23 @@ Convenciones generales:
|
|
334
335
|
| Color | Verde |
|
335
336
|
[más ejemplos](/nando/mundo-pepino/tree/master/features/es_ES/cuando-relleno-los-campos.feature)
|
336
337
|
#### Selecciono opción/opciones
|
337
|
-
##### Selecciono una opción de una lista (*select*)
|
338
|
+
##### Selecciono una opción de una lista (*select*)
|
338
339
|
Cuando selecciono "Hortalizas" en el listado de "Tipos de cultivo"
|
339
|
-
##### Selecciono fecha y hora sin especificar en que campo
|
340
|
+
##### Selecciono fecha y hora sin especificar en que campo
|
340
341
|
Cuando selecciono 1 de septiembre de 1998, 12:46 como fecha y hora
|
341
|
-
##### Selecciono fecha y hora para un campo concreto
|
342
|
+
##### Selecciono fecha y hora para un campo concreto
|
342
343
|
Cuando selecciono 2 de mayo de 1998, 12:46 como fecha y hora de "Cosechado"
|
343
|
-
##### Selecciono una hora sin especificar en que campo
|
344
|
+
##### Selecciono una hora sin especificar en que campo
|
344
345
|
Cuando selecciono 6:45PM como hora
|
345
|
-
##### Selecciono una hora para un campo concreto
|
346
|
+
##### Selecciono una hora para un campo concreto
|
346
347
|
Cuando selecciono 2:45PM como hora del "café"
|
347
|
-
##### Selecciono fecha sin especificar en que campo
|
348
|
+
##### Selecciono fecha sin especificar en que campo
|
348
349
|
Cuando selecciono 1 de septiembre de 1998 como fecha
|
349
|
-
##### Selecciono fecha para un campo concreto
|
350
|
+
##### Selecciono fecha para un campo concreto
|
350
351
|
Cuando selecciono 2 de marzo de 2009 como fecha para el comienzo de la poda
|
351
352
|
[más ejemplos](/nando/mundo-pepino/tree/master/features/es_ES/cuando-selecciono-en-listado.feature)
|
352
353
|
|
353
|
-
#### Borro el enésimo recurso desde la página de su índice (index)
|
354
|
+
#### Borro el enésimo recurso desde la página de su índice (index)
|
354
355
|
Cuando borro el Bancal en 6ª posición
|
355
356
|
[más ejemplos](/nando/mundo-pepino/tree/master/features/es_ES/cuando-borro-el-enesimo-recurso.feature)
|
356
357
|
|
@@ -379,7 +380,7 @@ Distinguimos entre los seis tipos de página que tienen sentido aquí (todos exc
|
|
379
380
|
##### Página de edición de un recurso
|
380
381
|
Entonces debo estar en la página de edición del huerto "H-01"
|
381
382
|
|
382
|
-
#### Veo (o no) un texto opcionalmente dentro de un selector concreto
|
383
|
+
#### Veo (o no) un texto opcionalmente dentro de un selector concreto
|
383
384
|
Entonces debo ver el texto "IVA incluido"
|
384
385
|
[más ejemplos](/nando/mundo-pepino/tree/master/features/es_ES/veo-el-texto.feature)
|
385
386
|
#### Veo (o no) una serie de textos expresados en una step-table (sin cabeceras)
|
@@ -398,7 +399,7 @@ Distinguimos entre los seis tipos de página que tienen sentido aquí (todos exc
|
|
398
399
|
| h1 | Mundo Pepino |
|
399
400
|
[más ejemplos]/mundo-pepino/tree/master/features/es_ES/veo-etiquetas-con-valores.feature
|
400
401
|
|
401
|
-
#### Veo (o no) un campo con un contenido concreto
|
402
|
+
#### Veo (o no) un campo con un contenido concreto
|
402
403
|
Entonces debería ver el campo "nombre" con "Wadus"
|
403
404
|
[más ejemplos]/mundo-pepino/tree/master/features/es_ES/veo-campo-con-valor.feature
|
404
405
|
|
@@ -430,18 +431,18 @@ Distinguimos entre los seis tipos de página que tienen sentido aquí (todos exc
|
|
430
431
|
##### Página relativa a una visitada con anterioridad
|
431
432
|
Entonces debo ver un enlace a la siguiente página
|
432
433
|
|
433
|
-
#### Veo marcada (o desmarcada) una casilla (*checkbox*)
|
434
|
+
#### Veo marcada (o desmarcada) una casilla (*checkbox*)
|
434
435
|
Entonces veo marcado "Acepto las condiciones del servicio"
|
435
436
|
[más ejemplos](/nando/mundo-pepino/tree/master/features/es_ES/veo-el-checkbox.feature)
|
436
437
|
|
437
|
-
#### Veo una tabla con determinados valores en sus celdas
|
438
|
+
#### Veo una tabla con determinados valores en sus celdas
|
438
439
|
Entonces veo la tabla "bancales" con el siguiente contenido:
|
439
440
|
| nombre | longitud | cultivo | matas |
|
440
441
|
| A-01 | 12 | Patatas | 16 |
|
441
442
|
| A-02 | 12 | Tomates | 18 |
|
442
443
|
[más ejemplos](/nando/mundo-pepino/tree/master/features/es_ES/veo-una-tabla-con-determinado-contenido.feature)
|
443
444
|
|
444
|
-
#### Veo un formulario con determinados campos convenientemente etiquetados
|
445
|
+
#### Veo un formulario con determinados campos convenientemente etiquetados
|
445
446
|
Entonces veo un formulario con los siguientes campos:
|
446
447
|
| Etiqueta | Tipo |
|
447
448
|
| Login | textfield |
|
@@ -478,8 +479,6 @@ Distinguimos entre los seis tipos de página que tienen sentido aquí (todos exc
|
|
478
479
|
Entonces tiene en base de datos siete Bancales
|
479
480
|
[más ejemplos](/nando/mundo-pepino/tree/master/features/es_ES/mundo-pepino.feature)
|
480
481
|
|
481
|
-
(\*) Los **asteriscos** al final de la definición hacen referencia a las **definiciones oficialmente comunes** generadas en inglés por `script/generate cucumber`. Dos asteríscos (\*\*) hacen referencia a una definición presente en la feature autogenerada por `script/generate feature`.
|
482
|
-
|
483
482
|
## Instalación
|
484
483
|
|
485
484
|
Como gema:
|
data/lib/mundo_pepino.rb
CHANGED
@@ -30,7 +30,17 @@ module MundoPepino
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def common_mappings
|
33
|
-
String.add_mapper
|
33
|
+
String.add_mapper(:number) {|str| str.to_i}
|
34
|
+
String.add_mapper(:model) {|str|
|
35
|
+
begin
|
36
|
+
c = str.singularize.capitalize.constantize
|
37
|
+
c.superclass == ActiveRecord::Base ? c : nil
|
38
|
+
rescue
|
39
|
+
nil
|
40
|
+
end
|
41
|
+
}
|
42
|
+
String.add_mapper :field
|
43
|
+
String.add_mapper :crud_action
|
34
44
|
String.add_mapper :relation_model
|
35
45
|
String.add_mapper(:content_type,
|
36
46
|
/\.png$/ => 'image/png',
|
@@ -48,7 +58,9 @@ module MundoPepino
|
|
48
58
|
str
|
49
59
|
end
|
50
60
|
end
|
61
|
+
String.add_mapper(:month) {|month| month.capitalize}
|
51
62
|
String.add_mapper(:url) {|str| str if str =~ /^\/.*$|^https?:\/\//i}
|
63
|
+
String.add_mapper(:real_value) {|value| value} # true, false...
|
52
64
|
end
|
53
65
|
|
54
66
|
def config
|
data/lib/mundo_pepino/base.rb
CHANGED
@@ -1,4 +1,59 @@
|
|
1
1
|
module MundoPepino
|
2
|
+
# Exceptions
|
3
|
+
class ResourceNotFound < RuntimeError
|
4
|
+
def initialize(resource_info=nil)
|
5
|
+
@resource_info = resource_info && " (#{resource_info})"
|
6
|
+
end
|
7
|
+
def message
|
8
|
+
"Resource not found#{@resource_info}"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class WithoutResources < ResourceNotFound
|
13
|
+
def initialize
|
14
|
+
super 'there is no resources'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class NotFoundInDatabase < ResourceNotFound
|
19
|
+
def initialize(model, value='')
|
20
|
+
super "#{model} called #{value||'nil'} not found in database"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class NotFoundInHistoryNorDatabase < ResourceNotFound
|
25
|
+
def initialize(model, value='')
|
26
|
+
super "#{model} called #{value||'nil'} not found in history nor database"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class NotMapped < RuntimeError
|
31
|
+
def initialize(type, string)
|
32
|
+
@type = type
|
33
|
+
@string = string
|
34
|
+
end
|
35
|
+
def message
|
36
|
+
"#{@type} not mapped '#{@string}'"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class ModelNotMapped < NotMapped
|
41
|
+
def initialize(string)
|
42
|
+
super('Model', string)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class FieldNotMapped < NotMapped
|
47
|
+
def initialize(string)
|
48
|
+
super('Field', string)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class CrudActionNotMapped < NotMapped
|
53
|
+
def initialize(string)
|
54
|
+
super('CRUD Action', string)
|
55
|
+
end
|
56
|
+
end
|
2
57
|
module Base
|
3
58
|
def parsed_attributes(raw_attributes)
|
4
59
|
attributes = {}
|
@@ -70,4 +125,5 @@ module MundoPepino
|
|
70
125
|
[attribs.keys.map{|s| "#{s}=?"}.join(' AND ')] + attribs.values
|
71
126
|
end
|
72
127
|
end
|
128
|
+
|
73
129
|
end
|
@@ -1,17 +1,19 @@
|
|
1
1
|
# MundoPepino's step definitions in en_US
|
2
2
|
# Simple creation w/ optional name/s
|
3
3
|
Given /^(?:that we have )?(#{_number_}) (?!.+ #{_which_})(.+?)(?: (?:called )?['"](.+)["'])?$/i do |number, model, name|
|
4
|
-
given_we_have_a_number_of_instances_called number
|
4
|
+
given_we_have_a_number_of_instances_called :number => number,
|
5
|
+
:model => model, :name => name
|
5
6
|
end
|
6
7
|
|
7
8
|
When /^#{_i_visit_} (.+)$/ do |page|
|
8
|
-
given_or_when_i_do_a_page_request page
|
9
|
+
given_or_when_i_do_a_page_request :page => page
|
9
10
|
end
|
10
11
|
|
11
12
|
Then /^I (#{_should_or_not_}) see the text (.+)$/ do |should, text|
|
12
|
-
then_i_see_or_not_the_text should, text
|
13
|
+
then_i_see_or_not_the_text :should => should, :text => text
|
13
14
|
end
|
14
15
|
|
15
|
-
Then /^we have (#{_number_}) ([^ ]+)(?: (?:called )?['"](.+)["'])? in our database$/ do |number, model,
|
16
|
-
then_we_have_a_number_of_instances_in_our_database number
|
16
|
+
Then /^we have (#{_number_}) ([^ ]+)(?: (?:called )?['"](.+)["'])? in our database$/ do |number, model, name|
|
17
|
+
then_we_have_a_number_of_instances_in_our_database :number => number,
|
18
|
+
:model => model, :name => name
|
17
19
|
end
|
@@ -1,13 +1,11 @@
|
|
1
1
|
module MundoPepino
|
2
2
|
class << self
|
3
3
|
def language_specific_mappings
|
4
|
-
String.
|
4
|
+
String.real_value_mappings = {
|
5
5
|
/^tru(e|th)$/i => true,
|
6
6
|
/^false$/i => false
|
7
|
-
}
|
8
|
-
String.
|
9
|
-
|
10
|
-
String.add_mapper(:number, {
|
7
|
+
}
|
8
|
+
String.number_mappings = {
|
11
9
|
/^an?$/i => 1,
|
12
10
|
/^one$/i => 1,
|
13
11
|
/^first?$/i => 1,
|
@@ -24,13 +22,13 @@ module MundoPepino
|
|
24
22
|
/^eight$/i => 8,
|
25
23
|
/^nine$/i => 9,
|
26
24
|
/^ten$/i => 10
|
27
|
-
}
|
28
|
-
String.
|
25
|
+
}
|
26
|
+
String.crud_action_mappings = {
|
29
27
|
/^creation$/i => 'new',
|
30
|
-
/^changes?$/i
|
31
|
-
/^modifications?$/i
|
32
|
-
/^editions?$/i
|
33
|
-
|
28
|
+
/^changes?$/i => 'edit',
|
29
|
+
/^modifications?$/i => 'edit',
|
30
|
+
/^editions?$/i => 'edit'
|
31
|
+
}
|
34
32
|
String.url_mappings[/^the home\s?page/i] = self.world.root_path
|
35
33
|
end
|
36
34
|
end
|
@@ -1,7 +1,10 @@
|
|
1
1
|
# MundoPepino's step definitions in es_ES
|
2
2
|
# Creación simple con nombre opcional
|
3
3
|
Dado /^(?:que tenemos )?(#{_numero_}) (?!.+ #{_cuyo_})(.+?)(?: (?:llamad[oa]s? )?['"](.+)["'])?$/i do |numero, modelo, nombre|
|
4
|
-
given_we_have_a_number_of_instances_called
|
4
|
+
given_we_have_a_number_of_instances_called(
|
5
|
+
:number => numero,
|
6
|
+
:model => modelo,
|
7
|
+
:name => nombre)
|
5
8
|
end
|
6
9
|
|
7
10
|
# Creación con asignación de valor en campo
|
@@ -11,39 +14,26 @@ Dado /^(?:que tenemos )?(#{_numero_}) (.+) #{_cuyo_} (.+?) (?:(?:es|son) (?:de )
|
|
11
14
|
end
|
12
15
|
|
13
16
|
Dado /^(?:que tenemos )?(?:el|la|los|las|el\/la|los\/las) (?:siguientes? )?(.+):$/ do |modelo, tabla|
|
14
|
-
model
|
15
|
-
add_resource model, translated_hashes(tabla.raw, :model => model), :force_creation => true
|
17
|
+
given_we_have_the_following_instances_from_step_table :model => modelo, :table => tabla
|
16
18
|
end
|
17
19
|
|
18
20
|
Dado /^que (?:el|la) (.+) ['"](.+)["'] tiene como (.+) ['"](.+)["'](?: \w+)?$/ do |modelo, nombre, campo, valor|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
else
|
24
|
-
raise MundoPepino::FieldNotMapped.new(campo)
|
25
|
-
end
|
26
|
-
end
|
21
|
+
given_resource_has_value_in_field :model => modelo,
|
22
|
+
:name => nombre,
|
23
|
+
:field => campo,
|
24
|
+
:value => valor
|
27
25
|
end
|
28
26
|
|
29
27
|
Dado /^que dich[oa]s? (.+) tienen? como (.+) ['"](.+)["'](?:.+)?$/i do |modelo, campo, valor|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
resources.each_with_index do |r, i|
|
34
|
-
r.update_attribute field, real_value_for(values[i])
|
35
|
-
end
|
36
|
-
pile_up res
|
37
|
-
else
|
38
|
-
raise MundoPepino::FieldNotMapped.new(campo)
|
39
|
-
end
|
40
|
-
end
|
28
|
+
given_those_resources_have_value_in_field :model => modelo,
|
29
|
+
:field => campo,
|
30
|
+
:value => valor
|
41
31
|
end
|
42
32
|
|
43
33
|
Dado /^que (?:el|la) (.+) ['"](.+)["'] tiene (#{_numero_}) (.+?)(?: (?:llamad[oa]s? )?['"](.+)["'])?$/i do |modelo_padre, nombre_del_padre, numero, campo_hijos, nombres|
|
44
34
|
given_resource_has_many_children(
|
45
|
-
:
|
46
|
-
:
|
35
|
+
:model => modelo_padre,
|
36
|
+
:name => nombre_del_padre,
|
47
37
|
:number_of_children => numero,
|
48
38
|
:children_field => campo_hijos,
|
49
39
|
:children_names => nombres)
|
@@ -51,7 +41,7 @@ end
|
|
51
41
|
|
52
42
|
Dado /^que dich[oa]s? (.+) tienen? (#{_numero_}) (.+?)(?: (?:llamad[oa]s? )?['"](.+)["'])?$/i do |modelo_padre, numero, campo_hijos, nombres|
|
53
43
|
given_resource_has_many_children(
|
54
|
-
:
|
44
|
+
:model => modelo_padre,
|
55
45
|
:number_of_children => numero,
|
56
46
|
:children_field => campo_hijos,
|
57
47
|
:children_names => nombres)
|
@@ -59,15 +49,15 @@ end
|
|
59
49
|
|
60
50
|
Dado /^que (?:el|la) (.+) ['"](.+)["'] tiene (?:el|la|los|las) siguientes? (.+):$/i do |modelo_padre, nombre_del_padre, campo_hijos, tabla|
|
61
51
|
given_resource_has_many_children_from_step_table(
|
62
|
-
:
|
63
|
-
:
|
52
|
+
:model => modelo_padre,
|
53
|
+
:name => nombre_del_padre,
|
64
54
|
:children_field => campo_hijos,
|
65
55
|
:step_table => tabla)
|
66
56
|
end
|
67
57
|
|
68
58
|
Dado /^que dich[ao]s? (.+) tienen? (?:el|la|los|las) siguientes? (.+):$/i do |modelo_padre, campo_hijos, tabla|
|
69
59
|
given_resource_has_many_children_from_step_table(
|
70
|
-
:
|
60
|
+
:model => modelo_padre,
|
71
61
|
:children_field => campo_hijos,
|
72
62
|
:step_table => tabla)
|
73
63
|
end
|
@@ -76,7 +66,7 @@ end
|
|
76
66
|
###############################################################################
|
77
67
|
|
78
68
|
Cuando /^(?:que )?#{_visito_} (.+)$/i do |pagina|
|
79
|
-
given_or_when_i_do_a_page_request pagina
|
69
|
+
given_or_when_i_do_a_page_request :page => pagina
|
80
70
|
end
|
81
71
|
|
82
72
|
Cuando /^(?:que )?#{_pulso_} (?:en )?el bot[oó]n (.+)$/i do |boton|
|
@@ -89,7 +79,9 @@ Cuando /^(?:que )?#{_pulso_} (?:en )?(#{_el_enlace_}) (.+?)(?:#{_que_existe_} #{
|
|
89
79
|
Entonces "veo el enlace #{href}"
|
90
80
|
Y "visito #{href}"
|
91
81
|
else
|
92
|
-
given_or_when_i_follow_the_link
|
82
|
+
given_or_when_i_follow_the_link(
|
83
|
+
:link => enlace.to_unquoted.to_translated,
|
84
|
+
:selector => selector)
|
93
85
|
end
|
94
86
|
end
|
95
87
|
|
@@ -182,7 +174,9 @@ end
|
|
182
174
|
|
183
175
|
#############################################################################
|
184
176
|
Entonces /^(#{_veo_o_no_}) el texto (.+?)(?: #{_dentro_de_} ['"]?(.+?)["']?)?$/i do |should, text, selector|
|
185
|
-
then_i_see_or_not_the_text should
|
177
|
+
then_i_see_or_not_the_text :should => should,
|
178
|
+
:text => text,
|
179
|
+
:selector => selector
|
186
180
|
end
|
187
181
|
|
188
182
|
Entonces /^(#{_leo_o_no_}) el texto (.+)?$/i do |should, text|
|
@@ -233,7 +227,8 @@ Entonces /^(#{_veo_o_no_}) (?:un|el) enlace (?:al? |para )?(.+)?$/i do |should,
|
|
233
227
|
}.send(not_shouldify(should), raise_error)
|
234
228
|
end
|
235
229
|
|
236
|
-
Entonces /^(#{_veo_o_no_}) el campo (.+) con el (?:valor|texto)? (.+)$/ do |should, campo, valor|
|
230
|
+
#Entonces /^(#{_veo_o_no_}) el campo (.+) con el (?:valor|texto)? (.+)$/ do |should, campo, valor|
|
231
|
+
Entonces /^(#{_veo_o_no_}) el campo (.+) con(?: el (?:valor|texto))? ['"]?(.+?)["']$/ do |should, campo, valor|
|
237
232
|
field_labeled(campo.to_unquoted).value.send shouldify(should), match(/#{valor.to_unquoted}/)
|
238
233
|
end
|
239
234
|
|
@@ -288,34 +283,42 @@ end
|
|
288
283
|
|
289
284
|
#BBDD
|
290
285
|
Entonces /^#{_tenemos_en_bbdd_} (#{_numero_}) ([^ ]+)(?: (?:llamad[oa]s? )?['"](.+)["'])?$/ do |numero, modelo, nombre|
|
291
|
-
then_we_have_a_number_of_instances_in_our_database numero,
|
286
|
+
then_we_have_a_number_of_instances_in_our_database :number => numero,
|
287
|
+
:model => modelo,
|
288
|
+
:name => nombre
|
292
289
|
end
|
293
290
|
|
294
291
|
Entonces /^(?:el|la) (.+) ['"](.+)["'] #{_tiene_en_bbdd_} como (.+) ['"](.+)["'](?: \w+)?$/ do |modelo, nombre, campo, valor|
|
295
|
-
|
296
|
-
|
292
|
+
then_resource_called_name_should_have_value_in_field :model => modelo,
|
293
|
+
:name => nombre,
|
294
|
+
:field => campo,
|
295
|
+
:value => valor
|
297
296
|
end
|
298
297
|
|
299
298
|
Entonces /^#{_tiene_en_bbdd_} como (.+) ['"](.+)["'](?: \w+)?$/ do |campo, valor|
|
300
|
-
|
299
|
+
then_that_resource_should_have_value_in_field :field => campo, :value => valor
|
301
300
|
end
|
302
301
|
|
303
302
|
Entonces /^(?:el|la) (.+) ['"](.+)["'] #{_tiene_en_bbdd_} una? (.+) ['"](.+)["']$/ do |padre, nombre_del_padre, hijo, nombre_del_hijo|
|
304
|
-
|
305
|
-
|
303
|
+
then_resource_called_name_should_have_child :model => padre,
|
304
|
+
:name => nombre_del_padre,
|
305
|
+
:children_field => hijo,
|
306
|
+
:child_name => nombre_del_hijo
|
306
307
|
end
|
307
308
|
|
308
|
-
Entonces /^(?:el|la) (.+) "(.+)" #{_tiene_en_bbdd_} (#{_numero_}) ['"]?([^"']+)["']?$/ do |
|
309
|
-
|
310
|
-
|
309
|
+
Entonces /^(?:el|la) (.+) "(.+)" #{_tiene_en_bbdd_} (#{_numero_}) ['"]?([^"']+)["']?$/ do |modelo, nombre, numero, relacion|
|
310
|
+
then_resource_called_name_should_have_n_children :number => numero,
|
311
|
+
:model => modelo,
|
312
|
+
:name => nombre,
|
313
|
+
:children_field => relacion
|
311
314
|
end
|
312
315
|
|
313
316
|
Entonces /^#{_tiene_en_bbdd_} una? (.+) ['"](.+)["']$/ do |hijo, nombre_del_hijo|
|
314
|
-
|
317
|
+
then_that_resource_should_have_child :children_field => hijo, :child_name => nombre_del_hijo
|
315
318
|
end
|
316
319
|
|
317
|
-
Entonces /^#{_tiene_en_bbdd_} (#{_numero_}) ['"]?([^"']+)["']?$/ do |numero,
|
318
|
-
|
320
|
+
Entonces /^#{_tiene_en_bbdd_} (#{_numero_}) ['"]?([^"']+)["']?$/ do |numero, hijo|
|
321
|
+
then_that_resource_should_have_n_children :number => numero, :children_field => hijo
|
319
322
|
end
|
320
323
|
|
321
324
|
Entonces /^#{_debo_estar_en_} (.+)$/i do |pagina|
|
@@ -2,13 +2,12 @@ module MundoPepino
|
|
2
2
|
class << self
|
3
3
|
include Matchers::Fragments
|
4
4
|
def language_specific_mappings
|
5
|
-
String.
|
5
|
+
String.field_mappings[/^nombres?/i] = :name
|
6
|
+
String.real_value_mappings = {
|
6
7
|
/^verdader[oa]$/i => true,
|
7
8
|
/^fals[ao]$/i => false
|
8
|
-
}
|
9
|
-
String.
|
10
|
-
|
11
|
-
String.add_mapper(:number, {
|
9
|
+
}
|
10
|
+
String.number_mappings = {
|
12
11
|
/^un[oa]?$/i => 1,
|
13
12
|
/^primer[oa]?$/i => 1,
|
14
13
|
:dos => 2,
|
@@ -24,16 +23,17 @@ module MundoPepino
|
|
24
23
|
:ocho => 8,
|
25
24
|
:nueve => 9,
|
26
25
|
:diez => 10
|
27
|
-
}
|
28
|
-
String.
|
26
|
+
}
|
27
|
+
String.crud_action_mappings = {
|
29
28
|
/^alta(?: de (?:una? )?nuev[ao])?$/i => 'new',
|
30
29
|
/^creaci[óo]n(?: de (?:una? )?nuev[ao])?$/i => 'new',
|
31
30
|
/^nuev(?:o|a|o\/a|a\/o)$/i => 'new',
|
32
31
|
/^inicio|comienzo$/i => 'new',
|
33
|
-
/^cambio$/i
|
34
|
-
/^modificaci[oó]n(?:es)?$/i
|
35
|
-
/^edici[oó]n$/i
|
36
|
-
|
32
|
+
/^cambio$/i => 'edit',
|
33
|
+
/^modificaci[oó]n(?:es)?$/i => 'edit',
|
34
|
+
/^edici[oó]n$/i => 'edit'
|
35
|
+
}
|
36
|
+
String.month_mappings = {
|
37
37
|
:enero => 'January',
|
38
38
|
:febrero => 'February',
|
39
39
|
:marzo => 'March',
|
@@ -45,7 +45,8 @@ module MundoPepino
|
|
45
45
|
/^sep?tiembre$/i => 'September',
|
46
46
|
:octubre => 'October',
|
47
47
|
:noviembre => 'November',
|
48
|
-
:diciembre => 'December'
|
48
|
+
:diciembre => 'December'
|
49
|
+
}
|
49
50
|
String.url_mappings.merge!({
|
50
51
|
/^la (?:portada|home\s?(?:page)?)$/i => lambda{MundoPepino.world.root_path},
|
51
52
|
/^(#{_el_listado_de_}) ([\w]+|['"][\w ]+["'])$/i =>
|
@@ -1,74 +1,132 @@
|
|
1
1
|
module MundoPepino
|
2
2
|
module Implementations
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
3
|
+
# Params:
|
4
|
+
# :model (raw)
|
5
|
+
# :number (f.e. "a", "three")
|
6
|
+
# :name ("Foo") or :names ("Foo, Fu and Kunfu")
|
7
|
+
def given_we_have_a_number_of_instances_called(params)
|
8
|
+
model = params[:model].to_unquoted.to_model || raise(ModelNotMapped.new(params[:model]))
|
9
|
+
number = params[:number].to_number
|
10
|
+
attribs = names_for_simple_creation(model, number, params[:name])
|
11
|
+
add_resource(model, attribs, :force_creation => true)
|
12
|
+
end
|
13
|
+
|
14
|
+
# Params:
|
15
|
+
# :model (raw)
|
16
|
+
# :table
|
17
|
+
def given_we_have_the_following_instances_from_step_table(params)
|
18
|
+
model = convert_to_model(params[:model])
|
19
|
+
add_resource model, translated_hashes(params[:table].raw, :model => model),
|
20
|
+
:force_creation => true
|
21
|
+
end
|
22
|
+
|
23
|
+
# Params:
|
24
|
+
# :model
|
25
|
+
# :name
|
26
|
+
# :field
|
27
|
+
# :value
|
28
|
+
def given_resource_has_value_in_field(params)
|
29
|
+
if resource = last_mentioned_of(params[:model], params[:name])
|
30
|
+
if field = field_for(resource.class, params[:field])
|
31
|
+
resource.update_attribute field, real_value_for(params[:value])
|
32
|
+
pile_up resource
|
33
|
+
else
|
34
|
+
raise MundoPepino::FieldNotMapped.new(params[:field])
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Params:
|
40
|
+
# :model
|
41
|
+
# :field
|
42
|
+
# :value
|
43
|
+
def given_those_resources_have_value_in_field(params)
|
44
|
+
if res = last_mentioned_of(params[:model])
|
45
|
+
resources, field, values = resources_array_field_and_values(res, params[:field], params[:value])
|
46
|
+
if field
|
47
|
+
resources.each_with_index do |r, i|
|
48
|
+
r.update_attribute field, real_value_for(values[i])
|
49
|
+
end
|
50
|
+
pile_up res
|
51
|
+
else
|
52
|
+
raise MundoPepino::FieldNotMapped.new(params[:field])
|
53
|
+
end
|
10
54
|
end
|
11
55
|
end
|
12
56
|
|
13
57
|
def given_resource_has_many_children(params)
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
parent_options(resource, children_model, params[:children_field]))
|
21
|
-
add_resource children_model, attribs, :force_creation => params[:children_names].nil?
|
22
|
-
end
|
23
|
-
pile_up mentioned
|
58
|
+
children_model = convert_to_model(params[:children_field])
|
59
|
+
last_mentioned_resources(params[:model], params[:name]) do |resource|
|
60
|
+
attribs = names_for_simple_creation(children_model,
|
61
|
+
params[:number_of_children].to_number, params[:children_names],
|
62
|
+
parent_options(resource, children_model, params[:children_field]))
|
63
|
+
add_resource children_model, attribs, :force_creation => params[:children_names].nil?
|
24
64
|
end
|
25
65
|
end
|
26
66
|
|
27
67
|
def given_resource_has_many_children_from_step_table(params)
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
options[:model] = children_model
|
34
|
-
add_resource children_model,
|
35
|
-
translated_hashes(params[:step_table].raw, options)
|
36
|
-
end
|
68
|
+
children_model = convert_to_model(params[:children_field])
|
69
|
+
last_mentioned_resources(params[:model], params[:name]) do |resource|
|
70
|
+
options = parent_options(resource, children_model, params[:children_field])
|
71
|
+
options[:model] = children_model
|
72
|
+
add_resource children_model, translated_hashes(params[:step_table].raw, options)
|
37
73
|
end
|
38
74
|
end
|
39
75
|
|
40
|
-
def given_or_when_i_do_a_page_request(
|
41
|
-
do_visit page.to_unquoted.to_url
|
76
|
+
def given_or_when_i_do_a_page_request(params)
|
77
|
+
do_visit params[:page].to_unquoted.to_url
|
42
78
|
end
|
43
79
|
|
44
|
-
def
|
45
|
-
|
46
|
-
|
80
|
+
def given_or_when_i_follow_the_link(params)
|
81
|
+
if params[:selector]
|
82
|
+
click_link_within params[:selector], params[:link]
|
83
|
+
else
|
84
|
+
click_link params[:link]
|
47
85
|
end
|
48
86
|
end
|
49
87
|
|
50
|
-
def
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
88
|
+
def then_i_see_or_not_the_text(params)
|
89
|
+
within params[:selector] || 'html' do
|
90
|
+
response.send(
|
91
|
+
shouldify(params[:should]),
|
92
|
+
contain(params[:text].to_unquoted.to_translated.to_regexp))
|
55
93
|
end
|
56
94
|
end
|
57
95
|
|
58
96
|
# DB CHECKS
|
59
|
-
def then_we_have_a_number_of_instances_in_our_database(
|
60
|
-
model =
|
61
|
-
conditions =
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
97
|
+
def then_we_have_a_number_of_instances_in_our_database(params)
|
98
|
+
model = convert_to_model(params[:model])
|
99
|
+
conditions = params[:name] && {:conditions => ["#{field_for(model)}=?", params[:name]]}
|
100
|
+
resources = model.find(:all, conditions || {})
|
101
|
+
resources.size.should == params[:number].to_number
|
102
|
+
pile_up (resources.size == 1 ? resources.first : resources) if resources.size > 0
|
103
|
+
end
|
104
|
+
|
105
|
+
def then_resource_called_name_should_have_n_children(params)
|
106
|
+
add_resource_from_database params[:model], params[:name]
|
107
|
+
then_that_resource_should_have_n_children params
|
108
|
+
end
|
109
|
+
|
110
|
+
def then_that_resource_should_have_n_children(params)
|
111
|
+
last_mentioned_should_have_n_children(params[:children_field], params[:number])
|
112
|
+
end
|
113
|
+
|
114
|
+
def then_resource_called_name_should_have_value_in_field(params)
|
115
|
+
add_resource_from_database(params[:model], params[:name])
|
116
|
+
then_that_resource_should_have_value_in_field params
|
117
|
+
end
|
118
|
+
|
119
|
+
def then_that_resource_should_have_value_in_field(params)
|
120
|
+
last_mentioned_should_have_value(params[:field], params[:value].to_real_value)
|
121
|
+
end
|
122
|
+
|
123
|
+
def then_resource_called_name_should_have_child(params)
|
124
|
+
add_resource_from_database params[:model], params[:name]
|
125
|
+
then_that_resource_should_have_child params
|
126
|
+
end
|
71
127
|
|
128
|
+
def then_that_resource_should_have_child(params)
|
129
|
+
last_mentioned_should_have_child(params[:children_field], params[:child_name])
|
72
130
|
end
|
73
131
|
end
|
74
132
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'rubygems'
|
1
2
|
require 'nokogiri'
|
2
3
|
|
3
4
|
module MundoPepino
|
@@ -77,6 +78,10 @@ module MundoPepino
|
|
77
78
|
end
|
78
79
|
end
|
79
80
|
|
81
|
+
def convert_to_model(raw_model)
|
82
|
+
raw_model.to_unquoted.to_model || raise(ModelNotMapped.new(raw_model))
|
83
|
+
end
|
84
|
+
|
80
85
|
def convert_to_field(raw_field, model = nil)
|
81
86
|
unless raw_field.nil?
|
82
87
|
if field = field_for(model, raw_field.to_unquoted)
|
@@ -90,11 +95,12 @@ module MundoPepino
|
|
90
95
|
def last_mentioned_children(field_raw)
|
91
96
|
if child_model = field_raw.to_model
|
92
97
|
parent_model = last_mentioned.mr_model
|
93
|
-
last_mentioned.send field_for(parent_model, field_raw) ||
|
98
|
+
children = last_mentioned.send field_for(parent_model, field_raw) ||
|
94
99
|
field_for(parent_model, child_model.table_name) ||
|
95
100
|
child_model.table_name
|
101
|
+
children.is_a?(Array) ? children : [children] #for has_one_associations
|
96
102
|
else
|
97
|
-
raise
|
103
|
+
raise ModelNotMapped.new(field_raw)
|
98
104
|
end
|
99
105
|
end
|
100
106
|
|
@@ -22,55 +22,6 @@ module MundoPepino
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
class ResourceNotFound < RuntimeError
|
26
|
-
def initialize(resource_info=nil)
|
27
|
-
@resource_info = resource_info && " (#{resource_info})"
|
28
|
-
end
|
29
|
-
def message
|
30
|
-
"Resource not found#{@resource_info}"
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
class WithoutResources < ResourceNotFound
|
35
|
-
def initialize
|
36
|
-
super 'there is no resources'
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
class NotFoundInDatabase < ResourceNotFound
|
41
|
-
def initialize(model, value='')
|
42
|
-
super "#{model} #{value} not found in database"
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
class NotMapped < RuntimeError
|
47
|
-
def initialize(type, string)
|
48
|
-
@type = type
|
49
|
-
@string = string
|
50
|
-
end
|
51
|
-
def message
|
52
|
-
"#{@type} not mapped '#{@string}'"
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
class ModelNotMapped < NotMapped
|
57
|
-
def initialize(string)
|
58
|
-
super('Model', string)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
class FieldNotMapped < NotMapped
|
63
|
-
def initialize(string)
|
64
|
-
super('Field', string)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
class CrudActionNotMapped < NotMapped
|
69
|
-
def initialize(string)
|
70
|
-
super('CRUD Action', string)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
25
|
# options: :force_creation
|
75
26
|
def add_resource(model, attribs=[], options = {})
|
76
27
|
attributes = if attribs.is_a?(Hash)
|
@@ -89,12 +40,12 @@ module MundoPepino
|
|
89
40
|
end
|
90
41
|
|
91
42
|
def add_resource_from_database(raw_model, name)
|
92
|
-
model = raw_model
|
43
|
+
model = convert_to_model(raw_model)
|
93
44
|
field = field_for(model)
|
94
45
|
if resource = model.send("find_by_#{field}", name)
|
95
46
|
pile_up resource
|
96
47
|
else
|
97
|
-
NotFoundInDatabase.new(model, name)
|
48
|
+
raise NotFoundInDatabase.new(model, name)
|
98
49
|
end
|
99
50
|
end
|
100
51
|
|
@@ -129,7 +80,11 @@ module MundoPepino
|
|
129
80
|
if mentioned = detect_first(resources_flatten, [model, with_name])
|
130
81
|
mentioned
|
131
82
|
else
|
132
|
-
|
83
|
+
begin
|
84
|
+
add_resource_from_database(raw_model, with_name)
|
85
|
+
rescue
|
86
|
+
raise NotFoundInHistoryNorDatabase.new(model.name, with_name)
|
87
|
+
end
|
133
88
|
end
|
134
89
|
elsif(last_mentioned.mr_model == model)
|
135
90
|
last_mentioned
|
@@ -149,6 +104,16 @@ module MundoPepino
|
|
149
104
|
def last_mentioned_called(name)
|
150
105
|
detect_first resources_flatten, name
|
151
106
|
end
|
107
|
+
|
108
|
+
def last_mentioned_resources(model, name)
|
109
|
+
mentioned = last_mentioned_of(model.to_unquoted, name)
|
110
|
+
if mentioned.is_a?(Array)
|
111
|
+
mentioned.each {|m| yield m}
|
112
|
+
else
|
113
|
+
yield mentioned
|
114
|
+
end
|
115
|
+
pile_up mentioned
|
116
|
+
end
|
152
117
|
|
153
118
|
def recursive_group_search(model, resources)
|
154
119
|
if lm = resources.shift
|
data/lib/mundo_pepino/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mundo-pepino
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "Fernando Garc\xC3\xADa Samblas"
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-12-07 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|