Module: DefaultMethodObjectToApp
- Defined in:
- lib/rspec/default_method_object_to_app.rb
Overview
Tries to send any method to application.method instead.
Sadly, Ruby doesn’t allow this to work work with naked assignments. So
.click # turns into application.foo_button.click
== 'baz' # turns into application.bar_text == 'baz'
but
quux = 'quuux' # just stays quux = 'quuux'
Instance Method Summary collapse
-
#method_missing(method, *args, &block) ⇒ Object
rubocop:disable Style/MethodMissingSuper.
-
#respond_to_missing?(method, _include_private = false) ⇒ Boolean
rubocop:enable Style/MethodMissingSuper.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
rubocop:disable Style/MethodMissingSuper
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/rspec/default_method_object_to_app.rb', line 12 def method_missing(method, *args, &block) super unless respond_to_missing? method if args.empty? app.send(method) else app.send(method, *args, &block) end rescue ArgumentError app.send(method) end |
Instance Method Details
#respond_to_missing?(method, _include_private = false) ⇒ Boolean
rubocop:enable Style/MethodMissingSuper
24 25 26 27 |
# File 'lib/rspec/default_method_object_to_app.rb', line 24 def respond_to_missing?(method, _include_private = false) return false if method =~ /^app$/ app.respond_to?(method) end |