Module: CapybaraTestHelpers
- Defined in:
- lib/capybara_test_helpers/config.rb,
lib/capybara_test_helpers/version.rb
Overview
Easily write fluent Page Objects for Capybara in Ruby.
Defined Under Namespace
Modules: Actions, Assertions, BenchmarkHelpers, DependencyInjection, Finders, Matchers, Selectors, Synchronization, ToOrExpectationHandler Classes: TestHelper
Constant Summary collapse
- DEFAULTS =
{ 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
- VERSION =
'1.0.4'
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.
38 39 40 41 42 |
# File 'lib/capybara_test_helpers/config.rb', line 38 def self.config @config ||= OpenStruct.new(DEFAULTS) 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.
46 47 48 49 50 51 52 53 54 55 |
# 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 |