class SitePrism::RspecMatchers
Attributes
element_name[R]
Public Class Methods
new(element_name)
click to toggle source
# File lib/site_prism/rspec_matchers.rb, line 7 def initialize(element_name) @element_name = element_name end
Public Instance Methods
_create_rspec_existence_matchers()
click to toggle source
# File lib/site_prism/rspec_matchers.rb, line 11 def _create_rspec_existence_matchers SitePrism.logger.debug('Including all relevant matcher names / warnings in RSpec scope.') create_rspec_existence_matchers(matcher, object_method, negated_object_method, warning) end
Private Instance Methods
create_rspec_existence_matchers(matcher, object_method, negated_object_method, warning)
click to toggle source
# File lib/site_prism/rspec_matchers.rb, line 18 def create_rspec_existence_matchers(matcher, object_method, negated_object_method, warning) RSpec::Matchers.define(matcher) do |*args| match { |actual| actual.public_send(object_method, *args) } match_when_negated do |actual| return actual.public_send(negated_object_method, *args) if actual.respond_to?(negated_object_method) SitePrism.logger.debug(warning) !actual.public_send(object_method, *args) end end end
matcher()
click to toggle source
# File lib/site_prism/rspec_matchers.rb, line 30 def matcher "have_#{element_name}" end
negated_object_method()
click to toggle source
# File lib/site_prism/rspec_matchers.rb, line 38 def negated_object_method "has_no_#{element_name}?" end
object_method()
click to toggle source
# File lib/site_prism/rspec_matchers.rb, line 34 def object_method "has_#{element_name}?" end
warning()
click to toggle source
# File lib/site_prism/rspec_matchers.rb, line 42 def warning "The RSpec matcher '#{matcher}' was added by SitePrism, but the object under test "\ "does not respond to '#{negated_object_method}' and is probably not a SitePrism object. "\ 'Falling back to the default RSpec matcher.' end