Class: Spectus::ExpectationTarget

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

Overview

Wraps the target of an expectation.

Examples:

this { actual value } # => ExpectationTarget wrapping the block

Instance Method Summary collapse

Constructor Details

#initialize(&subject) ⇒ 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

Parameters:

  • subject (Proc)

    The value which is compared with the expected value.



16
17
18
19
# File 'lib/spectus/expectation_target.rb', line 16

def initialize(&subject)
  @subject    = subject
  @challenges = [block_challenge]
end

Instance Method Details

#MAY(req) ⇒ Result::Fail, Result::Pass

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$/

Parameters:

  • req (Array, Hash, Symbol)

Returns:



133
134
135
# File 'lib/spectus/expectation_target.rb', line 133

def MAY(req)
  RequirementLevel::Low.new(req, false, subject, *challenges).result
end

#MAY!(req) ⇒ Object

Examples:

Optional definition with isolation

this { 'foo'.bar }.MAY! Match: /^foo$/

See Also:



141
142
143
# File 'lib/spectus/expectation_target.rb', line 141

def MAY!(req)
  RequirementLevel::Low.new(req, false, subject, *challenges).result(true)
end

#MUST(req) ⇒ Result::Fail, Result::Pass

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'

Parameters:

  • req (Array, Hash, Symbol)

Returns:



34
35
36
# File 'lib/spectus/expectation_target.rb', line 34

def MUST(req)
  RequirementLevel::High.new(req, false, subject, *challenges).result
end

#MUST!(req) ⇒ Object

Examples:

_Absolute requirement_ definition with isolation

this { 'foo'.upcase }.MUST! Eql: 'FOO'

See Also:



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

def MUST!(req)
  RequirementLevel::High.new(req, false, subject, *challenges).result(true)
end

#MUST_NOT(req) ⇒ Result::Fail, Result::Pass

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

Examples:

_Absolute prohibition_ definition

this { 'foo'.size }.MUST_NOT Equal: 42

Parameters:

  • req (Array, Hash, Symbol)

Returns:



55
56
57
# File 'lib/spectus/expectation_target.rb', line 55

def MUST_NOT(req)
  RequirementLevel::High.new(req, true, subject, *challenges).result
end

#MUST_NOT!(req) ⇒ Object

Examples:

_Absolute prohibition_ definition with isolation

this { 'foo'.size }.MUST_NOT! Equal: 42

See Also:



63
64
65
# File 'lib/spectus/expectation_target.rb', line 63

def MUST_NOT!(req)
  RequirementLevel::High.new(req, true, subject, *challenges).result(true)
end

#SHOULD(req) ⇒ Result::Fail, Result::Pass

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

Parameters:

  • req (Array, Hash, Symbol)

Returns:



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

def SHOULD(req)
  RequirementLevel::Medium.new(req, false, subject, *challenges).result
end

#SHOULD!(req) ⇒ Object

Examples:

Recommended definition with isolation

this { 'foo'.valid_encoding? }.SHOULD! Equal: true

See Also:



86
87
88
89
# File 'lib/spectus/expectation_target.rb', line 86

def SHOULD!(req)
  RequirementLevel::Medium.new(req, false, subject, *challenges)
    .result(true)
end

#SHOULD_NOT(req) ⇒ Result::Fail, Result::Pass

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 RaiseException: NoMethodError

Parameters:

  • req (Array, Hash, Symbol)

Returns:



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

def SHOULD_NOT(req)
  RequirementLevel::Medium.new(req, true, subject, *challenges).result
end

#SHOULD_NOT!(req) ⇒ Object

Examples:

_Not recommended_ definition with isolation

this { ''.blank? }.SHOULD_NOT! RaiseException: NoMethodError

See Also:



111
112
113
# File 'lib/spectus/expectation_target.rb', line 111

def SHOULD_NOT!(req)
  RequirementLevel::Medium.new(req, true, subject, *challenges).result(true)
end