Class: Neospec::Expector
- Inherits:
-
Object
- Object
- Neospec::Expector
- Includes:
- EqualityExpectors, ErrorExpectors, InclusionExpectors
- Defined in:
- lib/neospec/expector.rb,
lib/neospec/expector/error_expectors.rb,
lib/neospec/expector/equality_expectors.rb,
lib/neospec/expector/inclusion_expectors.rb
Defined Under Namespace
Modules: EqualityExpectors, ErrorExpectors, InclusionExpectors
Instance Attribute Summary collapse
-
#failure ⇒ Object
readonly
Returns the value of attribute failure.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Instance Method Summary collapse
- #actual ⇒ Object
- #failed(message) ⇒ Object
-
#initialize(result:, actual:, stack:, logger:) ⇒ Expector
constructor
A new instance of Expector.
- #log(message, context: nil) ⇒ Object
- #succeeded(message) ⇒ Object
Methods included from ErrorExpectors
Methods included from InclusionExpectors
#not_to_be_in, #not_to_include, #to_be_in, #to_include
Methods included from EqualityExpectors
#not_to_equal, #to_be_a, #to_be_empty, #to_be_false, #to_be_nil, #to_be_true, #to_equal
Constructor Details
#initialize(result:, actual:, stack:, logger:) ⇒ Expector
Returns a new instance of Expector.
9 10 11 12 13 14 |
# File 'lib/neospec/expector.rb', line 9 def initialize(result:, actual:, stack:, logger:) @actual = actual @stack = stack @logger = logger @result = result end |
Instance Attribute Details
#failure ⇒ Object (readonly)
Returns the value of attribute failure.
7 8 9 |
# File 'lib/neospec/expector.rb', line 7 def failure @failure end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
7 8 9 |
# File 'lib/neospec/expector.rb', line 7 def result @result end |
Instance Method Details
#actual ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/neospec/expector.rb', line 36 def actual if @actual.is_a?(Proc) @actual = @actual.call end @actual end |
#failed(message) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/neospec/expector.rb', line 25 def failed() @result.expectations += 1 @result.failures << Neospec::Spec::Result::Failure.new( stack: @stack, message: "Expected #{}" ) log(, context: :expect) raise Neospec::Spec::Result::FailureEncounteredError end |
#log(message, context: nil) ⇒ Object
16 17 18 |
# File 'lib/neospec/expector.rb', line 16 def log(, context: nil) @logger.log(, context: context, result: @result) end |
#succeeded(message) ⇒ Object
20 21 22 23 |
# File 'lib/neospec/expector.rb', line 20 def succeeded() @result.expectations += 1 log(, context: :expect) end |