Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minitest integration #321

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft

Minitest integration #321

wants to merge 5 commits into from

Conversation

alex-brook
Copy link

This PR allows Minitest users to use web first assertions via normal assertions or expectations

closes #309

@davekaro @gma I don't have access to a real app using Minitest at the moment, so I would appreciate you giving it a go and seeing if it works for you

I've left this in draft mode as I'm intending to also update the API documentation as part of this PR, but I might not be able to do that until next week

I've also included the devcontainer/docker setup I used to get the project running locally, which I thought might be useful for other contributors - but feel free to drop that commit if you don't want to include it

Copy link

vercel bot commented Dec 12, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
playwright-ruby-client ⬜️ Ignored (Inspect) Visit Preview Dec 12, 2024 9:36pm

@davekaro
Copy link

Thanks! I tried this in my project, but I'm getting an error trying to create a Playwright instance:

My code does this:

@playwright ||= Playwright.create(playwright_cli_executable_path: Rails.root.join("node_modules/.bin/playwright"))

And I see this error:

NoMethodError: undefined method `new' for module Playwright
    /Users/dave/.local/share/mise/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/bundler/gems/playwright-ruby-client-4eabeccc96a6/lib/playwright/playwright_api.rb:45:in `wrap'
    /Users/dave/.local/share/mise/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/bundler/gems/playwright-ruby-client-4eabeccc96a6/lib/playwright/playwright_api.rb:13:in `wrap'
    /Users/dave/.local/share/mise/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/bundler/gems/playwright-ruby-client-4eabeccc96a6/lib/playwright.rb:88:in `create'

@davekaro
Copy link

I figured out what is going on, but not sure how to resolve. When I bundle the gem like gem "playwright-ruby-client", github: "YusukeIwaki/playwright-ruby-client" in my Gemfile, I get the same error.

The issue arises from the call in lib/playwright/playwright_api.rb, the method detect_class_for ends up calling ::Playwright.const_get("Playwright"), which returns Playwright::Playwright when I bundle normally, but returns Playwright when I specify a GitHub repo. Unsure how to fix that.

@alex-brook
Copy link
Author

Part of the library is generated dynamically from an API specification and not included in the source code, which might be what you're seeing here.

If you cd into the place the gem was downloaded and run development/generate_api.rb does it still happen?

@davekaro
Copy link

Indeed, development/generate_api.rb did the trick. But now I have a different issue. Before, my specs have something like

expect(@page.get_by_text("Text I'm looking for").inner_text).wont_be_nil

I changed that to

expect(@page).must_have_text("Text I'm looking for")

and now I'm getting a weird foreign key error in my database, that is triggered before that expectation even runs. If I comment out the new expectation, it passes just fine.

It's as if adding the must_have_text expectation is rolling back my transactions mid way through the test. I make a few GET requests and then a POST request, and in the GET requests, the database still has the data, but in the POST request it's gone.

@alex-brook
Copy link
Author

Was it that by any chance?

@davekaro
Copy link

Was it that by any chance?

I made sure to re-bundle and get the latest, but problem is still there.

@gma
Copy link

gma commented Dec 13, 2024

Nice work @alex-brook. I'm afraid I'm not going to have an opportunity to take it for a spin in time to give you immediate feedback, but I'm very pleased to see minitest assertions are on the way. 🚀

@davekaro
Copy link

I'm using minitest-parallel_fork and there must be some race condition with the error from this test and the transaction rolling back. If I remove minitest-parallel_fork and just run the test, I get a more helpful error:

NoMethodError: undefined method `assert_text' for an instance of Staff::Programs::Program::playwright
    /Users/dave/.local/share/mise/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/capybara-3.40.0/lib/capybara/minitest/spec.rb:253:in `must_have_text'
    spec/web/staff/programs/programs_spec.rb:18:in `block (2 levels) in <main>'

I didn't spend any time tracking that down yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Minitest spec expectations
3 participants