class Howitzer::Web::PageDsl::PageScope

This class is for private usage only

Attributes

outer_context[RW]
page_klass[RW]

Public Class Methods

new(page_klass, &block) click to toggle source
# File lib/howitzer/web/page_dsl.rb, line 10
def initialize(page_klass, &block)
  self.page_klass = page_klass
  self.outer_context = eval('self', block.binding) if block.present?
  instance_eval(&block)
end

Public Instance Methods

is_expected() click to toggle source

Makes current page as a subject for Rspec expectations @example

HomePage.on { expect(HomePage.given).to have_menu_section } # Bad
HomePage.on { is_expected.to have_menu_section } # Good
# File lib/howitzer/web/page_dsl.rb, line 21
def is_expected # rubocop:disable Naming/PredicateName
  expect(page_klass.given)
end
method_missing(name, *args, **options, &block) click to toggle source

Proxies all methods to a page instance.

@note There are some exceptions:

* Methods with `be_` and `have_` prefixes are excluded
* `out` method extracts an instance variable from an original context if starts from @.
 Otherwise it executes a method from an original context
Calls superclass method
# File lib/howitzer/web/page_dsl.rb, line 32
def method_missing(name, *args, **options, &block)
  return super if name =~ /\A(?:be|have)_/
  return eval_in_out_context(*args, **options, &block) if name == :out

  if options.present?
    page_klass.given.send(name, *args, **options, &block)
  else
    page_klass.given.send(name, *args, &block)
  end
end
respond_to_missing?(name, include_private = false) click to toggle source

Makes proxied methods to be evaludated and returned as a proc @see method_missing

Calls superclass method
# File lib/howitzer/web/page_dsl.rb, line 46
def respond_to_missing?(name, include_private = false)
  name !~ /\A(?:be|have)_/ || super
end

Private Instance Methods

eval_in_out_context(*args, **options, &block) click to toggle source
# File lib/howitzer/web/page_dsl.rb, line 52
def eval_in_out_context(*args, **options, &block)
  return nil if args.empty?

  name = args.shift
  return get_outer_instance_variable(name) if name.to_s.start_with?('@')

  if options.present?
    outer_context.send(name, *args, **options, &block)
  else
    outer_context.send(name, *args, &block)
  end
end
get_outer_instance_variable(name) click to toggle source
# File lib/howitzer/web/page_dsl.rb, line 65
def get_outer_instance_variable(name)
  outer_context.instance_variable_get(name)
end