Class: Capybara::Simulated::Driver::FakePlaywrightPage
- Inherits:
-
Object
- Object
- Capybara::Simulated::Driver::FakePlaywrightPage
- Defined in:
- lib/capybara/simulated/driver.rb
Instance Method Summary collapse
-
#evaluate(js) ⇒ Object
Playwright’s ‘page.evaluate` takes either a string expression or a function literal — when given a function it calls it and returns the result.
-
#initialize(browser) ⇒ FakePlaywrightPage
constructor
A new instance of FakePlaywrightPage.
-
#locator(selector) ⇒ Object
‘pw_page.locator(selector)` returns a Locator that proxies click / fill / count / etc.
-
#method_missing {|_self| ... } ⇒ Object
Yield to the block when one is given so Playwright methods whose semantics live entirely in their block (the canonical case is ‘pw_page.expect_download { click_link “…” }` — `expect_download` arms a download watcher, then runs the block, then awaits the watcher).
- #respond_to_missing? ⇒ Boolean
Constructor Details
#initialize(browser) ⇒ FakePlaywrightPage
Returns a new instance of FakePlaywrightPage.
138 139 140 141 142 143 144 145 146 |
# File 'lib/capybara/simulated/driver.rb', line 138 def initialize(browser) = (@browser = browser) # Playwright's `page.evaluate` takes either a string expression # or a function literal — when given a function it calls it # and returns the result. The simulated driver's underlying # `evaluate_script` just runs the source as an expression, so # a function-literal payload would return the function object # instead of its return value. Wrap arrow-function-shaped # bodies in `(...)()` so the function is invoked and the test # sees its result. |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing {|_self| ... } ⇒ Object
Yield to the block when one is given so Playwright methods whose semantics live entirely in their block (the canonical case is ‘pw_page.expect_download { click_link “…” }` —`expect_download` arms a download watcher, then runs the block, then awaits the watcher). Returning `self` from a block-taking method-missing would skip the block entirely and the download never triggers. Pass the receiver in as the block argument so chained `|d| d.suggested_filename` readers see a no-op object.
169 170 171 172 |
# File 'lib/capybara/simulated/driver.rb', line 169 def method_missing(*) yield self if block_given? self end |
Instance Method Details
#evaluate(js) ⇒ Object
Playwright’s ‘page.evaluate` takes either a string expression or a function literal — when given a function it calls it and returns the result. The simulated driver’s underlying ‘evaluate_script` just runs the source as an expression, so a function-literal payload would return the function object instead of its return value. Wrap arrow-function-shaped bodies in `(…)()` so the function is invoked and the test sees its result.
147 148 149 150 151 |
# File 'lib/capybara/simulated/driver.rb', line 147 def evaluate(js, *) src = js.to_s.strip src = "(#{src})()" if src.match?(/\A(\(?\s*(async\s+)?(\(.*?\)|\w+)\s*=>|\(?\s*(async\s+)?function\s*\*?\s*\()/m) @browser.evaluate_script(src) end |
#locator(selector) ⇒ Object
‘pw_page.locator(selector)` returns a Locator that proxies click / fill / count / etc. through Capybara’s current session. Discourse’s SelectKit / system_helpers ‘locator` method drives the suspend / silence / penalize / dropdown chains via `pw_page.locator(…).click` — without a real locator the click is a no-op and the modal never advances.
158 |
# File 'lib/capybara/simulated/driver.rb', line 158 def locator(selector) = FakePlaywrightLocator.new(selector) |
#respond_to_missing? ⇒ Boolean
159 160 161 162 163 164 165 166 167 168 |
# File 'lib/capybara/simulated/driver.rb', line 159 def respond_to_missing?(*) = true # Yield to the block when one is given so Playwright methods # whose semantics live entirely in their block (the canonical # case is `pw_page.expect_download { click_link "…" }` — # `expect_download` arms a download watcher, *then* runs the # block, *then* awaits the watcher). Returning `self` from a # block-taking method-missing would skip the block entirely # and the download never triggers. Pass the receiver in as # the block argument so chained `|d| d.suggested_filename` # readers see a no-op object. |