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

Support non-rails applications with minitest #128

Open
pftg opened this issue Sep 12, 2024 · 0 comments
Open

Support non-rails applications with minitest #128

pftg opened this issue Sep 12, 2024 · 0 comments

Comments

@pftg
Copy link
Collaborator

pftg commented Sep 12, 2024

To setup non-rails app I need at least to provide such code:

module Rails
  def self.root
    File.expand_path("../../", __FILE__)
  end

  def self.application
    Capybara.app
  end
end

class ApplicationSystemTestCase < Minitest::Test
  include Capybara::DSL
  include Capybara::Minitest::Assertions
  include CapybaraScreenshotDiff::DSL

  def screenshot(*, **)
    super
  rescue CapybaraScreenshotDiff::ExpectationNotMet => e
    raise ::Minitest::Assertion, e.message
  end

  alias_method :assert_matches_screenshot, :screenshot

  def setup
    super
    if ::Capybara::Screenshot.window_size
      ::Capybara::Screenshot::BrowserHelpers.resize_to(::Capybara::Screenshot.window_size)
    end
  end

  def teardown
    super
    Capybara.reset_sessions!

    errors = verify_screenshots!(@test_screenshots)
    failures << ::Minitest::Assertion.new(errors.join("\n\n")) if errors && !errors.empty?
  end
end
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

No branches or pull requests

1 participant