mundo-pepino 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,13 @@
1
+ # encoding: UTF-8
2
+ == 0.2.2 2010-5-17
3
+ * Two new 'es_ES' steps courtesy of Paco Guzmán:
4
+ * Set values of an existing resource using a step table. More info at
5
+ features/es_ES/contexto-asignacion-de-valores-en-recurso-desde-fit-table.feature
6
+ * Check if something is "readable" in the current page (content without
7
+ markup). For example "Entonces veo el texto 'texto con marcado'"
8
+ * One bugfix: user page mappings over MundoPepino Page Interpretation TM.
9
+ * Other minor bugfixes.
10
+
1
11
  == 0.2.1 2010-4-16
2
12
  * Two minor changes:
3
13
  * Capybara extensions automagically loaded if Capybara is present
@@ -60,7 +60,7 @@ module MundoPepino
60
60
  String.add_mapper(:translated) do |str|
61
61
  if str =~ /^[a-z_]+\.[a-z_]+[a-z_\.]+$/
62
62
  I18n.translate(str, :default => str)
63
- elsif str =~ /^([a-z_]+\.[a-z_]+[a-z_\.]+),(\{.+\})$/
63
+ elsif str =~ /^([a-z_]+\.[a-z_]+[a-z_\.]+),(?: )?(\{.+\})$/
64
64
  I18n.translate($1, {:default => str}.merge(eval($2)))
65
65
  else
66
66
  str
@@ -68,9 +68,9 @@ module MundoPepino
68
68
  end
69
69
  String.add_mapper(:month) {|month| month.capitalize}
70
70
  String.add_mapper(:real_value) {|value| value} # true, false...
71
- String.add_mapper(:user_page)
71
+ String.add_mapper(:automagical_page)
72
72
  String.add_mapper(:page) do |str|
