Module: MotionSpec::ContextHelper::Matchers

Included in:
MotionSpec::Context
Defined in:
lib/motion-spec/context_helper/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



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/motion-spec/context_helper/matchers.rb', line 76

def method_missing(method_name, *args, &block)
  string_method_name = method_name.to_s
  match_be = string_method_name.match(/^be_(.*)/)

  if match_be
    return MotionSpec::Matcher::BeGeneric.new(match_be[1], *args)
  end

  match_have = string_method_name.match(/^have_(.*)/)

  if match_have
    return MotionSpec::Matcher::HaveGeneric.new(match_have[1], *args)
  end

  super
  # raise "method name not found #{method_name}"
end

Instance Method Details

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



26
27
28
# File 'lib/motion-spec/context_helper/matchers.rb', line 26

def be(value)
  MotionSpec::Matcher::Be.new(value)
end

#be_falseObject



13
14
15
# File 'lib/motion-spec/context_helper/matchers.rb', line 13

def be_false
  MotionSpec::Matcher::BeFalse.new
end

#be_nilObject



5
6
7
# File 'lib/motion-spec/context_helper/matchers.rb', line 5

def be_nil
  MotionSpec::Matcher::BeNil.new
end

#be_trueObject



9
10
11
# File 'lib/motion-spec/context_helper/matchers.rb', line 9

def be_true
  MotionSpec::Matcher::BeTrue.new
end

#be_within(range) ⇒ Object



72
73
74
# File 'lib/motion-spec/context_helper/matchers.rb', line 72

def be_within(range)
  MotionSpec::Matcher::BeWithin.new(range)
end

#change(&change_block) ⇒ Object



68
69
70
# File 'lib/motion-spec/context_helper/matchers.rb', line 68

def change(&change_block)
  MotionSpec::Matcher::Change.new(change_block)
end

#end_with(substring) ⇒ Object



64
65
66
# File 'lib/motion-spec/context_helper/matchers.rb', line 64

def end_with(substring)
  MotionSpec::Matcher::EndWith.new(substring)
end

#eq(value) ⇒ Object



31
32
33
# File 'lib/motion-spec/context_helper/matchers.rb', line 31

def eq(value)
  MotionSpec::Matcher::Eq.new(value)
end

#eql(value) ⇒ Object



22
23
24
# File 'lib/motion-spec/context_helper/matchers.rb', line 22

def eql(value)
  MotionSpec::Matcher::Eql.new(value)
end

#have(number) ⇒ Object



48
49
50
# File 'lib/motion-spec/context_helper/matchers.rb', line 48

def have(number)
  MotionSpec::Matcher::HaveItems.new(number)
end

#include(*values) ⇒ Object



44
45
46
# File 'lib/motion-spec/context_helper/matchers.rb', line 44

def include(*values)
  MotionSpec::Matcher::Include.new(*values)
end

#match(regex) ⇒ Object



35
36
37
# File 'lib/motion-spec/context_helper/matchers.rb', line 35

def match(regex)
  MotionSpec::Matcher::Match.new(regex)
end

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



39
40
41
# File 'lib/motion-spec/context_helper/matchers.rb', line 39

def match_array(array)
  MotionSpec::Matcher::MatchArray.new(array)
end

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



17
18
19
# File 'lib/motion-spec/context_helper/matchers.rb', line 17

def raise_error(exception_class = Exception, message = '')
  MotionSpec::Matcher::RaiseError.new(exception_class, message)
end

#respond_to(method_name) ⇒ Object



56
57
58
# File 'lib/motion-spec/context_helper/matchers.rb', line 56

def respond_to(method_name)
  MotionSpec::Matcher::RespondTo.new(method_name)
end

#satisfy(&block) ⇒ Object



52
53
54
# File 'lib/motion-spec/context_helper/matchers.rb', line 52

def satisfy(&block)
  MotionSpec::Matcher::Satisfy.new(&block)
end

#start_with(substring) ⇒ Object



60
61
62
# File 'lib/motion-spec/context_helper/matchers.rb', line 60

def start_with(substring)
  MotionSpec::Matcher::StartWith.new(substring)
end