module CapybaraTestHelpers
Internal: Configuration for Provides the basic functionality to create simple test helpers.
Easily write fluent Page Objects for Capybara
in Ruby.
Constants
- DEFAULTS
- METHODS_EXPECTING_A_HASH
Internal: Ruby 2.7 swallows keyword arguments, so for methods that take a Hash as the first argument as well as keyword arguments, we need to manually detect and move them to args if empty.
- RESERVED_METHODS
Internal: Methods that should not be overiden or used as locator aliases to avoid confusion while working on test helpers.
- SKIPPED_DSL_METHODS
Internal: Methods that are in the
Capybara
DSL but are so common that we don't want to issue a warning if they are used as selectors.- VERSION
Public Class Methods
Public: Returns the current configuration for the test helpers.
# File lib/capybara_test_helpers/config.rb, line 38 def self.config @config ||= OpenStruct.new(DEFAULTS) yield @config if block_given? @config end
Internal: Allows to define methods that are a part of the Capybara
DSL, as well as RSpec matchers.
# File lib/capybara_test_helpers/config.rb, line 46 def self.define_helper_method(klass, method_name, wrap: false, assertion: false, target: 'current_context', return_self: assertion, inject_test_helper: true) klass.class_eval <<~HELPER, __FILE__, __LINE__ + 1 def #{ method_name }(*args, **kwargs, &filter) #{ 'args.push(kwargs) && (kwargs = {}) if args.empty?' if METHODS_EXPECTING_A_HASH.include?(method_name) } #{ 'kwargs[:test_helper] = self' if inject_test_helper } #{ 'wrap_element ' if wrap }#{ assertion ? "expect(#{ target }).to_or not_to, test_context" : target }.#{ method_name }(*args, **kwargs, &filter) #{ 'self' if return_self } end HELPER end