Class: Spectus::ExpectationTarget Private

Inherits:
BasicObject
Defined in:
lib/spectus/expectation_target.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Wraps the target of an expectation.

Examples:

this { stuff } # => ExpectationTarget wrapping the block

Instance Method Summary collapse

Constructor Details

#initialize(&actual) ⇒ ExpectationTarget

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Create a new expection target



13
14
15
# File 'lib/spectus/expectation_target.rb', line 13

def initialize(&actual)
  @actual = actual
end

Instance Method Details

#MAY(definition) ⇒ Boolean

This word, or the adjective “OPTIONAL”, mean that an item is truly optional. One vendor may choose to include the item because a particular marketplace requires it or because the vendor feels that it enhances the product while another vendor may omit the same item. An implementation which does not include a particular option MUST be prepared to interoperate with another implementation which does include the option, though perhaps with reduced functionality. In the same vein an implementation which does include a particular option MUST be prepared to interoperate with another implementation which does not include the option (except, of course, for the feature the option provides.)

Examples:

Optional definition

this { 'foo'.bar }.MAY match: /^foo$/ # => true

Parameters:

  • definition (Hash)

Returns:

  • (Boolean)

    report if the expectation is true or false.



102
103
104
# File 'lib/spectus/expectation_target.rb', line 102

def MAY(definition)
  RequirementLevel::Low.new(definition).pass?(&@actual)
end

#MUST(definition) ⇒ Boolean

This word, or the terms “REQUIRED” or “SHALL”, mean that the definition is an absolute requirement of the specification.

Examples:

_Absolute requirement_ definition

this { 'foo'.upcase }.MUST eql: 'FOO' # => true

Parameters:

  • definition (Hash)

Returns:

  • (Boolean)

    report if the expectation is true or false.



28
29
30
# File 'lib/spectus/expectation_target.rb', line 28

def MUST(definition)
  RequirementLevel::High.new(definition).pass?(&@actual)
end

#MUST_NOT(definition) ⇒ Boolean

This phrase, or the phrase “SHALL NOT”, mean that the definition is an absolute prohibition of the specification.

Examples:

_Absolute prohibition_ definition

this { 'foo'.length }.MUST_NOT equal: 42 # => true

Parameters:

  • definition (Hash)

Returns:

  • (Boolean)

    report if the expectation is true or false.



43
44
45
# File 'lib/spectus/expectation_target.rb', line 43

def MUST_NOT(definition)
  RequirementLevel::High.new(definition, true).pass?(&@actual)
end

#SHOULD(definition) ⇒ Boolean

This word, or the adjective “RECOMMENDED”, mean that there may exist valid reasons in particular circumstances to ignore a particular item, but the full implications must be understood and carefully weighed before choosing a different course.

Examples:

Recommended definition

this { 'foo'.valid_encoding? }.SHOULD equal: true # => true

Parameters:

  • definition (Hash)

Returns:

  • (Boolean)

    report if the expectation is true or false.



60
61
62
# File 'lib/spectus/expectation_target.rb', line 60

def SHOULD(definition)
  RequirementLevel::Medium.new(definition).pass?(&@actual)
end

#SHOULD_NOT(definition) ⇒ Boolean

This phrase, or the phrase “NOT RECOMMENDED” mean that there may exist valid reasons in particular circumstances when the particular behavior is acceptable or even useful, but the full implications should be understood and the case carefully weighed before implementing any behavior described with this label.

Examples:

_Not recommended_ definition

this { ''.blank? }.SHOULD_NOT raise_exception: NoMethodError # => false

Parameters:

  • definition (Hash)

Returns:

  • (Boolean)

    report if the expectation is true or false.



78
79
80
# File 'lib/spectus/expectation_target.rb', line 78

def SHOULD_NOT(definition)
  RequirementLevel::Medium.new(definition, true).pass?(&@actual)
end