Class: Easytest::Expectation
- Inherits:
-
Object
- Object
- Easytest::Expectation
- Defined in:
- sig/easytest.rbs,
lib/easytest/expectation.rb
Overview
An expectation in test cases.
Instance Method Summary collapse
-
#not ⇒ Expectation
Negate this expectation.
-
#to_be(expected) ⇒ Object
Expect to be the same as the given object.
-
#to_be_a(expected) ⇒ void
Expect to be an instance of the given class (module) or its subclasses.
-
#to_be_empty ⇒ void
Expect to be empty.
-
#to_be_false ⇒ void
Expect to be
false. -
#to_be_instance_of(expected) ⇒ void
Expect to be an instance of the given class (module).
-
#to_be_kind_of(expected) ⇒ void
Expect to be an instance of the given class (module) or its subclasses.
-
#to_be_nil ⇒ void
Expect to be
nil. -
#to_be_true ⇒ void
Expect to be
true. -
#to_contain_exactly(*expected) ⇒ void
Expect to contain all the given items regardless of order.
-
#to_eq(expected) ⇒ void
(also: #to_equal)
Expect to equal the given object.
-
#to_have_attributes(**expected) ⇒ void
Expect to have the given attributes.
-
#to_include(expected) ⇒ void
Expect to include the given object.
-
#to_match(expected) ⇒ void
Expect to match the given object.
-
#to_raise(expected, with_message = nil) ⇒ Object
Expect to raise the given exception or an exception with the given message.
-
#to_raise_nothing ⇒ void
Expect to raise nothing.
-
#to_satisfy {|actual| ... } ⇒ void
Expect to satisfy a condition that the given block returns
true.
Instance Method Details
#not ⇒ Expectation
Negate this expectation.
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.
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.
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_empty ⇒ void
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_false ⇒ void
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).
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.
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_nil ⇒ void
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_true ⇒ void
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.
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.
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.
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.
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.
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.
77 78 79 80 81 82 83 |
# File 'sig/easytest.rbs', line 77 def to_raise(expected, = 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: ).match! end |
#to_raise_nothing ⇒ void
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 |