Sha256: 27f3d851f96c87cc286406c3a67fdafe3d6db26b1a463e2c1717003d51761250

Contents?: true

Size: 1.43 KB

Versions: 34

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true

require 'capybara'

module Capybara
  module DSL
    def self.included(base)
      warn 'including Capybara::DSL in the global scope is not recommended!' if base == Object
      super
    end

    def self.extended(base)
      warn 'extending the main object with Capybara::DSL is not recommended!' if base == TOPLEVEL_BINDING.eval('self')
      super
    end

    ##
    #
    # Shortcut to working in a different session.
    #
    def using_session(name_or_session, &block)
      Capybara.using_session(name_or_session, &block)
    end

    # Shortcut to using a different wait time.
    #
    def using_wait_time(seconds, &block)
      page.using_wait_time(seconds, &block)
    end

    ##
    #
    # Shortcut to accessing the current session.
    #
    #     class MyClass
    #       include Capybara::DSL
    #
    #       def has_header?
    #         page.has_css?('h1')
    #       end
    #     end
    #
    # @return [Capybara::Session] The current session object
    #
    def page
      Capybara.current_session
    end

    Session::DSL_METHODS.each do |method|
      if RUBY_VERSION >= '2.7'
        class_eval <<~METHOD, __FILE__, __LINE__ + 1
          def #{method}(...)
            page.method("#{method}").call(...)
          end
        METHOD
      else
        define_method method do |*args, &block|
          page.send method, *args, &block
        end
      end
    end
  end

  extend(Capybara::DSL)
end

Version data entries

34 entries across 23 versions & 3 rubygems

Version Path
tdiary-5.2.4 vendor/bundle/ruby/3.1.0/gems/capybara-3.36.0/lib/capybara/dsl.rb
tdiary-5.2.1 vendor/bundle/ruby/3.1.0/gems/capybara-3.36.0/lib/capybara/dsl.rb
tdiary-5.2.0 vendor/bundle/ruby/2.7.0/gems/capybara-3.35.3/lib/capybara/dsl.rb
tdiary-5.2.0 vendor/bundle/ruby/3.0.0/gems/capybara-3.36.0/lib/capybara/dsl.rb
date_n_time_picker_activeadmin-0.1.2 vendor/bundle/ruby/2.6.0/gems/capybara-3.36.0/lib/capybara/dsl.rb
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/capybara-3.36.0/lib/capybara/dsl.rb
capybara-3.36.0 lib/capybara/dsl.rb
tdiary-5.1.7 vendor/bundle/ruby/3.0.0/gems/capybara-3.35.3/lib/capybara/dsl.rb
tdiary-5.1.7 vendor/bundle/ruby/2.7.0/gems/capybara-3.35.3/lib/capybara/dsl.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/2.7.0/gems/capybara-3.35.3/lib/capybara/dsl.rb
tdiary-5.1.6 vendor/bundle/ruby/3.0.0/gems/capybara-3.35.3/lib/capybara/dsl.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/tdiary-5.1.4/vendor/bundle/ruby/2.7.0/gems/capybara-3.34.0/lib/capybara/dsl.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/capybara-3.35.3/lib/capybara/dsl.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/capybara-3.34.0/lib/capybara/dsl.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/capybara-3.35.3/lib/capybara/dsl.rb
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/capybara-3.34.0/lib/capybara/dsl.rb
tdiary-5.1.5 vendor/bundle/ruby/2.7.0/gems/capybara-3.35.3/lib/capybara/dsl.rb
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/capybara-3.35.3/lib/capybara/dsl.rb
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/tdiary-5.1.4/vendor/bundle/ruby/2.7.0/gems/capybara-3.34.0/lib/capybara/dsl.rb
capybara-3.35.3 lib/capybara/dsl.rb