Class: Spec::Matchers::SpecExtensions::HaveVariable

Inherits:
SpecExtensionsBase show all
Defined in:
lib/poolparty/spec/matchers/have_variable.rb

Instance Method Summary collapse

Methods inherited from SpecExtensionsBase

#ensured_as, #grab_entry, #is_valid_resource?

Constructor Details

#initialize(varname, expected, extra = "") ⇒ HaveVariable

Returns a new instance of HaveVariable.



5
6
7
8
9
# File 'lib/poolparty/spec/matchers/have_variable.rb', line 5

def initialize(varname, expected,extra="")
  @varname = varname
  @expected = expected
  @extra = extra
end

Instance Method Details

#failure_messageObject



17
18
19
# File 'lib/poolparty/spec/matchers/have_variable.rb', line 17

def failure_message
  "expected #{@target.inspect} to have variable #{@expected}"
end

#is_present?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/poolparty/spec/matchers/have_variable.rb', line 14

def is_present?
  @target.match(/\$#{@varname}(\W+)=(\W+)#{@expected}/)[0]
end

#matches?(target) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
13
# File 'lib/poolparty/spec/matchers/have_variable.rb', line 10

def matches?(target)
  @target = target
  is_present?
end

#negative_failure_messageObject



20
21
22
# File 'lib/poolparty/spec/matchers/have_variable.rb', line 20

def negative_failure_message
  "expected #{@target.inspect} not to have variable #{@expected}"
end

#typeObject



23
24
25
# File 'lib/poolparty/spec/matchers/have_variable.rb', line 23

def type
  "variable"
end