Class: Catechism::Matchers::RaiseError

Inherits:
Struct
  • Object
show all
Defined in:
lib/catechism/matchers/raise_error.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#negatedObject

Returns the value of attribute negated

Returns:

  • (Object)

    the current value of negated



2
3
4
# File 'lib/catechism/matchers/raise_error.rb', line 2

def negated
  @negated
end

#subjectObject

Returns the value of attribute subject

Returns:

  • (Object)

    the current value of subject



2
3
4
# File 'lib/catechism/matchers/raise_error.rb', line 2

def subject
  @subject
end

Instance Method Details

#failure_messageObject



16
17
18
19
20
21
22
# File 'lib/catechism/matchers/raise_error.rb', line 16

def failure_message
  if negated
    "Expected no error to be raised, but an error was raised"
  else
    "Expected error to be raised, but no error was raised"
  end
end

#raised?Boolean

Returns:

  • (Boolean)


3
4
5
6
7
8
9
10
# File 'lib/catechism/matchers/raise_error.rb', line 3

def raised?
  begin
    subject.call
  rescue StandardError => e
    return true
  end
  false
end

#valid?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/catechism/matchers/raise_error.rb', line 12

def valid?
  raised? ^ negated
end