Class: Test::Spec::ShouldNot

Inherits:
Object
  • Object
show all
Includes:
Unit::Assertions
Defined in:
lib/test-spec/test/spec.rb

Instance Method Summary collapse

Constructor Details

#initialize(object) ⇒ ShouldNot

Returns a new instance of ShouldNot.



163
164
165
# File 'lib/test-spec/test/spec.rb', line 163

def initialize(object)
  @object = object
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/test-spec/test/spec.rb', line 208

def method_missing(name, *args)
  # This will make raise call Kernel.raise, and self.raise call _raise.
  return _raise(*args)  if name == :raise

  if @object.respond_to?("#{name}?")
    assert_block("#{name}? expected to be false.") {
      not @object.__send__("#{name}?", *args)
    }
  else
    super
  end
end

Instance Method Details

#_raise(*args) ⇒ Object



189
190
191
# File 'lib/test-spec/test/spec.rb', line 189

def _raise(*args)
  assert_nothing_raised(*args, &@object)
end

#be(*value) ⇒ Object



172
173
174
175
176
177
178
179
180
181
# File 'lib/test-spec/test/spec.rb', line 172

def be(*value)
  case value.size
  when 0
    self
  when 1
    assert_not_same value.first, @object
  else
    Kernel.raise ArgumentError, "should.be needs zero or one argument"
  end
end

#equal(value) ⇒ Object Also known as: ==



167
168
169
# File 'lib/test-spec/test/spec.rb', line 167

def equal(value)
  assert_not_equal value, @object
end

#match(value) ⇒ Object Also known as: =~



183
184
185
186
# File 'lib/test-spec/test/spec.rb', line 183

def match(value)
  # Icky Regexp check
  assert_no_match value, @object
end

#nilObject Also known as: be_nil



197
198
199
# File 'lib/test-spec/test/spec.rb', line 197

def nil
  assert_not_nil @object
end

#notObject



203
204
205
# File 'lib/test-spec/test/spec.rb', line 203

def not
  Should.new(@object)
end

#throwObject



193
194
195
# File 'lib/test-spec/test/spec.rb', line 193

def throw
  assert_nothing_thrown(&@object)
end