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



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/motion-spec/context_helper/matchers.rb', line 81

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



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

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

#be_a(test_class) ⇒ Object Also known as: be_an



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

def be_a(test_class)
  MotionSpec::Matcher::BeA.new(test_class)
end

#be_falseObject



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

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

#be_nilObject



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

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

#be_trueObject



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

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

#be_within(range) ⇒ Object



77
78
79
# File 'lib/motion-spec/context_helper/matchers.rb', line 77

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

#change(&change_block) ⇒ Object



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

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

#end_with(substring) ⇒ Object



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

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

#eq(value) ⇒ Object



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

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

#eql(value) ⇒ Object



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

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

#have(number) ⇒ Object



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

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

#include(*values) ⇒ Object



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

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

#match(regex) ⇒ Object



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

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

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



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

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

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



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

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

#respond_to(method_name) ⇒ Object



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

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

#satisfy(&block) ⇒ Object



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

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

#start_with(substring) ⇒ Object



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

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