Sha256: 42267517cda8938af6fb6a5662f06735da6192e9a3e8bae188b5393b9832ce0f

Contents?: true

Size: 1.15 KB

Versions: 2

Compression:

Stored size: 1.15 KB

Contents

# Adds the ability to define a 'before' method on a matcher and allow 
# it to be run before the subject/setup phase of the current context
# 
# Pull Request for getting this functionality into shoulda-context
# https://github.com/thoughtbot/shoulda-context/pull/2
module Shoulda
  class Context
    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

    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
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
socialcast_shoulda_ext-0.1.4 lib/shoulda_ext/shoulda_patches/context_with_matcher_before_hooks.rb
socialcast_shoulda_ext-0.1.2 lib/shoulda_ext/shoulda_patches/context_with_matcher_before_hooks.rb