mundo-pepino 0.1.10 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +6 -0
- data/README_es.markdown +5 -4
- data/lib/mundo_pepino.rb +12 -4
- data/lib/mundo_pepino/config.rb +4 -5
- data/lib/mundo_pepino/en_US/mappings.rb +1 -1
- data/lib/mundo_pepino/es_ES/definitions.rb +62 -24
- data/lib/mundo_pepino/es_ES/mappings.rb +1 -1
- data/lib/mundo_pepino/es_ES/matchers.rb +7 -1
- data/lib/mundo_pepino/implementations.rb +10 -8
- data/lib/mundo_pepino/implementations_api.rb +69 -23
- data/lib/mundo_pepino/resources_history.rb +2 -2
- data/lib/mundo_pepino/version.rb +2 -2
- data/rails_generators/caracteristica/templates/caracteristica.erb +1 -0
- data/rails_generators/mundo_pepino/templates/mundo_pepino.rake +7 -5
- data/rails_generators/mundo_pepino/templates/mundo_pepino_es_ES.rb +1 -1
- data/rails_generators/mundo_pepino_steps/templates/mundo_pepino.rake +5 -4
- data/rails_generators/mundo_pepino_steps/templates/mundo_pepino_es_ES.rb +1 -1
- metadata +18 -8
data/History.txt
CHANGED
data/README_es.markdown
CHANGED
@@ -59,10 +59,10 @@ Para que MundoPepino sepa que cuando hablamos de *Huerto* nos estamos refiriendo
|
|
59
59
|
/^huertos?$/i => Orchard
|
60
60
|
}
|
61
61
|
config.field_mappings = { ... }
|
62
|
-
config.
|
62
|
+
config.page_mappings = { ... }
|
63
63
|
end
|
64
64
|
|
65
|
-
De forma similar se pueden definir mapeos para los atributos (*field_mappings*, p.e `/^usado$/i => :used`) y las rutas de la aplicación (*
|
65
|
+
De forma similar se pueden definir mapeos para los atributos (*field_mappings*, p.e `/^usado$/i => :used`) y las rutas de la aplicación (*page_mappings*, p.e. `/^la portada$/ => "/"`).
|
66
66
|
|
67
67
|
Del mapeo de atributos lo más destacable es la convención de que, si no se le indica lo contrario, el nombre del campo que guarda el *nombre* de cualquier modelo es **name**. Este mapeo nos permite escribir frases como `Dado que tengo un usuario llamado "Casimiro"` sin necesidad de hacer referencia al nombre del campo en el que debe guardarse *Casimiro*.
|
68
68
|
|
@@ -322,7 +322,7 @@ Convenciones generales:
|
|
322
322
|
Cuando adjunto el fichero "images/cucumber.jpg" en Fotografía actual
|
323
323
|
[más ejemplos](/nando/mundo-pepino/tree/master/features/es_ES/cuando-adjunto-el-fichero.feature)
|
324
324
|
#### Elijo una opción (*radiobutton*)
|
325
|
-
Cuando elijo
|
325
|
+
Cuando elijo "Tomates verdes"
|
326
326
|
[más ejemplos](/nando/mundo-pepino/tree/master/features/es_ES/cuando-elijo-de-radiobutton.feature)
|
327
327
|
#### Marco (o desmarco) una casilla (*checkbox*)
|
328
328
|
Cuando marco "color verde"
|
@@ -497,10 +497,11 @@ Como plugin (ver dependencias más abajo):
|
|
497
497
|
### Dependencias
|
498
498
|
Si instalamos la gema junto con ella deberían quedar instaladas todas sus dependencias.
|
499
499
|
|
500
|
-
Si instalamos mundo-pepino como plugin debemos tener instaladas las gemas o plugins de **cucumber**, **webrat**, **rspec** y **rspec-rails**. Por ejemplo, para instalar todas ellas como plugins:
|
500
|
+
Si instalamos mundo-pepino como plugin debemos tener instaladas las gemas o plugins de **cucumber**, **cucumber-rails**, **webrat**, **rspec** y **rspec-rails**. Por ejemplo, para instalar todas ellas como plugins:
|
501
501
|
|
502
502
|
gem install term-ansicolor treetop diff-lcs nokogiri # dependencias de Cucumber
|
503
503
|
script/plugin install git://github.com/aslakhellesoy/cucumber.git
|
504
|
+
script/plugin install git://github.com/aslakhellesoy/cucumber-rails.git
|
504
505
|
script/plugin install git://github.com/brynary/webrat.git
|
505
506
|
script/plugin install git://github.com/dchelimsky/rspec.git
|
506
507
|
script/plugin install git://github.com/dchelimsky/rspec-rails.git
|
data/lib/mundo_pepino.rb
CHANGED
@@ -59,8 +59,11 @@ module MundoPepino
|
|
59
59
|
end
|
60
60
|
end
|
61
61
|
String.add_mapper(:month) {|month| month.capitalize}
|
62
|
-
String.add_mapper(:url) {|str| str if str =~ /^\/.*$|^https?:\/\//i}
|
63
62
|
String.add_mapper(:real_value) {|value| value} # true, false...
|
63
|
+
String.add_mapper(:user_page)
|
64
|
+
String.add_mapper(:page) do |str|
|
65
|
+
str.to_user_page || (str =~ /^\/.*$|^https?:\/\//i ? str : nil)
|
66
|
+
end
|
64
67
|
end
|
65
68
|
|
66
69
|
def config
|
@@ -72,14 +75,19 @@ module MundoPepino
|
|
72
75
|
end
|
73
76
|
|
74
77
|
def clean_models
|
75
|
-
config.models_to_clean.each
|
76
|
-
|
78
|
+
config.models_to_clean.each do |model|
|
79
|
+
model.destroy_all
|
80
|
+
model.delete_all if model.count > 0
|
81
|
+
end
|
82
|
+
end
|
77
83
|
|
78
84
|
def user_specific_mappings
|
79
85
|
config.model_mappings.each {|k,v| String.model_mappings[k] = v}
|
80
86
|
config.relation_model_mappings.each {|k,v| String.relation_model_mappings[k] = v}
|
81
87
|
config.field_mappings.each {|k,v| String.field_mappings[k] = v}
|
82
|
-
|
88
|
+
# url_mappings are deprecated, use page_mappings instead
|
89
|
+
config.url_mappings.each {|k,v| String.user_page_mappings[k] = v}
|
90
|
+
config.page_mappings.each {|k,v| String.user_page_mappings[k] = v}
|
83
91
|
end
|
84
92
|
end
|
85
93
|
end
|
data/lib/mundo_pepino/config.rb
CHANGED
@@ -1,17 +1,16 @@
|
|
1
|
-
require 'ostruct'
|
2
|
-
|
3
1
|
module MundoPepino
|
4
2
|
class Config
|
5
3
|
attr_accessor :models_to_clean,
|
6
4
|
:model_mappings,
|
7
5
|
:field_mappings,
|
8
6
|
:relation_model_mappings,
|
9
|
-
:url_mappings
|
7
|
+
:url_mappings, # deprecated, use...
|
8
|
+
:page_mappings # page_mappings instead
|
10
9
|
|
11
10
|
def initialize(&block)
|
12
11
|
@models_to_clean = []
|
13
|
-
@model_mappings, @field_mappings,
|
14
|
-
|
12
|
+
@model_mappings, @field_mappings, @page_mappings = {}, {}, {}
|
13
|
+
@relation_model_mappings, @url_mappings = {}, {}
|
15
14
|
configure(&block) if block_given?
|
16
15
|
end
|
17
16
|
|
@@ -70,12 +70,13 @@ Cuando /^(?:que )?#{_visito_} (.+)$/i do |pagina|
|
|
70
70
|
end
|
71
71
|
|
72
72
|
Cuando /^(?:que )?#{_pulso_} (?:en )?el bot[oó]n (.+)$/i do |boton|
|
73
|
+
#TODO features/es_ES/cuando-adjunto-el-fichero.feature:22 # Capybara is case sensitive
|
73
74
|
click_button(boton.to_unquoted.to_translated)
|
74
75
|
end
|
75
76
|
|
76
77
|
Cuando /^(?:que )?#{_pulso_} (?:en )?(#{_el_enlace_}) (.+?)(?:#{_que_existe_} #{_dentro_de_} ['"]?(.+?)["']?)?$/i do |el_enlace, enlace, selector|
|
77
78
|
if selector.nil? and
|
78
|
-
href = (enlace.
|
79
|
+
href = (enlace.to_page || "#{el_enlace} #{enlace}".to_page)
|
79
80
|
Entonces "veo el enlace #{href}"
|
80
81
|
Y "visito #{href}"
|
81
82
|
else
|
@@ -100,47 +101,70 @@ Cuando /^(?:que )?#{_pulso_} (?:en )?los (?:siguientes )?(?:enlaces|botones)(?:
|
|
100
101
|
end
|
101
102
|
end
|
102
103
|
|
103
|
-
Cuando /^(?:que )
|
104
|
-
|
104
|
+
Cuando /^(?:que )?#{_relleno_} (?!#{_localizador_de_atributo_anidado_(false)})(.+) con (?:el valor )?['"](.+)["']$/i do |campo, valor|
|
105
|
+
find_field_and_do :fill_in, campo, :with => valor
|
105
106
|
end
|
106
107
|
|
107
|
-
Cuando /^(?:que )
|
108
|
+
Cuando /^(?:que )?#{_relleno_}(?: los(?: siguientes)? campos)?:$/i do |tabla|
|
108
109
|
tabla.raw[1..-1].each do |row|
|
109
110
|
Cuando "relleno \"#{row[0].gsub('"', '\"')}\" con \"#{row[1].gsub('"', '\"')}\""
|
110
111
|
end
|
111
112
|
end
|
112
113
|
|
113
|
-
Cuando /^(?:que )
|
114
|
+
Cuando /^(?:que )?#{_relleno_} #{_localizador_de_atributo_anidado_} con (?:el valor )?['"](.+)["']$/i do |campo, modelo, nombre, valor|
|
114
115
|
field_id = nested_field_id(last_mentioned, modelo, campo, nombre)
|
115
|
-
|
116
|
+
find_field_and_do :fill_in, field_id, :with => valor
|
116
117
|
end
|
117
118
|
|
118
|
-
Cuando /^(?:que )?elijo (
|
119
|
+
Cuando /^(?:que )?elijo (?:#{_como_}) ?(.+) ['"](.+)["']$/i do |campo, valor|
|
119
120
|
choose(convert_to_field(campo).to_s + '_' + valor.downcase.to_underscored)
|
120
121
|
end
|
121
122
|
|
122
|
-
Cuando /^(?:que )?
|
123
|
-
|
123
|
+
Cuando /^(?:que )?elijo (?!#{_como_} )(.+)$/i do |texto_de_label|
|
124
|
+
choose texto_de_label.to_unquoted
|
124
125
|
end
|
125
126
|
|
126
|
-
Cuando /^(?:que )?
|
127
|
-
|
127
|
+
Cuando /^(?:que )?marco (?:#{_como_})? ?(.+)$/i do |campo|
|
128
|
+
find_field_and_do :check, campo
|
129
|
+
end
|
130
|
+
|
131
|
+
Cuando /^(?:que )?desmarco (?:#{_como_})? ?(.+)$/i do |campo|
|
132
|
+
find_field_and_do :uncheck, campo
|
128
133
|
end
|
129
134
|
|
130
135
|
Cuando /^(?:que )?adjunto el fichero ['"](.*)["'] (?:a|en) (.*)$/ do |ruta, campo|
|
131
|
-
|
136
|
+
find_field_and_do :attach_file, campo,
|
132
137
|
{:path => ruta, :content_type => ruta.to_content_type}
|
133
138
|
end
|
134
139
|
|
135
140
|
Cuando /^(?:que )?selecciono ["']([^"']+?)["'](?: (?:en (?:el listado de )?|como )(?!#{_fecha_y_o_hora_})(.+))?$/i do |valor, campo|
|
136
141
|
begin
|
142
|
+
# TODO
|
143
|
+
# Y selecciono "Hortalizas" en el listado de "Tipos de cultivo" # lib/mundo_pepino/es_ES/definitions.rb:139
|
144
|
+
# En la página el label es -> "Tipo de cultivo"
|
137
145
|
if campo
|
138
|
-
select valor, :from => campo.to_unquoted.to_translated
|
146
|
+
select valor, :from => campo.to_unquoted.to_translated # Vía label
|
139
147
|
else
|
140
|
-
|
148
|
+
# TODO capybara always need a :from
|
149
|
+
#features/es_ES/cuando-selecciono-en-listado.feature:4 # Scenario: Selecciono una opción de una lista (*select*)
|
150
|
+
# Y selecciono "Hortalizas" debo pasar un string vacio por como capybara construye el objeto locator en concreto
|
151
|
+
# el uso de un función s(string) que sanitiza strings
|
152
|
+
if defined?(Webrat)
|
153
|
+
select valor
|
154
|
+
else
|
155
|
+
select valor, :from => ""
|
156
|
+
end
|
157
|
+
end
|
158
|
+
rescue StandardError => e
|
159
|
+
if (defined?(Webrat) && e.is_a?(Webrat::NotFoundError)) || (defined?(Capybara) && e.is_a?(Capybara::ElementNotFound))
|
160
|
+
begin
|
161
|
+
previous_exception = $!
|
162
|
+
# TODO added to_s to capybara pass the steps
|
163
|
+
select(valor, :from => convert_to_field(campo).to_s) # Sin label
|
164
|
+
rescue
|
165
|
+
raise "#{previous_exception}\nand\n#{$!}"
|
166
|
+
end
|
141
167
|
end
|
142
|
-
rescue Webrat::NotFoundError
|
143
|
-
select(valor, :from => convert_to_field(campo)) # Sin label
|
144
168
|
end
|
145
169
|
end
|
146
170
|
|
@@ -183,7 +207,7 @@ Entonces /^(#{_leo_o_no_}) el texto (.+)?$/i do |should, text|
|
|
183
207
|
begin
|
184
208
|
HTML::FullSanitizer.new.sanitize(response.body).send(shouldify(should)) =~ /#{Regexp.escape(text.to_unquoted.to_translated)}/m
|
185
209
|
rescue Spec::Expectations::ExpectationNotMetError
|
186
|
-
webrat.save_and_open_page
|
210
|
+
defined?(Webrat) ? webrat.save_and_open_page : save_and_open_page
|
187
211
|
raise
|
188
212
|
end
|
189
213
|
end
|
@@ -202,8 +226,13 @@ end
|
|
202
226
|
|
203
227
|
Entonces /^(#{_veo_o_no_}) #{_la_etiqueta_} (["'].+?['"]|[^ ]+)(?:(?: con)? el (?:valor|texto) )?["']?([^"']+)?["']?$/ do |should, tag, value |
|
204
228
|
lambda {
|
229
|
+
# TODO tag in upcase must not be used
|
230
|
+
# features/es_ES/veo-etiqueta-con-valor.feature:4
|
231
|
+
tag = tag.downcase # Capybara is casesensitive
|
232
|
+
# For capybara page.should have_css(tag.to_unquoted, :text => /.*#{Regexp.escape(value.to_translated)}.*/i)
|
233
|
+
|
205
234
|
if value
|
206
|
-
response.should have_tag(tag.to_unquoted, /.*#{value.to_translated}.*/i)
|
235
|
+
response.should have_tag(tag.to_unquoted, /.*#{Regexp.escape(value.to_translated)}.*/i)
|
207
236
|
else
|
208
237
|
response.should have_tag(tag.to_unquoted)
|
209
238
|
end
|
@@ -223,7 +252,10 @@ end
|
|
223
252
|
|
224
253
|
Entonces /^(#{_veo_o_no_}) (?:un|el) enlace (?:al? |para )?(.+)?$/i do |should, pagina|
|
225
254
|
lambda {
|
226
|
-
|
255
|
+
# TODO
|
256
|
+
# In webrat response.should have_tag('a[href=?]', pagina.to_unquoted.to_page)
|
257
|
+
# For capybara page.should page.should have_css("a[href='#{pagina.to_unquoted.to_page}']")
|
258
|
+
response.should have_tag("a[href='#{pagina.to_unquoted.to_page}']")
|
227
259
|
}.send(not_shouldify(should), raise_error)
|
228
260
|
end
|
229
261
|
|
@@ -233,12 +265,18 @@ Entonces /^(#{_veo_o_no_}) el campo (.+) con(?: el (?:valor|texto))? ['"]?(.+?)[
|
|
233
265
|
end
|
234
266
|
|
235
267
|
Entonces /^(#{_veo_o_no_}) marcad[ao] (?:la casilla|el checkbox)? ?(.+)$/ do |should, campo|
|
236
|
-
|
268
|
+
# TODO
|
269
|
+
if defined?(Webrat)
|
270
|
+
field_labeled(campo.to_unquoted).send shouldify(should), be_checked
|
271
|
+
else
|
272
|
+
has_checked_field?(campo.to_unquoted).send shouldify(should), be_true
|
273
|
+
end
|
237
274
|
end
|
238
275
|
|
239
276
|
Entonces /^(#{_veo_o_no_}) (?:una|la) tabla (?:(["'].+?['"]|[^ ]+) )?con (?:el|los) (?:siguientes? )?(?:valore?s?|contenidos?):$/ do |should, table_id, valores|
|
240
277
|
table_id = "##{table_id.to_unquoted}" if table_id
|
241
278
|
shouldified = shouldify(should)
|
279
|
+
#TODO For capybara page instead response and have_css instead have_selector
|
242
280
|
response.send shouldified, have_selector("table#{table_id}")
|
243
281
|
|
244
282
|
if have_selector("table#{table_id} tbody").matches?(response)
|
@@ -251,7 +289,7 @@ Entonces /^(#{_veo_o_no_}) (?:una|la) tabla (?:(["'].+?['"]|[^ ]+) )?con (?:el|l
|
|
251
289
|
|
252
290
|
valores.raw[1..-1].each_with_index do |row, i|
|
253
291
|
row.each_with_index do |cell, j|
|
254
|
-
response.send shouldified,
|
292
|
+
response.send shouldified,
|
255
293
|
have_selector("table#{table_id} #{tbody} tr:nth-child(#{i+start_row})>td:nth-child(#{j+1})") { |td|
|
256
294
|
td.inner_text.should =~ /#{cell == '.*' ? cell : Regexp.escape((cell||"").to_translated)}/
|
257
295
|
}
|
@@ -271,10 +309,10 @@ Entonces /^(#{_veo_o_no_}) un formulario con (?:el|los) (?:siguientes? )?(?:camp
|
|
271
309
|
with_tag('div') do
|
272
310
|
with_tag "label", label
|
273
311
|
with_tag "input[type='radio']"
|
274
|
-
end
|
312
|
+
end
|
275
313
|
when "select", "textarea":
|
276
314
|
field_labeled(label).element.name.should == type
|
277
|
-
else
|
315
|
+
else
|
278
316
|
field_labeled(label).element.attributes['type'].to_s.should == type
|
279
317
|
end
|
280
318
|
end
|
@@ -322,5 +360,5 @@ Entonces /^#{_tiene_en_bbdd_} (#{_numero_}) ['"]?([^"']+)["']?$/ do |numero, hij
|
|
322
360
|
end
|
323
361
|
|
324
362
|
Entonces /^#{_debo_estar_en_} (.+)$/i do |pagina|
|
325
|
-
URI.parse(current_url).path.should == pagina.to_unquoted.
|
363
|
+
URI.parse(current_url).path.should == pagina.to_unquoted.to_page
|
326
364
|
end
|
@@ -47,7 +47,7 @@ module MundoPepino
|
|
47
47
|
:noviembre => 'November',
|
48
48
|
:diciembre => 'December'
|
49
49
|
}
|
50
|
-
String.
|
50
|
+
String.page_mappings.merge!({
|
51
51
|
/^la (?:portada|home\s?(?:page)?)$/i => lambda{MundoPepino.world.root_path},
|
52
52
|
/^(#{_el_listado_de_}) ([\w]+|['"][\w ]+["'])$/i =>
|
53
53
|
lambda{ |el_listado_de, modelo|
|
@@ -42,7 +42,7 @@ module MundoPepino
|
|
42
42
|
end
|
43
43
|
def _localizador_de_atributo_anidado_(capture=true)
|
44
44
|
o,c = capture ? ['(', ')'] : ['', '']
|
45
|
-
"(?:(?:el|la) )?#{o}
|
45
|
+
"(?:(?:el|la) )?#{o}[^\"']+?#{c} de(?:l| la| su nuev[oa]) #{o}.+?#{c}(?: ['\"]#{o}[^\"']+#{c}[\"'])?"
|
46
46
|
end
|
47
47
|
def _dentro_de_
|
48
48
|
'dentro de(?: la etiqueta|l selector)?'
|
@@ -56,6 +56,12 @@ module MundoPepino
|
|
56
56
|
def _la_etiqueta_
|
57
57
|
'(?:en )?(?:(?:una?|el|la) (?:selector|etiqueta|tag))'
|
58
58
|
end
|
59
|
+
def _como_
|
60
|
+
'la|el|como'
|
61
|
+
end
|
62
|
+
def _relleno_
|
63
|
+
'(?:completo|relleno)'
|
64
|
+
end
|
59
65
|
end
|
60
66
|
end
|
61
67
|
end
|
@@ -74,22 +74,24 @@ module MundoPepino
|
|
74
74
|
end
|
75
75
|
|
76
76
|
def given_or_when_i_do_a_page_request(params)
|
77
|
-
do_visit params[:page].to_unquoted.
|
77
|
+
do_visit params[:page].to_unquoted.to_page
|
78
78
|
end
|
79
79
|
|
80
80
|
def given_or_when_i_follow_the_link(params)
|
81
|
-
if params[:selector]
|
82
|
-
click_link_within params[:selector], params[:link]
|
83
|
-
else
|
81
|
+
if params[:selector].blank?
|
84
82
|
click_link params[:link]
|
83
|
+
else
|
84
|
+
click_link_within params[:selector], params[:link]
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
88
88
|
def then_i_see_or_not_the_text(params)
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
89
|
+
if params[:selector].blank?
|
90
|
+
should_or_not_contain_text params
|
91
|
+
else
|
92
|
+
within params[:selector] do
|
93
|
+
should_or_not_contain_text params
|
94
|
+
end
|
93
95
|
end
|
94
96
|
end
|
95
97
|
|
@@ -22,13 +22,13 @@ module MundoPepino
|
|
22
22
|
[base_hash] * number
|
23
23
|
end
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
def field_for(model=nil, field = nil)
|
27
27
|
model_name = "#{model && model.name+'::'}"
|
28
28
|
if field
|
29
29
|
"#{model_name}#{field}".to_field || field.to_field
|
30
30
|
else
|
31
|
-
"#{model_name}name".to_field || 'name'.to_field ||
|
31
|
+
"#{model_name}name".to_field || 'name'.to_field ||
|
32
32
|
# The use of "nombre" the name field mapping is deprecated
|
33
33
|
"#{model_name}nombre".to_field || 'nombre'.to_field || :name
|
34
34
|
end
|
@@ -37,16 +37,16 @@ module MundoPepino
|
|
37
37
|
def shouldify(should_or_not)
|
38
38
|
should_or_not =~ /^(#{MundoPepino::Matchers::Bites._should_})$/i ? :should : :should_not
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
def not_shouldify(should_or_not)
|
42
42
|
shouldify(should_or_not) == :should ? :should_not : :should
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
# Cucumber::Model::Table's hashes traduciendo nombres de campo
|
46
46
|
def translated_hashes(step_table, options = {})
|
47
47
|
base_hash = base_hash_for(options)
|
48
|
-
header = step_table[0].map do |raw_field|
|
49
|
-
field_for(options[:model], raw_field) || raw_field
|
48
|
+
header = step_table[0].map do |raw_field|
|
49
|
+
field_for(options[:model], raw_field) || raw_field
|
50
50
|
end
|
51
51
|
step_table[1..-1].map do |row|
|
52
52
|
h = base_hash.dup
|
@@ -57,14 +57,14 @@ module MundoPepino
|
|
57
57
|
h
|
58
58
|
end
|
59
59
|
end
|
60
|
-
|
61
|
-
def base_hash_for(options)
|
60
|
+
|
61
|
+
def base_hash_for(options)
|
62
62
|
if options[:parent]
|
63
63
|
# polymorphic associations
|
64
64
|
if options[:polymorphic_as]
|
65
65
|
{ "#{options[:polymorphic_as]}_id" => options[:parent].id,
|
66
66
|
"#{options[:polymorphic_as]}_type" => options[:parent].class.name }
|
67
|
-
else
|
67
|
+
else
|
68
68
|
field_prefix = options[:parent_field] || options[:parent].class.name.underscore
|
69
69
|
if options[:through]
|
70
70
|
{:through => {"model" => eval(options[:through].to_s.classify),
|
@@ -77,21 +77,21 @@ module MundoPepino
|
|
77
77
|
{}
|
78
78
|
end
|
79
79
|
end
|
80
|
-
|
80
|
+
|
81
81
|
def convert_to_model(raw_model)
|
82
82
|
raw_model.to_unquoted.to_model || raise(ModelNotMapped.new(raw_model))
|
83
83
|
end
|
84
84
|
|
85
85
|
def convert_to_field(raw_field, model = nil)
|
86
|
-
unless raw_field.nil?
|
86
|
+
unless raw_field.nil?
|
87
87
|
if field = field_for(model, raw_field.to_unquoted)
|
88
88
|
field
|
89
89
|
else
|
90
|
-
raise MundoPepino::FieldNotMapped.new(raw_field)
|
90
|
+
raise MundoPepino::FieldNotMapped.new(raw_field)
|
91
91
|
end
|
92
92
|
end
|
93
93
|
end
|
94
|
-
|
94
|
+
|
95
95
|
def last_mentioned_children(field_raw)
|
96
96
|
if child_model = field_raw.to_model
|
97
97
|
parent_model = last_mentioned.mr_model
|
@@ -107,7 +107,7 @@ module MundoPepino
|
|
107
107
|
def last_mentioned_should_have_n_children(field, number)
|
108
108
|
last_mentioned_children(field).size.should == number.to_number
|
109
109
|
end
|
110
|
-
|
110
|
+
|
111
111
|
def last_mentioned_should_have_value(raw_field, valor)
|
112
112
|
res = last_mentioned
|
113
113
|
if child_model = raw_field.to_model
|
@@ -120,21 +120,57 @@ module MundoPepino
|
|
120
120
|
raise MundoPepino::FieldNotMapped.new(raw_field)
|
121
121
|
end
|
122
122
|
end
|
123
|
-
|
123
|
+
|
124
124
|
def last_mentioned_should_have_child(field_raw, name)
|
125
125
|
children = last_mentioned_children(field_raw)
|
126
126
|
child = if children.any?
|
127
127
|
model = children.first.class
|
128
|
-
model.send("find_by_#{field_for(model)}", name)
|
128
|
+
model.send("find_by_#{field_for(model)}", name)
|
129
129
|
end
|
130
130
|
children.detect {|c| c.id == child.id}.should_not be_nil
|
131
131
|
end
|
132
|
-
|
132
|
+
|
133
|
+
def find_field_and_do(action, raw_field, options = nil)
|
134
|
+
if defined?(Webrat)
|
135
|
+
# Webrat
|
136
|
+
find_field_and_do_with_webrat(action, raw_field, options)
|
137
|
+
else
|
138
|
+
# Capybara
|
139
|
+
find_field_and_do_with_capybara(action, raw_field, options)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def find_field_and_do_with_capybara(action, raw_field, options = nil)
|
144
|
+
do_with_capybara action, raw_field.to_unquoted.to_translated, options # a pelo (localización vía labels)
|
145
|
+
rescue Capybara::ElementNotFound
|
146
|
+
field = convert_to_field(raw_field, last_mentioned_model)
|
147
|
+
begin
|
148
|
+
do_with_capybara action, field.to_s, options # campo traducido tal cual...
|
149
|
+
rescue Capybara::ElementNotFound
|
150
|
+
#TODO cucumber -p capybara_es_ES features/es_ES/tenemos-en-bbdd-registros.feature:50 # Scenario: dos campos has_many del mismo modelo
|
151
|
+
# se busca un campo "name" tenemos "for=session_name" y el texto del label es 'Name' capybara es casesensitive
|
152
|
+
raise $! if field.to_s.capitalize == field.to_s
|
153
|
+
do_with_capybara action, field.to_s.capitalize, options
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
def do_with_capybara(action, field, options)
|
158
|
+
if options
|
159
|
+
if options[:path] # and options[:content_type]
|
160
|
+
self.send action, field, options[:path]#, options[:content_type]
|
161
|
+
else
|
162
|
+
self.send action, field, options
|
163
|
+
end
|
164
|
+
else
|
165
|
+
self.send action, field
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
133
169
|
def find_field_and_do_with_webrat(action, raw_field, options = nil)
|
134
170
|
do_with_webrat action, raw_field.to_unquoted.to_translated, options # a pelo (localización vía labels)
|
135
171
|
rescue Webrat::NotFoundError
|
136
172
|
field = convert_to_field(raw_field, last_mentioned_model)
|
137
|
-
begin
|
173
|
+
begin
|
138
174
|
do_with_webrat action, field, options # campo traducido tal cual...
|
139
175
|
rescue Webrat::NotFoundError
|
140
176
|
if singular = last_mentioned_singular # traducido y con el modelo por delante
|
@@ -144,7 +180,7 @@ module MundoPepino
|
|
144
180
|
end
|
145
181
|
end
|
146
182
|
end
|
147
|
-
|
183
|
+
|
148
184
|
def do_with_webrat(action, field, options)
|
149
185
|
if options
|
150
186
|
if options[:path] and options[:content_type]
|
@@ -156,10 +192,10 @@ module MundoPepino
|
|
156
192
|
self.send action, field
|
157
193
|
end
|
158
194
|
end
|
159
|
-
|
195
|
+
|
160
196
|
def parent_options(parent, child_model, child_field)
|
161
197
|
options = {:parent => parent}
|
162
|
-
if child_field and
|
198
|
+
if child_field and
|
163
199
|
parent_field = "#{child_model.name}::#{child_field}".to_field
|
164
200
|
options[:parent_field] = parent_field
|
165
201
|
elsif reflections = parent.class.reflect_on_association(child_model.table_name.to_sym)
|
@@ -178,7 +214,7 @@ module MundoPepino
|
|
178
214
|
if model = unquoted_model.to_model
|
179
215
|
pile_up model.new
|
180
216
|
MundoPepino.world.send "#{model.table_name}_path"
|
181
|
-
elsif url = "#{the_page_of} #{raw_model}".
|
217
|
+
elsif url = "#{the_page_of} #{raw_model}".to_user_page
|
182
218
|
url
|
183
219
|
else
|
184
220
|
raise MundoPepino::ModelNotMapped.new(unquoted_model)
|
@@ -210,6 +246,7 @@ module MundoPepino
|
|
210
246
|
|
211
247
|
def nested_field_id_prefix(parent_resource, resource)
|
212
248
|
preprefix = nested_field_prefix_prefix(parent_resource.mr_model, resource.class)
|
249
|
+
# We can use response with capybara due to capextensions
|
213
250
|
Nokogiri::HTML.parse(response.body).xpath(
|
214
251
|
"//input[@type='hidden' and @value=#{resource.id}]"
|
215
252
|
).each do |input|
|
@@ -220,15 +257,24 @@ module MundoPepino
|
|
220
257
|
def new_nested_field_id(parent_resource, model, field)
|
221
258
|
preprefix = nested_field_prefix_prefix(parent_resource.mr_model, model)
|
222
259
|
(0..MAX_NESTED_RESOURCES).each do |index|
|
260
|
+
# We can use response with capybara due to capextensions
|
223
261
|
if Nokogiri::HTML.parse(response.body).css("##{preprefix}_#{index}_id").empty?
|
224
262
|
return "#{preprefix}_#{index}_#{field}"
|
225
263
|
end
|
226
264
|
end
|
227
265
|
# TODO: raise too many nested resources
|
228
266
|
end
|
267
|
+
|
229
268
|
def nested_field_prefix_prefix(parent_model, child_model)
|
230
269
|
"#{parent_model.name.underscore}_#{child_model.name.pluralize.underscore}_attributes"
|
231
270
|
end
|
232
|
-
|
271
|
+
|
272
|
+
def should_or_not_contain_text(params)
|
273
|
+
# We can use response and contain with capybara due to capextensions
|
274
|
+
response.send(
|
275
|
+
shouldify(params[:should]),
|
276
|
+
contain(params[:text].to_unquoted.to_translated.to_regexp))
|
277
|
+
end
|
278
|
+
end
|
233
279
|
end
|
234
280
|
|
@@ -42,8 +42,8 @@ module MundoPepino
|
|
42
42
|
def add_resource_from_database(raw_model, name)
|
43
43
|
model = convert_to_model(raw_model)
|
44
44
|
field = field_for(model)
|
45
|
-
if resource = model.send("find_by_#{field}", name)
|
46
|
-
pile_up resource
|
45
|
+
if resource = model.send("find_by_#{field}", name, :select => :id)
|
46
|
+
pile_up model.find(resource.id)
|
47
47
|
else
|
48
48
|
raise NotFoundInDatabase.new(model, name)
|
49
49
|
end
|
data/lib/mundo_pepino/version.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
$:.unshift(RAILS_ROOT + '/vendor/plugins/cucumber/lib')
|
2
|
-
|
2
|
+
$:.unshift(RAILS_ROOT + '/vendor/plugins/mundo-pepino/lib')
|
3
|
+
gem 'cucumber', '>= 0.6.2'
|
3
4
|
require 'cucumber/rake/task'
|
4
5
|
|
5
|
-
Cucumber::Rake::Task.new(:caracteristicas) do |t|
|
6
|
-
t.
|
7
|
-
|
8
|
-
|
6
|
+
Cucumber::Rake::Task.new({:caracteristicas => 'db:test:prepare'}) do |t|
|
7
|
+
t.fork = true # You may get faster startup if you set this to false
|
8
|
+
t.profile = 'default'
|
9
|
+
#t.cucumber_opts = "--format pretty"
|
10
|
+
end
|
@@ -1,9 +1,10 @@
|
|
1
1
|
$:.unshift(RAILS_ROOT + '/vendor/plugins/cucumber/lib')
|
2
2
|
$:.unshift(RAILS_ROOT + '/vendor/plugins/mundo-pepino/lib')
|
3
|
-
gem 'cucumber', '
|
3
|
+
gem 'cucumber', '>= 0.6.2'
|
4
4
|
require 'cucumber/rake/task'
|
5
5
|
|
6
|
-
Cucumber::Rake::Task.new(:caracteristicas) do |t|
|
7
|
-
t.
|
6
|
+
Cucumber::Rake::Task.new({:caracteristicas => 'db:test:prepare'}) do |t|
|
7
|
+
t.fork = true # You may get faster startup if you set this to false
|
8
|
+
t.profile = 'default'
|
9
|
+
#t.cucumber_opts = "--format pretty"
|
8
10
|
end
|
9
|
-
task :caracteristicas => 'db:test:prepare'
|
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.
|
4
|
+
version: 0.2.0
|
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: 2010-
|
12
|
+
date: 2010-03-05 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -28,9 +28,19 @@ dependencies:
|
|
28
28
|
version_requirement:
|
29
29
|
version_requirements: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.6.2
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: cucumber-rails
|
37
|
+
type: :runtime
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
32
42
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.
|
43
|
+
version: 0.3.0
|
34
44
|
version:
|
35
45
|
- !ruby/object:Gem::Dependency
|
36
46
|
name: webrat
|
@@ -40,7 +50,7 @@ dependencies:
|
|
40
50
|
requirements:
|
41
51
|
- - ">="
|
42
52
|
- !ruby/object:Gem::Version
|
43
|
-
version: 0.
|
53
|
+
version: 0.7.0
|
44
54
|
version:
|
45
55
|
- !ruby/object:Gem::Dependency
|
46
56
|
name: rspec
|
@@ -50,7 +60,7 @@ dependencies:
|
|
50
60
|
requirements:
|
51
61
|
- - ">="
|
52
62
|
- !ruby/object:Gem::Version
|
53
|
-
version: 1.
|
63
|
+
version: 1.3.0
|
54
64
|
version:
|
55
65
|
- !ruby/object:Gem::Dependency
|
56
66
|
name: rspec-rails
|
@@ -60,7 +70,7 @@ dependencies:
|
|
60
70
|
requirements:
|
61
71
|
- - ">="
|
62
72
|
- !ruby/object:Gem::Version
|
63
|
-
version: 1.
|
73
|
+
version: 1.3.0
|
64
74
|
version:
|
65
75
|
- !ruby/object:Gem::Dependency
|
66
76
|
name: nokogiri
|
@@ -70,7 +80,7 @@ dependencies:
|
|
70
80
|
requirements:
|
71
81
|
- - ">="
|
72
82
|
- !ruby/object:Gem::Version
|
73
|
-
version: 1.
|
83
|
+
version: 1.4.1
|
74
84
|
version:
|
75
85
|
- !ruby/object:Gem::Dependency
|
76
86
|
name: string-mapper
|