Class: Easytest::Expectation
- Inherits:
-
Object
- Object
- Easytest::Expectation
- Defined in:
- lib/easytest/expectation.rb
Instance Method Summary collapse
- #not ⇒ Object
- #to_be(expected) ⇒ Object
- #to_be_a(expected) ⇒ Object
- #to_be_empty ⇒ Object
- #to_be_false ⇒ Object
- #to_be_instance_of(expected) ⇒ Object
- #to_be_kind_of(expected) ⇒ Object
- #to_be_nil ⇒ Object
- #to_be_true ⇒ Object
- #to_contain_exactly(*expected) ⇒ Object
- #to_eq(expected) ⇒ Object (also: #to_equal)
- #to_have_attributes(**expected) ⇒ Object
- #to_include(expected) ⇒ Object
- #to_match(expected) ⇒ Object
- #to_raise(expected, with_message = nil) ⇒ Object
- #to_raise_nothing ⇒ Object
- #to_satisfy(&expected) ⇒ Object
Instance Method Details
#not ⇒ Object
3 4 5 |
# File 'lib/easytest/expectation.rb', line 3 def not self.class.new(actual, negate: true, &block) end |
#to_be(expected) ⇒ Object
12 13 14 |
# File 'lib/easytest/expectation.rb', line 12 def to_be(expected) Matcher::Be.new(actual: actual, expected: expected, negate: negate).match! end |
#to_be_a(expected) ⇒ Object
28 29 30 |
# File 'lib/easytest/expectation.rb', line 28 def to_be_a(expected) Matcher::BeA.new(actual: actual, expected: expected, negate: negate).match! end |
#to_be_empty ⇒ Object
40 41 42 |
# File 'lib/easytest/expectation.rb', line 40 def to_be_empty Matcher::Empty.new(actual: actual, expected: nil, negate: negate).match! end |
#to_be_false ⇒ Object
24 25 26 |
# File 'lib/easytest/expectation.rb', line 24 def to_be_false Matcher::False.new(actual: actual, expected: false, negate: negate).match! end |
#to_be_instance_of(expected) ⇒ Object
36 37 38 |
# File 'lib/easytest/expectation.rb', line 36 def to_be_instance_of(expected) Matcher::InstanceOf.new(actual: actual, expected: expected, negate: negate).match! end |
#to_be_kind_of(expected) ⇒ Object
32 33 34 |
# File 'lib/easytest/expectation.rb', line 32 def to_be_kind_of(expected) Matcher::KindOf.new(actual: actual, expected: expected, negate: negate).match! end |
#to_be_nil ⇒ Object
16 17 18 |
# File 'lib/easytest/expectation.rb', line 16 def to_be_nil Matcher::Nil.new(actual: actual, expected: nil, negate: negate).match! end |
#to_be_true ⇒ Object
20 21 22 |
# File 'lib/easytest/expectation.rb', line 20 def to_be_true Matcher::True.new(actual: actual, expected: true, negate: negate).match! end |
#to_contain_exactly(*expected) ⇒ Object
52 53 54 |
# File 'lib/easytest/expectation.rb', line 52 def to_contain_exactly(*expected) Matcher::ContainExactly.new(actual: actual, expected: expected, negate: negate).match! end |
#to_eq(expected) ⇒ Object Also known as: to_equal
7 8 9 |
# File 'lib/easytest/expectation.rb', line 7 def to_eq(expected) Matcher::Equal.new(actual: actual, expected: expected, negate: negate).match! end |
#to_have_attributes(**expected) ⇒ Object
56 57 58 |
# File 'lib/easytest/expectation.rb', line 56 def to_have_attributes(**expected) Matcher::HaveAttributes.new(actual: actual, expected: expected, negate: negate).match! end |
#to_include(expected) ⇒ Object
44 45 46 |
# File 'lib/easytest/expectation.rb', line 44 def to_include(expected) Matcher::Include.new(actual: actual, expected: expected, negate: negate).match! end |
#to_match(expected) ⇒ Object
48 49 50 |
# File 'lib/easytest/expectation.rb', line 48 def to_match(expected) Matcher::Match.new(actual: actual, expected: expected, negate: negate).match! end |
#to_raise(expected, with_message = nil) ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/easytest/expectation.rb', line 64 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 ⇒ Object
72 73 74 75 76 |
# File 'lib/easytest/expectation.rb', line 72 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 |