ElMassimo / capybara-compose

✅ Easily write fluent integration tests with Capybara in Ruby
https://capybara-test-helpers.netlify.app/
MIT License
32 stars 1 forks source link

Using synchronize_expectation globally #5

Closed simonasdev closed 3 years ago

simonasdev commented 3 years ago

Hi. Just started using your gem but can't really get how can I use synchronize_expectation globally in my tests. After defining base test helper like so:

class BaseTestHelper < Capybara::TestHelper
end

and verifying that this class indeed defines synchronize_expectation method I've tried using it in my globally included module like so:

module GlobalTestHelper
  extend ActiveSupport::Concern

  included do
    use_test_helpers(:base)
  end
end

But when calling synchronize_expectation I'm still getting undefined method synchronize_expectation for #<RSpec::ExampleGroups::Dashboard::NewUser:0x00007f99afaa5cd0>. Even if I delegate the method to base with delegate :synchronize_expectation, to: :base inside of included block, I'm still getting protected method synchronize_expectation called for #<BaseTestHelper 70144865172940>. So it seems to me that synchronize_expectation can only be called without explicit receiver, hence only inside of subclasses of Capybara::TestHelper. Any ideas what I'm missing? The example does not include this use case as far as I've noticed

simonasdev commented 3 years ago

For now I've settled by implementing synchronize_expectation in BaseTestHelper:

class BaseTestHelper < Capybara::TestHelper
  def synchronize_expectation(*args)
    super
  end
end

but this seems really unnecessary

ElMassimo commented 3 years ago

By default, synchronize_expectation is protected, because it's meant to be used inside test helpers, where it can be properly encapsulated.

Using it directly in tests can make them significantly harder to read.

If you really need to, you can change the method visibility to public instead:

class BaseTestHelper < Capybara::TestHelper
  public :synchronize_expectation
end