Class: Easytest::Expectation

Inherits:
Object
  • Object
show all
Defined in:
sig/easytest.rbs,
lib/easytest/expectation.rb

Overview

An expectation in test cases.

Instance Method Summary collapse

Instance Method Details

#notExpectation

Negate this expectation.

Returns:



31
32
33
# File 'sig/easytest.rbs', line 31

def not
  self.class.new(actual, negate: true, &block)
end

#to_be(expected) ⇒ Object

Expect to be the same as the given object.

Parameters:

  • expected (Object)

Returns:

  • (Object)


38
39
40
# File 'sig/easytest.rbs', line 38

def to_be(expected)
  Matcher::Be.new(actual: actual, expected: expected, negate: negate).match!
end

#to_be_a(expected) ⇒ void

This method returns an undefined value.

Expect to be an instance of the given class (module) or its subclasses.

Parameters:

  • expected (Module)


50
51
52
# File 'sig/easytest.rbs', line 50

def to_be_a(expected)
  Matcher::BeA.new(actual: actual, expected: expected, negate: negate).match!
end

#to_be_emptyvoid

This method returns an undefined value.

Expect to be empty.



59
60
61
# File 'sig/easytest.rbs', line 59

def to_be_empty
  Matcher::Empty.new(actual: actual, expected: nil, negate: negate).match!
end

#to_be_falsevoid

This method returns an undefined value.

Expect to be false. Same as to_be(false).



44
45
46
# File 'sig/easytest.rbs', line 44

def to_be_false
  Matcher::False.new(actual: actual, expected: false, negate: negate).match!
end

#to_be_instance_of(expected) ⇒ void

This method returns an undefined value.

Expect to be an instance of the given class (module).

Parameters:

  • expected (Module)


56
57
58
# File 'sig/easytest.rbs', line 56

def to_be_instance_of(expected)
  Matcher::InstanceOf.new(actual: actual, expected: expected, negate: negate).match!
end

#to_be_kind_of(expected) ⇒ void

This method returns an undefined value.

Expect to be an instance of the given class (module) or its subclasses.

Parameters:

  • expected (Module)


53
54
55
# File 'sig/easytest.rbs', line 53

def to_be_kind_of(expected)
  Matcher::KindOf.new(actual: actual, expected: expected, negate: negate).match!
end

#to_be_nilvoid

This method returns an undefined value.

Expect to be nil. Same as to_be(nil).



41
42
43
# File 'sig/easytest.rbs', line 41

def to_be_nil
  Matcher::Nil.new(actual: actual, expected: nil, negate: negate).match!
end

#to_be_truevoid

This method returns an undefined value.

Expect to be true. Same as to_be(true).



47
48
49
# File 'sig/easytest.rbs', line 47

def to_be_true
  Matcher::True.new(actual: actual, expected: true, negate: negate).match!
end

#to_contain_exactly(*expected) ⇒ void

This method returns an undefined value.

Expect to contain all the given items regardless of order.

Parameters:

  • expected (Object)


68
69
70
# File 'sig/easytest.rbs', line 68

def to_contain_exactly(*expected)
  Matcher::ContainExactly.new(actual: actual, expected: expected, negate: negate).match!
end

#to_eq(expected) ⇒ void Also known as: to_equal

This method returns an undefined value.

Expect to equal the given object.

Parameters:

  • expected (Object)


34
35
36
# File 'sig/easytest.rbs', line 34

def to_eq(expected)
  Matcher::Equal.new(actual: actual, expected: expected, negate: negate).match!
end

#to_have_attributes(**expected) ⇒ void

This method returns an undefined value.

Expect to have the given attributes.

Parameters:

  • expected (Object)


71
72
73
# File 'sig/easytest.rbs', line 71

def to_have_attributes(**expected)
  Matcher::HaveAttributes.new(actual: actual, expected: expected, negate: negate).match!
end

#to_include(expected) ⇒ void

This method returns an undefined value.

Expect to include the given object.

Parameters:

  • expected (Object)


62
63
64
# File 'sig/easytest.rbs', line 62

def to_include(expected)
  Matcher::Include.new(actual: actual, expected: expected, negate: negate).match!
end

#to_match(expected) ⇒ void

This method returns an undefined value.

Expect to match the given object.

Parameters:

  • expected (Object)


65
66
67
# File 'sig/easytest.rbs', line 65

def to_match(expected)
  Matcher::Match.new(actual: actual, expected: expected, negate: negate).match!
end

#to_raise(expected, with_message) ⇒ void #to_raise(expected) ⇒ void

Expect to raise the given exception or an exception with the given message.

Overloads:

  • #to_raise(expected, with_message) ⇒ void

    This method returns an undefined value.

    Parameters:

    • expected (Class)
    • with_message (?(String | Regexp), nil)
  • #to_raise(expected) ⇒ void

    This method returns an undefined value.

    Parameters:

    • expected (String, Regexp)


77
78
79
80
81
82
83
# File 'sig/easytest.rbs', line 77

def to_raise(expected, with_message = nil)
  raise FatalError, "`to_raise` requires a block like `expect { ... }.to_raise`" unless block
  raise FatalError, "`not.to_raise` can cause a false positive, so use `to_raise_nothing` instead" if negate?
  raise FatalError, "`to_raise` requires a Class, String, or Regexp" unless [Class, String, Regexp].any? { expected.is_a? _1 }

  Matcher::Raise.new(actual: block, expected: expected, negate: negate, with_message: with_message).match!
end

#to_raise_nothingvoid

This method returns an undefined value.

Expect to raise nothing.



81
82
83
84
85
# File 'sig/easytest.rbs', line 81

def to_raise_nothing
  raise FatalError, "`to_raise_nothing` requires a block like `expect { ... }.to_raise_nothing`" unless block

  Matcher::RaiseNothing.new(actual: block).match!
end

#to_satisfy {|actual| ... } ⇒ void

This method returns an undefined value.

Expect to satisfy a condition that the given block returns true.

Yields:

Yield Parameters:

  • actual (Object)

Yield Returns:

  • (boolish)


74
75
76
# File 'sig/easytest.rbs', line 74

def to_satisfy(&expected)
  Matcher::Satisfy.new(actual: actual, expected: expected, negate: negate).match!
end