mundo-pepino 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +9 -0
- data/Manifest.txt +4 -1
- data/README.markdown +20 -476
- data/README_es.markdown +534 -0
- data/lib/mundo_pepino.rb +20 -1
- data/lib/mundo_pepino/definitions/en_US.rb +41 -0
- data/lib/mundo_pepino/definitions/es_ES.rb +34 -69
- data/lib/mundo_pepino/implementations.rb +54 -0
- data/lib/mundo_pepino/version.rb +1 -1
- data/lib/mundo_pepino_en_US.rb +2 -0
- metadata +6 -2
data/lib/mundo_pepino.rb
CHANGED
@@ -2,14 +2,33 @@ $:.unshift(File.dirname(__FILE__)) unless
|
|
2
2
|
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
3
|
|
4
4
|
require 'cucumber/rails/world'
|
5
|
+
require 'mundo_pepino/implementations'
|
5
6
|
require 'mundo_pepino/resources_history'
|
6
7
|
require 'mundo_pepino/visits_history'
|
7
8
|
require 'mundo_pepino/version'
|
8
9
|
|
9
10
|
require 'string-mapper'
|
10
11
|
|
11
|
-
|
12
|
+
String.add_mapper :model
|
13
|
+
String.add_mapper :relation_model
|
14
|
+
String.add_mapper(:content_type,
|
15
|
+
/\.png$/ => 'image/png',
|
16
|
+
/\.jpe?g$/ => 'image/jpg',
|
17
|
+
/\.gif$/ => 'image/gif') { |str| 'text/plain' }
|
18
|
+
String.add_mapper(:underscored) { |string| string.gsub(/ +/, '_') }
|
19
|
+
String.add_mapper(:unquoted) { |str| str =~ /^['"](.*)['"]$/ ? $1 : str}
|
20
|
+
String.add_mapper(:translated) { |str|
|
21
|
+
if str =~ /^[a-z_]+\.[a-z_]+[a-z_\.]+$/
|
22
|
+
I18n.translate(str, :default => str)
|
23
|
+
elsif str =~ /^([a-z_]+\.[a-z_]+[a-z_\.]+),(\{.+\})$/
|
24
|
+
I18n.translate($1, {:default => str}.merge(eval($2)))
|
25
|
+
else
|
26
|
+
str
|
27
|
+
end
|
28
|
+
}
|
12
29
|
|
30
|
+
module MundoPepino
|
31
|
+
include Implementations
|
13
32
|
include ResourcesHistory
|
14
33
|
include VisitsHistory
|
15
34
|
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# MundoPepino's step definitions in en_US
|
2
|
+
|
3
|
+
String.add_mapper(:real_value, {
|
4
|
+
/^tru(e|th)$/i => true,
|
5
|
+
/^false$/i => false
|
6
|
+
}) { |value| value } # "true".to_real_value # => true
|
7
|
+
String.add_mapper(:field, {:nombre => :name})
|
8
|
+
|
9
|
+
String.add_mapper(:url, /^the home(page)?/i => '/') do |string|
|
10
|
+
string if string =~ /^\/.*$|^https?:\/\//i
|
11
|
+
end
|
12
|
+
|
13
|
+
String.add_mapper(:number, {
|
14
|
+
/^an?$/i => 1,
|
15
|
+
/^one$/i => 1,
|
16
|
+
/^first?$/i => 1,
|
17
|
+
/^two$/i => 2,
|
18
|
+
/^second$/i => 2,
|
19
|
+
/^three$/i => 3,
|
20
|
+
/^third$/i => 3,
|
21
|
+
/^four$/i => 4,
|
22
|
+
/^fourth$/i => 4,
|
23
|
+
/^five$/i => 5,
|
24
|
+
/^fifth$/i => 5}) { |string| string.to_i }
|
25
|
+
String.add_mapper(:crud_action,
|
26
|
+
/^creation$/i => 'new',
|
27
|
+
/^changes?$/i => 'edit',
|
28
|
+
/^modifications?$/i => 'edit',
|
29
|
+
/^editions?$/i => 'edit') { |action| action }
|
30
|
+
String.add_mapper(:month) { |month| month.capitalize }
|
31
|
+
|
32
|
+
number = 'a|an|one|two|three|four|five|six|seven|eight|nine|ten|\d+'
|
33
|
+
which = '(?:which|that have as)'
|
34
|
+
# Simple creation w/ optional name/s
|
35
|
+
Given /^(?:that we have )?(#{number}) (?!.+ #{which})(.+?)(?: (?:called )?['"](.+)["'])?$/i do |number, model, name|
|
36
|
+
given_we_have_a_number_of_instances_called number, model, name
|
37
|
+
end
|
38
|
+
|
39
|
+
Then /^we have (#{number}) ([^ ]+)(?: (?:called )?['"](.+)["'])? in our database$/ do |number, model, names|
|
40
|
+
then_we_have_a_number_of_instances_in_our_database number, model, names
|
41
|
+
end
|
@@ -1,19 +1,9 @@
|
|
1
|
-
|
2
|
-
module Cucumber::StepMethods
|
3
|
-
alias_method :Dado, :Given
|
4
|
-
alias_method :Cuando, :When
|
5
|
-
alias_method :Entonces, :Then
|
6
|
-
end
|
7
|
-
rescue
|
8
|
-
# NO NEED TO CREATE ALIASES IN post-0.2 Cucumbers
|
9
|
-
end
|
1
|
+
# MundoPepino's step definitions in es_ES
|
10
2
|
|
11
3
|
String.add_mapper(:real_value, {
|
12
4
|
/^verdader[oa]$/i => true,
|
13
5
|
/^fals[ao]$/i => false
|
14
6
|
}) { |value| value }
|
15
|
-
String.add_mapper :model
|
16
|
-
String.add_mapper :relation_model
|
17
7
|
String.add_mapper(:field) { |str| :name if str =~ /nombres?/ }
|
18
8
|
String.add_mapper(:url, /^la (portada|home)/i => '/') do |string|
|
19
9
|
string if string =~ /^\/.*$|^https?:\/\//i
|
@@ -50,38 +40,15 @@ String.add_mapper(:month,
|
|
50
40
|
:octubre => 'October',
|
51
41
|
:noviembre => 'November',
|
52
42
|
:diciembre => 'December')
|
53
|
-
String.add_mapper(:content_type,
|
54
|
-
/\.png$/ => 'image/png',
|
55
|
-
/\.jpe?g$/ => 'image/jpg',
|
56
|
-
/\.gif$/ => 'image/gif') { |str| 'text/plain' }
|
57
|
-
String.add_mapper(:underscored) { |string| string.gsub(/ +/, '_') }
|
58
|
-
String.add_mapper(:unquoted) { |str| str =~ /^['"](.*)['"]$/ ? $1 : str}
|
59
|
-
String.add_mapper(:translated) { |str|
|
60
|
-
if str =~ /^[a-z_]+\.[a-z_]+[a-z_\.]+$/
|
61
|
-
I18n.translate(str, :default => str)
|
62
|
-
elsif str =~ /^([a-z_]+\.[a-z_]+[a-z_\.]+),(\{.+\})$/
|
63
|
-
I18n.translate($1, {:default => str}.merge(eval($2)))
|
64
|
-
else
|
65
|
-
str
|
66
|
-
end
|
67
|
-
}
|
68
|
-
|
69
|
-
|
70
43
|
|
71
|
-
|
44
|
+
nro = 'un|una|dos|tres|cuatro|cinco|seis|siete|ocho|nueve|diez|\d+'
|
72
45
|
cuyo = '(?:cuy[oa]s?|que tienen? como)'
|
73
46
|
# Creación simple con nombre opcional
|
74
|
-
Dado /^(?:que tenemos )?(#{
|
75
|
-
|
76
|
-
number = numero.to_number
|
77
|
-
attribs = names_for_simple_creation(model, number, nombre)
|
78
|
-
add_resource(model, attribs, :force_creation => true)
|
79
|
-
else
|
80
|
-
raise MundoPepino::ModelNotMapped.new(modelo)
|
81
|
-
end
|
47
|
+
Dado /^(?:que tenemos )?(#{nro}) (?!.+ #{cuyo})(.+?)(?: (?:llamad[oa]s? )?['"](.+)["'])?$/i do |numero, modelo, nombre|
|
48
|
+
given_we_have_a_number_of_instances_called numero, modelo, nombre
|
82
49
|
end
|
83
50
|
# Creación con asignación de valor en campo
|
84
|
-
Dado /^(?:que tenemos )?(#{
|
51
|
+
Dado /^(?:que tenemos )?(#{nro}) (.+) #{cuyo} (.+?) (?:(?:es|son) (?:de )?)?['"](.+)["'](?: .+)?$/i do |numero, modelo, campo, valor|
|
85
52
|
Dado "que tenemos #{numero} #{modelo}"
|
86
53
|
Dado "que dichos #{modelo} tienen como #{campo} '#{valor}'"
|
87
54
|
end
|
@@ -116,28 +83,36 @@ Dado /^que dich[oa]s? (.+) tienen? como (.+) ['"](.+)["'](?:.+)?$/i do |modelo,
|
|
116
83
|
end
|
117
84
|
end
|
118
85
|
|
119
|
-
Dado /^que
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
86
|
+
Dado /^que (?:el|la) (.+) ['"](.+)["'] tiene (#{nro}) (.+?)(?: (?:llamad[oa]s? )?['"](.+)["'])?$/i do |modelo_padre, nombre_del_padre, numero, modelo_hijos, nombres|
|
87
|
+
given_resource_has_many_children(
|
88
|
+
:resource_model => modelo_padre,
|
89
|
+
:resource_name => nombre_del_padre,
|
90
|
+
:number_of_children => numero,
|
91
|
+
:children_model => modelo_hijos,
|
92
|
+
:children_names => nombres)
|
93
|
+
end
|
94
|
+
|
95
|
+
Dado /^que dich[oa]s? (.+) tienen? (#{nro}) (.+?)(?: (?:llamad[oa]s? )?['"](.+)["'])?$/i do |modelo_padre, numero, modelo_hijos, nombres|
|
96
|
+
given_resource_has_many_children(
|
97
|
+
:resource_model => modelo_padre,
|
98
|
+
:number_of_children => numero,
|
99
|
+
:children_model => modelo_hijos,
|
100
|
+
:children_names => nombres)
|
101
|
+
end
|
102
|
+
|
103
|
+
Dado /^que (?:el|la) (.+) ['"](.+)["'] tiene (?:el|la|los|las) siguientes? (.+):$/i do |modelo_padre, nombre_del_padre, modelo_hijos, tabla|
|
104
|
+
given_resource_has_many_children_from_step_table(
|
105
|
+
:resource_model => modelo_padre,
|
106
|
+
:resource_name => nombre_del_padre,
|
107
|
+
:children_model => modelo_hijos,
|
108
|
+
:step_table => tabla)
|
130
109
|
end
|
131
110
|
|
132
111
|
Dado /^que dich[ao]s? (.+) tienen? (?:el|la|los|las) siguientes? (.+):$/i do |modelo_padre, modelo_hijos, tabla|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
add_resource children_model,
|
138
|
-
translated_hashes(tabla.raw, parent_options(resource, children_model))
|
139
|
-
end
|
140
|
-
end
|
112
|
+
given_resource_has_many_children_from_step_table(
|
113
|
+
:resource_model => modelo_padre,
|
114
|
+
:children_model => modelo_hijos,
|
115
|
+
:step_table => tabla)
|
141
116
|
end
|
142
117
|
|
143
118
|
|
@@ -387,18 +362,8 @@ end
|
|
387
362
|
#BBDD
|
388
363
|
en_bbdd_tenemos = '(?:en (?:la )?(?:bb?dd?|base de datos) tenemos|tenemos en (?:la )?(?:bb?dd?|base de datos))'
|
389
364
|
tiene_en_bbdd = '(?:tiene en (?:la )?bbdd|en (?:la )?bbdd tiene|tiene en (?:la )?base de datos|en (?:la )?base de datos tiene)'
|
390
|
-
Entonces /^#{en_bbdd_tenemos} (
|
391
|
-
|
392
|
-
conditions = if nombre
|
393
|
-
{:conditions => [ "#{field_for(model, 'nombre')}=?", nombre ]}
|
394
|
-
else
|
395
|
-
{}
|
396
|
-
end
|
397
|
-
resources = model.find(:all, conditions)
|
398
|
-
resources.size.should == numero.to_number
|
399
|
-
if resources.size > 0
|
400
|
-
pile_up (resources.size == 1 ? resources.first : resources)
|
401
|
-
end
|
365
|
+
Entonces /^#{en_bbdd_tenemos} (#{nro}) ([^ ]+)(?: (?:llamad[oa]s? )?['"](.+)["'])?$/ do |numero, modelo, nombre|
|
366
|
+
then_we_have_a_number_of_instances_in_our_database numero, modelo, nombre
|
402
367
|
end
|
403
368
|
|
404
369
|
Entonces /^(?:el|la) (.+) "(.+)" #{tiene_en_bbdd} como (.+) "(.+)"(?: \w+)?$/ do |modelo, nombre, campo, valor|
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module MundoPepino
|
2
|
+
module Implementations
|
3
|
+
def given_we_have_a_number_of_instances_called(raw_number, raw_model, name)
|
4
|
+
if model = raw_model.to_unquoted.to_model
|
5
|
+
number = raw_number.to_number
|
6
|
+
attribs = names_for_simple_creation(model, number, name)
|
7
|
+
add_resource(model, attribs, :force_creation => true)
|
8
|
+
else
|
9
|
+
raise MundoPepino::ModelNotMapped.new(raw_model)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def given_resource_has_many_children(params)
|
14
|
+
if mentioned = last_mentioned_of(params[:resource_model].to_unquoted, params[:resource_name])
|
15
|
+
children_model = params[:children_model].to_unquoted.to_model
|
16
|
+
resources = (mentioned.is_a?(Array) ? mentioned : [mentioned])
|
17
|
+
resources.each do |resource|
|
18
|
+
attribs = names_for_simple_creation(children_model,
|
19
|
+
params[:number_of_children].to_number, params[:children_names],
|
20
|
+
parent_options(resource, children_model))
|
21
|
+
add_resource children_model, attribs, :force_creation => params[:children_names].nil?
|
22
|
+
end
|
23
|
+
pile_up mentioned
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def given_resource_has_many_children_from_step_table(params)
|
28
|
+
if mentioned = last_mentioned_of(params[:resource_model].to_unquoted, params[:resource_name])
|
29
|
+
children_model = params[:children_model].to_unquoted.to_model
|
30
|
+
resources = (mentioned.is_a?(Array) ? mentioned : [mentioned])
|
31
|
+
resources.each do |resource|
|
32
|
+
add_resource children_model,
|
33
|
+
translated_hashes(params[:step_table].raw, parent_options(resource, children_model))
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# DB CHECKS
|
39
|
+
def then_we_have_a_number_of_instances_in_our_database(raw_number, raw_model, name)
|
40
|
+
model = raw_model.to_unquoted.to_model
|
41
|
+
conditions = if name
|
42
|
+
{:conditions => [ "#{field_for(model, 'nombre')}=?", name ]}
|
43
|
+
else
|
44
|
+
{}
|
45
|
+
end
|
46
|
+
resources = model.find(:all, conditions)
|
47
|
+
resources.size.should == raw_number.to_number
|
48
|
+
if resources.size > 0
|
49
|
+
pile_up (resources.size == 1 ? resources.first : resources)
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
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.2
|
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-10-
|
12
|
+
date: 2009-10-20 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -97,12 +97,16 @@ files:
|
|
97
97
|
- History.txt
|
98
98
|
- Manifest.txt
|
99
99
|
- README.markdown
|
100
|
+
- README_es.markdown
|
100
101
|
- init.rb
|
101
102
|
- lib/mundo_pepino.rb
|
103
|
+
- lib/mundo_pepino/definitions/en_US.rb
|
102
104
|
- lib/mundo_pepino/definitions/es_ES.rb
|
105
|
+
- lib/mundo_pepino/implementations.rb
|
103
106
|
- lib/mundo_pepino/resources_history.rb
|
104
107
|
- lib/mundo_pepino/version.rb
|
105
108
|
- lib/mundo_pepino/visits_history.rb
|
109
|
+
- lib/mundo_pepino_en_US.rb
|
106
110
|
- lib/mundo_pepino_es_ES.rb
|
107
111
|
- rails_generators/caracteristica/USAGE
|
108
112
|
- rails_generators/caracteristica/caracteristica_generator.rb
|