73
- str.to_user_page || (str =~ /^\/.*$|^https?:\/\//i ? str : nil)
73
+ str.to_automagical_page || (str =~ /^\/.*$|^https?:\/\//i ? str : nil)
74
74
  end
75
75
  end
76
76
 
@@ -94,8 +94,8 @@ module MundoPepino
94
94
  config.relation_model_mappings.each {|k,v| String.relation_model_mappings[k] = v}
95
95
  config.field_mappings.each {|k,v| String.field_mappings[k] = v}
96
96
  # url_mappings are deprecated, use page_mappings instead
97
- config.url_mappings.each {|k,v| String.user_page_mappings[k] = v}
98
- config.page_mappings.each {|k,v| String.user_page_mappings[k] = v}
97
+ config.url_mappings.each {|k,v| String.page_mappings[k] = v}
98
+ config.page_mappings.each {|k,v| String.page_mappings[k] = v}
99
99
  end
100
100
  end
101
101
  end
@@ -41,9 +41,9 @@ module Capextensions
41
41
 
42
42
  id_prefix ||= options[:id_prefix]
43
43
 
44
- select date.year, :from => "#{id_prefix}_#{DATE_TIME_SUFFIXES[:year]}"
44
+ select date.year.to_s, :from => "#{id_prefix}_#{DATE_TIME_SUFFIXES[:year]}"
45
45
  select date.strftime('%B'), :from => "#{id_prefix}_#{DATE_TIME_SUFFIXES[:month]}"
46
- select date.day, :from => "#{id_prefix}_#{DATE_TIME_SUFFIXES[:day]}"
46
+ select date.day.to_s, :from => "#{id_prefix}_#{DATE_TIME_SUFFIXES[:day]}"
47
47
  end
48
48
 
49
49
  def select_time(time_to_select, options ={})
@@ -127,4 +127,11 @@ module Capextensions
127
127
  end
128
128
  end
129
129
 
130
- World(Capextensions)
130
+ World(Capextensions)
131
+
132
+ module WithinHelpers
133
+ def with_scope(locator)
134
+ locator ? within(locator) { yield } : yield
135
+ end
136
+ end
137
+ World(WithinHelpers)
@@ -19,18 +19,26 @@ Dado /^(?:que tenemos )?(?:el|la|los|las|el\/la|los\/las) (?:siguientes? )?(.+):
19
19
  end
20
20
 
21
21
  Dado /^que (?:el|la) (.+) ['"](.+)["'] tiene como (.+) ['"](.+)["'](?: \w+)?$/ do |modelo, nombre, campo, valor|
22
- given_resource_has_value_in_field :model => modelo,
22
+ given_those_resources_have_value_in_field :model => modelo,
23
23
  :name => nombre,
24
24
  :field => campo,
25
25
  :value => valor
26
26
  end
27
27
 
28
+ Dado /^que (?:el|la) (.+) ['"](.+)["'] tiene:$/ do |modelo, nombre, tabla|
29
+ given_resource_have_the_following_values_from_step_table :model => modelo, :name => nombre, :table => tabla
30
+ end
31
+
28
32
  Dado /^que dich[oa]s? (.+) tienen? como (.+) ['"](.+)["'](?:.+)?$/i do |modelo, campo, valor|
29
33
  given_those_resources_have_value_in_field :model => modelo,
30
34
  :field => campo,
31
35
  :value => valor
32
36
  end
33
37
 
38
+ Dado /^que(?: dich[oa]s? (.+))? tiene:$/i do |modelo, tabla|
39
+ given_resource_have_the_following_values_from_step_table :model => modelo, :table => tabla
40
+ end
41
+
34
42
  Dado /^que (?:el|la) (.+) ['"](.+)["'] tiene (#{_numero_}) (.+?)(?: (?:llamad[oa]s? )?['"](.+)["'])?$/i do |modelo_padre, nombre_del_padre, numero, campo_hijos, nombres|
35
43
  given_resource_has_many_children(
36
44
  :model => modelo_padre,
@@ -122,7 +130,7 @@ Cuando /^(?:que )?elijo (?:#{_como_}) ?(.+) ['"](.+)["']$/i do |campo, valor|
122
130
  end
123
131
 
124
132
  Cuando /^(?:que )?elijo (?!#{_como_} )(.+)$/i do |texto_de_label|
125
- choose texto_de_label.to_unquoted
133
+ choose texto_de_label.to_unquoted.to_translated
126
134
  end
127
135
 
128
136
  Cuando /^(?:que )?marco (?:#{_como_})? ?(.+)$/i do |campo|
@@ -140,16 +148,12 @@ end
140
148
 
141
149
  Cuando /^(?:que )?selecciono ["']([^"']+?)["'](?: (?:en (?:el listado de )?|como )(?!#{_fecha_y_o_hora_})(.+))?$/i do |valor, campo|
142
150
  begin
143
- # TODO
144
- # Y selecciono "Hortalizas" en el listado de "Tipos de cultivo" # lib/mundo_pepino/es_ES/definitions.rb:139
145
- # En la página el label es -> "Tipo de cultivo"
151
+ valor = valor.to_unquoted.to_translated
146
152
  if campo
147
- select valor, :from => campo.to_unquoted.to_translated # Vía label
153
+ campo = campo.to_unquoted.to_translated
154
+ select valor, :from => campo # Vía label
148
155
  else
149
- # TODO capybara always need a :from
150
- #features/es_ES/cuando-selecciono-en-listado.feature:4 # Scenario: Selecciono una opción de una lista (*select*)
151
- # Y selecciono "Hortalizas" debo pasar un string vacio por como capybara construye el objeto locator en concreto
152
- # el uso de un función s(string) que sanitiza strings
156
+ # capybara always need a :from
153
157
  if defined?(Webrat)
154
158
  select valor
155
159
  else
@@ -160,7 +164,6 @@ Cuando /^(?:que )?selecciono ["']([^"']+?)["'](?: (?:en (?:el listado de )?|como
160
164
  if (defined?(Webrat) && e.is_a?(Webrat::NotFoundError)) || (defined?(Capybara) && e.is_a?(Capybara::ElementNotFound))
161
165
  begin
162
166
  previous_exception = $!
163
- # TODO added to_s to capybara pass the steps
164
167
  select(valor, :from => convert_to_field(campo).to_s) # Sin label
165
168
  rescue
166
169
  raise "#{previous_exception}\nand\n#{$!}"
@@ -213,9 +216,13 @@ Entonces /^(#{_leo_o_no_}) el texto (.+)?$/i do |should, text|
213
216
  end
214
217
  end
215
218
 
216
- Entonces /^(#{_veo_o_no_}) los siguientes textos:$/i do |should, texts|
219
+ Entonces /^(#{_veo_o_no_}) los siguientes textos(?: #{_dentro_de_} ['"]?(.+?)["']?)?:$/i do |should, selector, texts|
217
220
  texts.raw.each do |row|
218
- Entonces "#{should} el texto #{row[0]}"
221
+ if selector
222
+ Entonces "#{should} el texto #{row[0]} dentro del selector #{selector}"
223
+ else
224
+ Entonces "#{should} el texto #{row[0]}"
225
+ end
219
226
  end
220
227
  end
221
228
 
@@ -225,15 +232,14 @@ Entonces /^(#{_leo_o_no_}) los siguientes textos:$/i do |should, texts|
225
232
  end
226
233
  end
227
234
 
228
- Entonces /^(#{_veo_o_no_}) #{_la_etiqueta_} (["'].+?['"]|[^ ]+)(?:(?: con)? el (?:valor|texto) )?["']?([^"']+)?["']?$/ do |should, tag, value |
235
+ Entonces /^(#{_veo_o_no_}) #{_la_etiqueta_} (["'].+?['"]|[^ ]+)(?:(?: con)? el (?:valor|texto) )?(.+)?$/ do |should, tag, value |
229
236
  lambda {
230
237
  # TODO tag in upcase must not be used
231
238
  # features/es_ES/veo-etiqueta-con-valor.feature:4
232
239
  tag = tag.downcase # Capybara is casesensitive
233
240
  # For capybara page.should have_css(tag.to_unquoted, :text => /.*#{Regexp.escape(value.to_translated)}.*/i)
234
-
235
241
  if value
236
- response.should have_tag(tag.to_unquoted, /.*#{Regexp.escape(value.to_translated)}.*/i)
242
+ response.should have_tag(tag.to_unquoted, /.*#{Regexp.escape(value.to_unquoted.to_translated)}.*/i)
237
243
  else
238
244
  response.should have_tag(tag.to_unquoted)
239
245
  end
@@ -48,7 +48,7 @@ module MundoPepino
48
48
  :noviembre => 'November',
49
49
  :diciembre => 'December'
50
50
  }
51
- String.page_mappings.merge!({
51
+ String.automagical_page_mappings.merge!({
52
52
  /^la (?:portada|home\s?(?:page)?)$/i => lambda{MundoPepino.world.root_path},
53
53
  /^(#{_el_listado_de_}) ([\w]+|['"][\w ]+["'])$/i =>
54
54
  lambda{ |el_listado_de, modelo|
@@ -84,7 +84,9 @@ module MundoPepino
84
84
  end
85
85
  else
86
86
  model = modelo.to_unquoted.to_model or raise(MundoPepino::ModelNotMapped.new(modelo))
87
- MundoPepino.world.pile_up model.new
87
+ if dummy_instance = model.new rescue nil
88
+ MundoPepino.world.pile_up dummy_instance
89
+ end
88
90
  MundoPepino.world.send "#{action}_#{model.name.underscore}_path"
89
91
  end
90
92
  },
@@ -22,34 +22,42 @@ module MundoPepino
22
22
 
23
23
  # Params:
24
24
  # :model
25
- # :name
26
25
  # :field
27
26
  # :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
27
+ # :name (optional)
28
+ def given_those_resources_have_value_in_field(params)
29
+ if res = params[:name] ? [last_mentioned_of(params[:model], params[:name])] : last_mentioned_of(params[:model])
30
+
31
+ if resource_not_respond_to_field?(res, params[:field]) && !resource_respond_to_relation_field?(res, params[:field])
32
+ params.merge!(:children_field => params[:field], :children_names => params[:value])
33
+ given_resource_has_many_children(params)
33
34
  else
34
- raise MundoPepino::FieldNotMapped.new(params[:field])
35
+ resources, field, values = resources_array_field_and_values(res, params[:field], params[:value])
36
+ if field
37
+ resources.each_with_index do |r, i|
38
+ r.update_attribute field, real_value_for(values[i])
39
+ end
40
+ pile_up res
41
+ else
42
+ raise MundoPepino::FieldNotMapped.new(params[:field])
43
+ end
35
44
  end
36
45
  end
37
46
  end
38
-
47
+
39
48
  # 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])
49
+ # :model (raw) (optional)
50
+ # :table
51
+ # :name (optional)
52
+ def given_resource_have_the_following_values_from_step_table(params)
53
+ params[:model] = last_mentioned.class.name.downcase if params[:model].nil?
54
+
55
+ params[:table].hashes.each do |hash|
56
+ hash.each_pair do |campo, valor|
57
+ given_those_resources_have_value_in_field :model => params[:model],
58
+ :name => params[:name],
59
+ :field => campo,
60
+ :value => valor
53
61
  end
54
62
  end
55
63
  end
@@ -58,7 +66,7 @@ module MundoPepino
58
66
  children_model = convert_to_model(params[:children_field])
59
67
  last_mentioned_resources(params[:model], params[:name]) do |resource|
60
68
  attribs = names_for_simple_creation(children_model,
61
- params[:number_of_children].to_number, params[:children_names],
69
+ (params[:number_of_children] || '1').to_number, params[:children_names],
62
70
  parent_options(resource, children_model, params[:children_field]))
63
71
  add_resource children_model, attribs, :force_creation => params[:children_names].nil?
64
72
  end
@@ -89,8 +97,14 @@ module MundoPepino
89
97
  if params[:selector].blank?
90
98
  should_or_not_contain_text params
91
99
  else
92
- within params[:selector] do
93
- should_or_not_contain_text params
100
+ if defined?(Capybara)
101
+ with_scope params[:selector] do
102
+ should_or_not_contain_text params
103
+ end
104
+ else
105
+ within params[:selector] do |content|
106
+ should_or_not_contain_text content, params
107
+ end
94
108
  end
95
109
  end
96
110
  end
@@ -130,5 +144,16 @@ module MundoPepino
130
144
  def then_that_resource_should_have_child(params)
131
145
  last_mentioned_should_have_child(params[:children_field], params[:child_name])
132
146
  end
147
+
148
+ private
149
+ def resource_not_respond_to_field?(res, field)
150
+ res = res.is_a?(Array) ? res.first : res
151
+ field.to_model && !res.respond_to?(field.to_model.name.downcase)
152
+ end
153
+
154
+ def resource_respond_to_relation_field?(res, field)
155
+ res = res.is_a?(Array) ? res.first : res
156
+ field_for(res.class, field) && res.respond_to?(field_for(res.class, field))
157
+ end
133
158
  end
134
159
  end
@@ -34,6 +34,14 @@ module MundoPepino
34
34
  end
35
35
  end
36
36
 
37
+ def hasify(should_or_not)
38
+ shouldify(should_or_not) == :should ? :have : :have_no
39
+ end
40
+
41
+ def not_hasify(should_or_not)
42
+ hasify(should_or_not) == :have ? :have_no : :have
43
+ end
44
+
37
45
  def shouldify(should_or_not)
38
46
  should_or_not =~ /^(#{MundoPepino::Matchers::Bites._should_})$/i ? :should : :should_not
39
47
  end
@@ -84,7 +92,7 @@ module MundoPepino
84
92
 
85
93
  def convert_to_field(raw_field, model = nil)
86
94
  unless raw_field.nil?
87
- if field = field_for(model, raw_field.to_unquoted)
95
+ if field = field_for(model, raw_field.to_unquoted.to_translated)
88
96
  field
89
97
  else
90
98
  raise MundoPepino::FieldNotMapped.new(raw_field)
@@ -214,7 +222,7 @@ module MundoPepino
214
222
  if model = unquoted_model.to_model
215
223
  pile_up model.new
216
224
  MundoPepino.world.send "#{model.table_name}_path"
217
- elsif url = "#{the_page_of} #{raw_model}".to_user_page
225
+ elsif url = "#{the_page_of} #{raw_model}".to_page
218
226
  url
219
227
  else
220
228
  raise MundoPepino::ModelNotMapped.new(unquoted_model)
@@ -269,12 +277,27 @@ module MundoPepino
269
277
  "#{parent_model.name.underscore}_#{child_model.name.pluralize.underscore}_attributes"
270
278
  end
271
279
 
272
- def should_or_not_contain_text(params)
280
+ def should_or_not_contain_text(*args)
281
+ params = args.last.is_a?(Hash) ? args.pop : {}
282
+ content = args.empty? ? nil : args.first
283
+
273
284
  # 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))
285
+ if defined?(Capybara)
286
+ response.should send("#{hasify(params[:should])}_xpath", '/descendant-or-self::*',
287
+ :text => params[:text].to_unquoted.to_translated.to_regexp)
288
+ else
289
+ if content
290
+ content.send(
291
+ shouldify(params[:should]),
292
+ contain(params[:text].to_unquoted.to_translated.to_regexp))
293
+ else
294
+ response.send(
295
+ shouldify(params[:should]),
296
+ contain(params[:text].to_unquoted.to_translated.to_regexp))
297
+ end
298
+ end
277
299
  end
278
300
  end
279
301
  end
280
302
 
303
+
@@ -2,7 +2,7 @@ module MundoPepino #:nodoc:
2
2
  class VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 2
5
- TINY = 1
5
+ TINY = 2
6
6
  PATCH = nil # Set to nil for official release
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, PATCH].compact.join('.')
@@ -1,10 +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
+ gem 'cucumber' unless File.directory?(File.join(Rails.root, 'vendor/plugins/cucumber'))
4
4
  require 'cucumber/rake/task'
5
5
 
6
6
  Cucumber::Rake::Task.new({:caracteristicas => 'db:test:prepare'}) do |t|
7
7
  t.fork = true # You may get faster startup if you set this to false
8
8
  t.profile = 'default'
9
- #t.cucumber_opts = "--format pretty"
10
- end
9
+ t.cucumber_opts = "--format pretty"
10
+ end
@@ -1,10 +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
+ gem 'cucumber' unless File.directory?(File.join(Rails.root, 'vendor/plugins/cucumber'))
4
4
  require 'cucumber/rake/task'
5
5
 
6
6
  Cucumber::Rake::Task.new({:caracteristicas => 'db:test:prepare'}) do |t|
7
7
  t.fork = true # You may get faster startup if you set this to false
8
8
  t.profile = 'default'
9
- #t.cucumber_opts = "--format pretty"
9
+ t.cucumber_opts = "--format pretty"
10
10
  end
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.2.1
4
+ version: 0.2.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: 2010-04-16 00:00:00 +02:00
12
+ date: 2010-05-17 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency