Skip to content

Commit 9ec41ea

Browse files
author
Nick Schwaderer
committed
Add generic finder methods to shoes-spec
- find_all(*specs): returns array of matching elements (alias for drawables()) - find_button(text): finds button by text content - all_ovals, all_rects, all_buttons, all_paras: aliases for plural finders - Fix pluralization: progress -> progresses (not progresss) - Fix pluralization comment for edit_box, list_box Both Scarpe-Webview and Niente implementations updated.
1 parent a14b02e commit 9ec41ea

File tree

2 files changed

+127
-0
lines changed

2 files changed

+127
-0
lines changed

lacci/lib/scarpe/niente/shoes_spec.rb

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ def self.pluralize_dsl_name(name)
4141
# Handle common English pluralization rules
4242
case name
4343
when /box$/
44+
# edit_box -> edit_boxes, list_box -> list_boxes
45+
name + "es"
46+
when /ss$/
47+
# progress -> progresses
4448
name + "es"
4549
else
4650
name + "s"
@@ -68,6 +72,29 @@ def self.pluralize_dsl_name(name)
6872
end
6973
end
7074

75+
# Text size finders - these find Shoes::Para by size attribute
76+
# title(), banner(), caption(), subtitle(), tagline(), inscription()
77+
# are convenience methods that create Para with a specific size,
78+
# so we need special finders for them.
79+
TEXT_SIZE_NAMES = [:title, :banner, :caption, :subtitle, :tagline, :inscription].freeze
80+
81+
TEXT_SIZE_NAMES.each do |size_name|
82+
# Singular finder - raises if not exactly one match
83+
define_method(size_name) do
84+
drawables = Shoes::App.find_drawables_by(Shoes::Para).select { |d| d.size == size_name }
85+
raise Shoes::Errors::MultipleDrawablesFoundError, "Found more than one #{size_name}!" if drawables.size > 1
86+
raise Shoes::Errors::NoDrawablesFoundError, "Found no #{size_name}!" if drawables.empty?
87+
88+
Niente::ShoesSpecProxy.new(drawables[0])
89+
end
90+
91+
# Plural finder - returns array of all matches
92+
define_method(pluralize_dsl_name(size_name.to_s)) do
93+
drawables = Shoes::App.find_drawables_by(Shoes::Para).select { |d| d.size == size_name }
94+
drawables.map { |d| Niente::ShoesSpecProxy.new(d) }
95+
end
96+
end
97+
7198
# Singular drawable finder
7299
def drawable(*specs)
73100
found = Shoes::App.find_drawables_by(*specs)
@@ -81,6 +108,41 @@ def drawables(*specs)
81108
found = Shoes::App.find_drawables_by(*specs)
82109
found.map { |d| Niente::ShoesSpecProxy.new(d) }
83110
end
111+
112+
# Generic finder - returns array of all matching elements
113+
# Alias for drawables() for Shoes-Spec compatibility
114+
# @param specs [Array] search specifications (class, symbol, or string)
115+
# @return [Array<Niente::ShoesSpecProxy>] array of matching proxy objects
116+
# @example
117+
# find_all(Shoes::Button)
118+
# find_all(:@my_button)
119+
def find_all(*specs)
120+
drawables(*specs)
121+
end
122+
123+
# Find a button by its text content
124+
# @param text [String] the button text to search for
125+
# @return [Niente::ShoesSpecProxy] proxy for the matching button
126+
# @raise [Shoes::Errors::NoDrawablesFoundError] if no button matches
127+
# @raise [Shoes::Errors::MultipleDrawablesFoundError] if multiple buttons match
128+
# @example
129+
# find_button("Click Me")
130+
# find_button("Submit").trigger_click
131+
def find_button(text)
132+
all_buttons = Shoes::App.find_drawables_by(Shoes::Button)
133+
matching = all_buttons.select { |b| b.text == text }
134+
135+
raise Shoes::Errors::MultipleDrawablesFoundError, "Found more than one button with text #{text.inspect}!" if matching.size > 1
136+
raise Shoes::Errors::NoDrawablesFoundError, "Found no button with text #{text.inspect}!" if matching.empty?
137+
138+
Niente::ShoesSpecProxy.new(matching[0])
139+
end
140+
141+
# Aliases for consistency - some specs use all_* naming convention
142+
alias all_ovals ovals
143+
alias all_rects rects
144+
alias all_buttons buttons
145+
alias all_paras paras
84146
end
85147

86148
class Niente::ShoesSpecProxy

lib/scarpe/shoes_spec.rb

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,10 @@ def self.pluralize_dsl_name(name)
259259
# Handle common English pluralization rules
260260
case name
261261
when /box$/
262+
# edit_box -> edit_boxes, list_box -> list_boxes
263+
name + "es"
264+
when /ss$/
265+
# progress -> progresses
262266
name + "es"
263267
else
264268
name + "s"
@@ -289,6 +293,31 @@ def self.pluralize_dsl_name(name)
289293
end
290294
end
291295

296+
# Text size finders - these find Shoes::Para by size attribute
297+
# title(), banner(), caption(), subtitle(), tagline(), inscription()
298+
# are convenience methods that create Para with a specific size,
299+
# so we need special finders for them.
300+
TEXT_SIZE_NAMES = [:title, :banner, :caption, :subtitle, :tagline, :inscription].freeze
301+
302+
TEXT_SIZE_NAMES.each do |size_name|
303+
# Singular finder - raises if not exactly one match
304+
define_method(size_name) do
305+
app = Shoes.APPS[0]
306+
drawables = app.find_drawables_by(Shoes::Para).select { |d| d.size == size_name }
307+
raise Shoes::Errors::MultipleDrawablesFoundError, "Found more than one #{size_name}!" if drawables.size > 1
308+
raise Shoes::Errors::NoDrawablesFoundError, "Found no #{size_name}!" if drawables.empty?
309+
310+
Scarpe::ShoesSpecProxy.new(drawables[0])
311+
end
312+
313+
# Plural finder - returns array of all matches
314+
define_method(pluralize_dsl_name(size_name.to_s)) do
315+
app = Shoes.APPS[0]
316+
drawables = app.find_drawables_by(Shoes::Para).select { |d| d.size == size_name }
317+
drawables.map { |d| Scarpe::ShoesSpecProxy.new(d) }
318+
end
319+
end
320+
292321
# Singular drawable finder
293322
def drawable(*specs)
294323
app = Shoes.APPS[0]
@@ -306,6 +335,42 @@ def drawables(*specs)
306335
found.map { |d| Scarpe::ShoesSpecProxy.new(d) }
307336
end
308337

338+
# Generic finder - returns array of all matching elements
339+
# Alias for drawables() for Shoes-Spec compatibility
340+
# @param specs [Array] search specifications (class, symbol, or string)
341+
# @return [Array<Scarpe::ShoesSpecProxy>] array of matching proxy objects
342+
# @example
343+
# find_all(Shoes::Button)
344+
# find_all(:@my_button)
345+
def find_all(*specs)
346+
drawables(*specs)
347+
end
348+
349+
# Find a button by its text content
350+
# @param text [String] the button text to search for
351+
# @return [Scarpe::ShoesSpecProxy] proxy for the matching button
352+
# @raise [Shoes::Errors::NoDrawablesFoundError] if no button matches
353+
# @raise [Shoes::Errors::MultipleDrawablesFoundError] if multiple buttons match
354+
# @example
355+
# find_button("Click Me")
356+
# find_button("Submit").trigger_click
357+
def find_button(text)
358+
app = Shoes.APPS[0]
359+
all_buttons = app.find_drawables_by(Shoes::Button)
360+
matching = all_buttons.select { |b| b.text == text }
361+
362+
raise Shoes::Errors::MultipleDrawablesFoundError, "Found more than one button with text #{text.inspect}!" if matching.size > 1
363+
raise Shoes::Errors::NoDrawablesFoundError, "Found no button with text #{text.inspect}!" if matching.empty?
364+
365+
Scarpe::ShoesSpecProxy.new(matching[0])
366+
end
367+
368+
# Aliases for consistency - some specs use all_* naming convention
369+
alias all_ovals ovals
370+
alias all_rects rects
371+
alias all_buttons buttons
372+
alias all_paras paras
373+
309374
def catscradle_dsl(&block)
310375
Scarpe::CCInstance.instance.instance_eval(&block)
311376
end

0 commit comments

Comments
 (0)