Class: Spectus::ExpectationTarget

Inherits:
Object
  • Object
show all
Defined in:
lib/spectus/expectation_target.rb

Overview

Wraps the target of an expectation.

Examples:

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

Instance Method Summary collapse

Constructor Details

#initialize(&callable) ⇒ ExpectationTarget

Create a new expectation target

Parameters:

  • callable (Proc)

    The object to test.



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

def initialize(&callable)
  @callable = callable
end

Instance Method Details

#MAY(matcher) ⇒ Spectus::Result::Fail, Spectus::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

it { "foo".bar }.MAY match /^foo$/

Parameters:

  • matcher (#matches?)

    The matcher.

Returns:



169
170
171
172
173
174
175
176
# File 'lib/spectus/expectation_target.rb', line 169

def MAY(matcher)
  RequirementLevel::May.new(
    callable:   callable,
    isolation:  false,
    negate:     false,
    matcher:    matcher
  ).call
end

#MAY!(matcher) ⇒ Object

Examples:

Optional definition with isolation

it { "foo".bar }.MAY! match /^foo$/

See Also:



182
183
184
185
186
187
188
189
# File 'lib/spectus/expectation_target.rb', line 182

def MAY!(matcher)
  RequirementLevel::May.new(
    callable:   callable,
    isolation:  true,
    negate:     false,
    matcher:    matcher
  ).call
end

#MUST(matcher) ⇒ Spectus::Result::Fail, Spectus::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

it { "foo".upcase }.MUST eql 'FOO'

Parameters:

  • matcher (#matches?)

    The matcher.

Returns:



28
29
30
31
32
33
34
35
# File 'lib/spectus/expectation_target.rb', line 28

def MUST(matcher)
  RequirementLevel::Must.new(
    callable:   callable,
    isolation:  false,
    negate:     false,
    matcher:    matcher
  ).call
end

#MUST!(matcher) ⇒ Object

Examples:

_Absolute requirement_ definition with isolation

it { "foo".upcase }.MUST! eql 'FOO'

See Also:



41
42
43
44
45
46
47
48
# File 'lib/spectus/expectation_target.rb', line 41

def MUST!(matcher)
  RequirementLevel::Must.new(
    callable:   callable,
    isolation:  true,
    negate:     false,
    matcher:    matcher
  ).call
end

#MUST_NOT(matcher) ⇒ Spectus::Result::Fail, Spectus::Result::Pass

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

Examples:

_Absolute prohibition_ definition

it { "foo".size }.MUST_NOT equal 42

Parameters:

  • matcher (#matches?)

    The matcher.

Returns:



60
61
62
63
64
65
66
67
# File 'lib/spectus/expectation_target.rb', line 60

def MUST_NOT(matcher)
  RequirementLevel::Must.new(
    callable:   callable,
    isolation:  false,
    negate:     true,
    matcher:    matcher
  ).call
end

#MUST_NOT!(matcher) ⇒ Object

Examples:

_Absolute prohibition_ definition with isolation

it { "foo".size }.MUST_NOT! equal 42

See Also:



73
74
75
76
77
78
79
80
# File 'lib/spectus/expectation_target.rb', line 73

def MUST_NOT!(matcher)
  RequirementLevel::Must.new(
    callable:   callable,
    isolation:  true,
    negate:     true,
    matcher:    matcher
  ).call
end

#SHOULD(matcher) ⇒ Spectus::Result::Fail, Spectus::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

it { "foo".valid_encoding? }.SHOULD equal true

Parameters:

  • matcher (#matches?)

    The matcher.

Returns:



94
95
96
97
98
99
100
101
# File 'lib/spectus/expectation_target.rb', line 94

def SHOULD(matcher)
  RequirementLevel::Should.new(
    callable:   callable,
    isolation:  false,
    negate:     false,
    matcher:    matcher
  ).call
end

#SHOULD!(matcher) ⇒ Object

Examples:

Recommended definition with isolation

it { "foo".valid_encoding? }.SHOULD! equal true

See Also:



107
108
109
110
111
112
113
114
# File 'lib/spectus/expectation_target.rb', line 107

def SHOULD!(matcher)
  RequirementLevel::Should.new(
    callable:   callable,
    isolation:  true,
    negate:     false,
    matcher:    matcher
  ).call
end

#SHOULD_NOT(matcher) ⇒ Spectus::Result::Fail, Spectus::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

it { "".blank? }.SHOULD_NOT raise_exception NoMethodError

Parameters:

  • matcher (#matches?)

    The matcher.

Returns:



129
130
131
132
133
134
135
136
# File 'lib/spectus/expectation_target.rb', line 129

def SHOULD_NOT(matcher)
  RequirementLevel::Should.new(
    callable:   callable,
    isolation:  false,
    negate:     true,
    matcher:    matcher
  ).call
end

#SHOULD_NOT!(matcher) ⇒ Object

Examples:

_Not recommended_ definition with isolation

it { "".blank? }.SHOULD_NOT! raise_exception NoMethodError

See Also:



142
143
144
145
146
147
148
149
# File 'lib/spectus/expectation_target.rb', line 142

def SHOULD_NOT!(matcher)
  RequirementLevel::Should.new(
    callable:   callable,
    isolation:  true,
    negate:     true,
    matcher:    matcher
  ).call
end