Class: Howitzer::Web::PageDsl::PageScope
- Inherits:
-
Object
- Object
- Howitzer::Web::PageDsl::PageScope
- 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
-
#initialize(page_klass, &block) ⇒ PageScope
constructor
A new instance of PageScope.
-
#is_expected ⇒ Object
Makes current page as a subject for Rspec expectations.
-
#method_missing(name, *args, **options, &block) ⇒ Object
Proxies all methods to a page instance.
-
#respond_to_missing?(name, include_private = false) ⇒ Boolean
Makes proxied methods to be evaludated and returned as a proc.
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, **options, &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 37 38 39 40 41 |
# 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 if .present? page_klass.given.send(name, *args, **, &block) else page_klass.given.send(name, *args, &block) end end |
Instance Method Details
#is_expected ⇒ Object
Makes current page as a subject for Rspec expectations
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
46 47 48 |
# File 'lib/howitzer/web/page_dsl.rb', line 46 def respond_to_missing?(name, include_private = false) name !~ /\A(?:be|have)_/ || super end |