Sha256: 0e7e4f7fe64417ddac4fadd287ab78e239b9749d1f7c43c21813dcb136b7b78d

Contents?: true

Size: 1.73 KB

Versions: 35

Compression:

Stored size: 1.73 KB

Contents

require File.dirname(__FILE__) + '/../../spec_helper.rb'

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

Version data entries

35 entries across 35 versions & 5 rubygems

Version Path
dchelimsky-rspec-1.1.11.1 spec/spec/matchers/has_spec.rb
dchelimsky-rspec-1.1.11.2 spec/spec/matchers/has_spec.rb
dchelimsky-rspec-1.1.11.3 spec/spec/matchers/has_spec.rb
dchelimsky-rspec-1.1.11.4 spec/spec/matchers/has_spec.rb
dchelimsky-rspec-1.1.11.5 spec/spec/matchers/has_spec.rb
dchelimsky-rspec-1.1.11.6 spec/spec/matchers/has_spec.rb
dchelimsky-rspec-1.1.11.7 spec/spec/matchers/has_spec.rb
dchelimsky-rspec-1.1.12 spec/spec/matchers/has_spec.rb
dchelimsky-rspec-1.1.99.1 spec/spec/matchers/has_spec.rb
dchelimsky-rspec-1.1.99.13 spec/spec/matchers/has_spec.rb
dchelimsky-rspec-1.1.99.2 spec/spec/matchers/has_spec.rb
dchelimsky-rspec-1.1.99.3 spec/spec/matchers/has_spec.rb
dchelimsky-rspec-1.1.99.4 spec/spec/matchers/has_spec.rb
dchelimsky-rspec-1.1.99.5 spec/spec/matchers/has_spec.rb
dchelimsky-rspec-1.1.99.6 spec/spec/matchers/has_spec.rb
dchelimsky-rspec-1.1.99.7 spec/spec/matchers/has_spec.rb
dchelimsky-rspec-1.1.99.8 spec/spec/matchers/has_spec.rb
dchelimsky-rspec-1.1.99.9 spec/spec/matchers/has_spec.rb
newbamboo-evented-rspec-1.1.12 spec/spec/matchers/has_spec.rb
newbamboo-rspec-1.1.12 spec/spec/matchers/has_spec.rb