Class: Shoulda::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/shoulda_ext/shoulda_patches/context_with_matcher_before_hooks.rb

Instance Method Summary collapse

Instance Method Details

#should(name_or_matcher, options = {}, &blk) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/shoulda_ext/shoulda_patches/context_with_matcher_before_hooks.rb', line 9

def should(name_or_matcher, options = {}, &blk)
  if name_or_matcher.respond_to?(:description) && name_or_matcher.respond_to?(:matches?)
    name = name_or_matcher.description
    blk = lambda { assert_accepts name_or_matcher, subject }
    options[:before] = lambda { name_or_matcher.before } if name_or_matcher.respond_to?(:before)
  else
    name = name_or_matcher
  end

  if blk
    self.shoulds << { :name => name, :before => options[:before], :block => blk }
  else
   self.should_eventuallys << { :name => name }
 end
end

#should_not(matcher) ⇒ Object



25
26
27
28
29
30
# File 'lib/shoulda_ext/shoulda_patches/context_with_matcher_before_hooks.rb', line 25

def should_not(matcher)
  name = matcher.description
  blk = lambda { assert_rejects matcher, subject }
  before = matcher.respond_to?(:before) ? lambda { matcher.before } : nil
  self.shoulds << { :name => "not #{name}", :block => blk, :before => before }
end