Module: BaconExpect::Matcher::BaconContext

Included in:
Bacon::Context
Defined in:
lib/bacon-expect/matchers/matchers.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/bacon-expect/matchers/matchers.rb', line 75

def method_missing(method_name, *args, &block)
  string_method_name = method_name.to_s
  match_be = string_method_name.match(/^be_(.*)/)
  if match_be
    BeGeneric.new(match_be[1], *args)
  else
    match_have = string_method_name.match(/^have_(.*)/)
    if match_have
      HaveGeneric.new(match_have[1], *args)
    else
      super
    end
  end
end

Instance Method Details

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



25
26
27
# File 'lib/bacon-expect/matchers/matchers.rb', line 25

def be(value)
  Be.new(value)
end

#be_falseObject



12
13
14
# File 'lib/bacon-expect/matchers/matchers.rb', line 12

def be_false
  BeFalse.new
end

#be_nilObject



4
5
6
# File 'lib/bacon-expect/matchers/matchers.rb', line 4

def be_nil
  BeNil.new
end

#be_trueObject



8
9
10
# File 'lib/bacon-expect/matchers/matchers.rb', line 8

def be_true
  BeTrue.new
end

#be_within(range) ⇒ Object



71
72
73
# File 'lib/bacon-expect/matchers/matchers.rb', line 71

def be_within(range)
  BeWithin.new(range)
end

#change(&change_block) ⇒ Object



67
68
69
# File 'lib/bacon-expect/matchers/matchers.rb', line 67

def change(&change_block)
  Change.new(change_block)
end

#end_with(substring) ⇒ Object



63
64
65
# File 'lib/bacon-expect/matchers/matchers.rb', line 63

def end_with(substring)
  EndWith.new(substring)
end

#eq(value) ⇒ Object



30
31
32
# File 'lib/bacon-expect/matchers/matchers.rb', line 30

def eq(value)
  Eq.new(value)
end

#eql(value) ⇒ Object



21
22
23
# File 'lib/bacon-expect/matchers/matchers.rb', line 21

def eql(value)
  Eql.new(value)
end

#have(number) ⇒ Object



47
48
49
# File 'lib/bacon-expect/matchers/matchers.rb', line 47

def have(number)
  HaveItems.new(number)
end

#include(*values) ⇒ Object



43
44
45
# File 'lib/bacon-expect/matchers/matchers.rb', line 43

def include(*values)
  Include.new(*values)
end

#match(regex) ⇒ Object



34
35
36
# File 'lib/bacon-expect/matchers/matchers.rb', line 34

def match(regex)
  Match.new(regex)
end

#match_array(array) ⇒ Object Also known as: contain_exactly



38
39
40
# File 'lib/bacon-expect/matchers/matchers.rb', line 38

def match_array(array)
  MatchArray.new(array)
end

#raise_error(exception_class = Exception, message = "") ⇒ Object Also known as: raise_exception



16
17
18
# File 'lib/bacon-expect/matchers/matchers.rb', line 16

def raise_error(exception_class = Exception, message = "")
  RaiseError.new(exception_class, message)
end

#respond_to(method_name) ⇒ Object



55
56
57
# File 'lib/bacon-expect/matchers/matchers.rb', line 55

def respond_to(method_name)
  RespondTo.new(method_name)
end

#satisfy(&block) ⇒ Object



51
52
53
# File 'lib/bacon-expect/matchers/matchers.rb', line 51

def satisfy(&block)
  Satisfy.new(&block)
end

#start_with(substring) ⇒ Object



59
60
61
# File 'lib/bacon-expect/matchers/matchers.rb', line 59

def start_with(substring)
  StartWith.new(substring)
end