Class: Easytest::Expectation

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

Instance Method Summary collapse

Instance Method Details

#notObject



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_emptyObject



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_falseObject



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_nilObject



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_trueObject



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

Raises:



64
65
66
67
68
69
70
# File 'lib/easytest/expectation.rb', line 64

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_nothingObject

Raises:



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

#to_satisfy(&expected) ⇒ Object



60
61
62
# File 'lib/easytest/expectation.rb', line 60

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