Class: BotAway::TestCase::Matchers::ObfuscationMatcher

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(obfuscated_name, obfuscated_id) ⇒ ObfuscationMatcher



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

def initialize(obfuscated_name, obfuscated_id)
  @obfuscated_id, @obfuscated_name = obfuscated_id, obfuscated_name
end

Instance Attribute Details

#obfuscated_idObject (readonly)

Returns the value of attribute obfuscated_id.



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

def obfuscated_id
  @obfuscated_id
end

#obfuscated_nameObject (readonly)

Returns the value of attribute obfuscated_name.



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

def obfuscated_name
  @obfuscated_name
end

Instance Method Details

#descriptionObject



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

def description
  "be obfuscated as '#{obfuscated_name}' with id '#{obfuscated_id}'"
end

#failure_messageObject



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

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

#match(key, value) ⇒ Object



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

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

#matches?(target) ⇒ Boolean



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

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

#negative_failure_messageObject



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

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