Class: BotAway::TestCase::Matchers::HoneypotMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/bot-away/test_case/matchers/honeypot_matcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, tag_id) ⇒ HoneypotMatcher

Returns a new instance of HoneypotMatcher.



4
5
6
# File 'lib/bot-away/test_case/matchers/honeypot_matcher.rb', line 4

def initialize(tag_name, tag_id)
  @tag_name, @tag_id = tag_name, tag_id
end

Instance Attribute Details

#tag_idObject (readonly)

Returns the value of attribute tag_id.



2
3
4
# File 'lib/bot-away/test_case/matchers/honeypot_matcher.rb', line 2

def tag_id
  @tag_id
end

#tag_nameObject (readonly)

Returns the value of attribute tag_name.



2
3
4
# File 'lib/bot-away/test_case/matchers/honeypot_matcher.rb', line 2

def tag_name
  @tag_name
end

Instance Method Details

#descriptionObject



19
20
21
# File 'lib/bot-away/test_case/matchers/honeypot_matcher.rb', line 19

def description
  "include a honeypot named '#{tag_name}' with id '#{tag_id}'"
end

#failure_messageObject



23
24
25
# File 'lib/bot-away/test_case/matchers/honeypot_matcher.rb', line 23

def failure_message
  "expected #{@target.inspect}\n  to match #{@rx.inspect}"
end

#match(key, value, suffix = nil) ⇒ Object



14
15
16
17
# File 'lib/bot-away/test_case/matchers/honeypot_matcher.rb', line 14

def match(key, value, suffix = nil)
  @rx = /#{key}=['"]#{Regexp::escape value}["']/
  @target[@rx]
end

#matches?(target) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
11
12
# File 'lib/bot-away/test_case/matchers/honeypot_matcher.rb', line 8

def matches?(target)
  target = target.call if target.kind_of?(Proc)
  @target = target
  match(:id, tag_id) && match(:name, tag_name)
end

#negative_failure_messageObject



27
28
29
# File 'lib/bot-away/test_case/matchers/honeypot_matcher.rb', line 27

def negative_failure_message
  "expected #{@target.inspect}\n  to not match #{@rx.inspect}"
end