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

Inherits:
Object
  • Object
show all
Includes:
RSpec::Matchers
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.



9
10
11
12
13
# File 'lib/howitzer/web/page_dsl.rb', line 9

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.



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

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


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

def is_expected # rubocop:disable Style/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:



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

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