Module: Capybara::Compose
- Defined in:
- lib/capybara/compose.rb,
lib/capybara/compose/version.rb
Overview
Internal: Global configuration for the library.
Defined Under Namespace
Modules: Actions, Assertions, BenchmarkHelpers, DependencyInjection, Finders, Matchers, Selectors, Synchronization, ToOrExpectationHandler Classes: Config, TestHelper
Constant Summary collapse
- VERSION =
'1.0.4'- DEFAULT_CONFIGURATION =
{ helpers_paths: ['test_helpers'].freeze, }.freeze
- 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.
[ :title, :body, :html, ].freeze
- RESERVED_METHODS =
Internal: Methods that should not be overiden or used as locator aliases to avoid confusion while working on test helpers.
(Capybara::Session::DSL_METHODS - SKIPPED_DSL_METHODS + test_helper_methods).to_set.freeze
- 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.
%i[matches_style? has_style? match_style have_style].to_set.freeze
Class Method Summary collapse
-
.config {|@config| ... } ⇒ Object
Public: Returns the current configuration for the test helpers.
-
.define_helper_method(klass, method_name, wrap: false, assertion: false, target: 'current_context', return_self: assertion, inject_test_helper: true) ⇒ Object
Internal: Allows to define methods that are a part of the Capybara DSL, as well as RSpec matchers.
Class Method Details
.config {|@config| ... } ⇒ Object
Public: Returns the current configuration for the test helpers.
52 53 54 55 56 |
# File 'lib/capybara/compose.rb', line 52 def self.config @config ||= Config.new(*DEFAULT_CONFIGURATION.values) yield @config if block_given? @config end |
.define_helper_method(klass, method_name, wrap: false, assertion: false, target: 'current_context', return_self: assertion, inject_test_helper: true) ⇒ Object
Internal: Allows to define methods that are a part of the Capybara DSL, as well as RSpec matchers.
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/capybara/compose.rb', line 60 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 |