Module: Spectre::Assertion

Defined in:
lib/spectre/assertion.rb

Defined Under Namespace

Classes: AndWrapper, Evaluation, OrWrapper, ValueWrapper

Class Method Summary collapse

Class Method Details

.be(expected_val) ⇒ Object



142
143
144
145
146
147
148
# File 'lib/spectre/assertion.rb', line 142

def be expected_val
  [
    expected_val,
    __method__,
    proc { |expected, actual| expected.inspect == actual.inspect },
  ]
end

.be_emptyObject



150
151
152
153
154
155
156
# File 'lib/spectre/assertion.rb', line 150

def be_empty
  [
    nil,
    'be',
    proc { |_, actual| actual.nil? or (actual.respond_to?(:empty?) and actual.empty?) }
  ]
end

.contain(expected_val) ⇒ Object



158
159
160
161
162
163
164
165
166
167
# File 'lib/spectre/assertion.rb', line 158

def contain expected_val
  [
    expected_val,
    __method__,
    proc do |expected, actual|
      expected = expected.to_s if actual.is_a? String
      actual.respond_to? :include? and actual.include?(expected)
    end
  ]
end

.match(regex) ⇒ Object



169
170
171
172
173
174
175
# File 'lib/spectre/assertion.rb', line 169

def match regex
  [
    regex,
    __method__,
    proc { |expected, actual| actual.match?(expected) }
  ]
end