Sha256: 7a808825fff555f44406044d7b1f09fe1d8d6d4b2e8f3e5adc6aa96e1f1301bf

Contents?: true

Size: 1.89 KB

Versions: 39

Compression:

Stored size: 1.89 KB

Contents

require File.expand_path(File.dirname(__FILE__) + "/../../../example_helper")

describe Micronaut::Matchers do

  describe "should have_sym(*args)" do
    
    it "should pass if #has_sym?(*args) returns true" do
      {:a => "A"}.should have_key(:a)
    end

    it "should fail if #has_sym?(*args) returns false" do
      lambda {
        {:b => "B"}.should have_key(:a)
      }.should fail_with("expected #has_key?(:a) to return true, got false")
    end

    it "should fail if target does not respond to #has_sym?" do
      lambda { Object.new.should have_key(:a) }.should raise_error(NoMethodError)
    end
  
    it "should re-raise an exception thrown in #has_sym?(*args)" do
      o = Object.new
      def o.has_sym?(*args)
        raise "Funky exception"
      end
      lambda { o.should have_sym(:foo) }.should raise_error("Funky exception")
    end
    
  end

  describe "should_not have_sym(*args)" do
    
    it "should pass if #has_sym?(*args) returns false" do
      {:a => "A"}.should_not have_key(:b)
    end

    it "should fail if #has_sym?(*args) returns true" do
      lambda {
        {:a => "A"}.should_not have_key(:a)
      }.should fail_with("expected #has_key?(:a) to return false, got true")
    end

    it "should fail if target does not respond to #has_sym?" do
      lambda {
        Object.new.should have_key(:a)
      }.should raise_error(NoMethodError)
    end
  
    it "should reraise an exception thrown in #has_sym?(*args)" do
      o = Object.new
      def o.has_sym?(*args)
        raise "Funky exception"
      end
      lambda { o.should_not have_sym(:foo) }.should raise_error("Funky exception")
    end
    
  end

  describe "has" do
    
    it "should work when the target implements #send" do
      o = {:a => "A"}
      def o.send(*args); raise "DOH! Library developers shouldn't use #send!" end
      lambda { o.should have_key(:a) }.should_not raise_error
    end
    
  end

end

Version data entries

39 entries across 39 versions & 2 rubygems

Version Path
spicycode-micronaut-0.1.4.3 examples/lib/micronaut/matchers/has_example.rb
spicycode-micronaut-0.1.4.4 examples/lib/micronaut/matchers/has_example.rb
spicycode-micronaut-0.1.5.2 examples/lib/micronaut/matchers/has_example.rb
spicycode-micronaut-0.1.5 examples/lib/micronaut/matchers/has_example.rb
spicycode-micronaut-0.1.6.1 examples/lib/micronaut/matchers/has_example.rb
spicycode-micronaut-0.1.6.8 examples/lib/micronaut/matchers/has_example.rb
spicycode-micronaut-0.1.6.9.1 examples/lib/micronaut/matchers/has_example.rb
spicycode-micronaut-0.1.6.9 examples/lib/micronaut/matchers/has_example.rb
spicycode-micronaut-0.1.6 examples/lib/micronaut/matchers/has_example.rb
spicycode-micronaut-0.1.7.1 examples/lib/micronaut/matchers/has_example.rb
spicycode-micronaut-0.1.7.2 examples/lib/micronaut/matchers/has_example.rb
spicycode-micronaut-0.1.7.3 examples/lib/micronaut/matchers/has_example.rb
spicycode-micronaut-0.1.7.4 examples/lib/micronaut/matchers/has_example.rb
spicycode-micronaut-0.1.7 examples/lib/micronaut/matchers/has_example.rb
spicycode-micronaut-0.1.8.0 examples/lib/micronaut/matchers/has_example.rb
spicycode-micronaut-0.1.8.1 examples/lib/micronaut/matchers/has_example.rb
spicycode-micronaut-0.1.8.2 examples/lib/micronaut/matchers/has_example.rb
spicycode-micronaut-0.1.8.3 examples/lib/micronaut/matchers/has_example.rb
spicycode-micronaut-0.1.8.5 examples/lib/micronaut/matchers/has_example.rb
spicycode-micronaut-0.1.9.0 examples/lib/micronaut/matchers/has_example.rb