Class: Howitzer::Web::PageDsl::PageScope

Inherits:
Object
  • Object
show all
Includes:
RSpec::Matchers, RSpec::Wait
Defined in:
lib/howitzer/web/page_dsl.rb

Overview

This class is for private usage only

Instance Method Summary collapse

Constructor Details

#initialize(page_klass, &block) ⇒ PageScope

Returns a new instance of PageScope



10
11
12
13
14
# 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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object

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

Proxies all methods to a page instance.



32
33
34
35
36
# File 'lib/howitzer/web/page_dsl.rb', line 32

def method_missing(name, *args, &block)
  return super if name =~ /\A(?:be|have)_/
  return eval_in_out_context(*args, &block) if name == :out
  page_klass.given.send(name, *args, &block)
end

Instance Method Details

#is_expectedObject

Makes current page as a subject for Rspec expectations

Examples:

HomePage.on { expect(HomePage.given).to have_menu_section } # Bad
HomePage.on { is_expected.to have_menu_section } # Good


21
22
23
# File 'lib/howitzer/web/page_dsl.rb', line 21

def is_expected # rubocop:disable Naming/PredicateName
  expect(page_klass.given)
end

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Makes proxied methods to be evaludated and returned as a proc

Returns:

  • (Boolean)

See Also:



41
42
43
# File 'lib/howitzer/web/page_dsl.rb', line 41

def respond_to_missing?(name, include_private = false)
  name !~ /\A(?:be|have)_/ || super
end