Sha256: cf65b43b99b03d6d82203c6b9c0c76ca8b2b786fac4fc6f167ece19865b38273

Contents?: true

Size: 1.68 KB

Versions: 9

Compression:

Stored size: 1.68 KB

Contents

module Micronaut
  module Matchers
    
    # wraps an expectation in a block that will return true if the
    # expectation passes and false if it fails (without bubbling up
    # the failure).
    #     
    # This is intended to be used in the context of a simple matcher,
    # and is especially useful for wrapping multiple expectations or
    # one or more assertions from test/unit extensions when running
    # with test/unit.
    #
    # == Examples
    #
    #   def eat_cheese(cheese)
    #     simple_matcher do |mouse, matcher|
    #       matcher.negative_failure_message = "expected #{mouse} not to eat cheese"
    #       wrap_expectation do |matcher|
    #         assert_eats_cheese(mouse)
    #       end
    #     end
    #   end
    #
    #   describe Mouse do
    #     it "eats cheese" do
    #       Mouse.new.should eat_cheese
    #     end
    #   end
    #
    # You might be wondering "why would I do this if I could just say"
    # assert_eats_cheese?", a fair question, indeed. You might prefer
    # to replace the word assert with something more aligned with the
    # rest of your code examples. You are using rspec, after all.
    #
    # The other benefit you get is that you can use the negative version
    # of the matcher:
    #
    #   describe Cat do
    #     it "does not eat cheese" do
    #       Cat.new.should_not eat_cheese
    #     end
    #   end
    #
    # So in the event there is no assert_does_not_eat_cheese available,
    # you're all set!
    def wrap_expectation(matcher, &block)
      begin
        block.call(matcher)
        return true
      rescue Exception => e
        matcher.failure_message = e.message
        return false
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
spicycode-micronaut-0.0.3 lib/micronaut/expectations/wrap_expectation.rb
spicycode-micronaut-0.0.4 lib/micronaut/expectations/wrap_expectation.rb
spicycode-micronaut-0.0.5 lib/micronaut/expectations/wrap_expectation.rb
spicycode-micronaut-0.0.6 lib/micronaut/expectations/wrap_expectation.rb
spicycode-micronaut-0.0.7 lib/micronaut/expectations/wrap_expectation.rb
spicycode-micronaut-0.0.9 lib/micronaut/expectations/wrap_expectation.rb
spicycode-micronaut-0.1.0 lib/micronaut/expectations/wrap_expectation.rb
spicycode-micronaut-0.1.1 lib/micronaut/expectations/wrap_expectation.rb
spicycode-micronaut-0.1.2 lib/micronaut/expectations/wrap_expectation.rb