Sha256: 2c358836f5d74461474808e495a39e803d961c67d034f4d5ef540a0e02d4a1c0

Contents?: true

Size: 1.74 KB

Versions: 23

Compression:

Stored size: 1.74 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 Spec::Matchers::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

23 entries across 23 versions & 7 rubygems

Version Path
dchelimsky-rspec-1.1.10 spec/spec/matchers/has_spec.rb
dchelimsky-rspec-1.1.11 spec/spec/matchers/has_spec.rb
jnstq-acts_as_sms-0.1.0 test/vendor/plugins/rspec/spec/spec/matchers/has_spec.rb
jnstq-acts_as_sms-0.1.1 test/vendor/plugins/rspec/spec/spec/matchers/has_spec.rb
jnstq-acts_as_sms-0.1.3 test/vendor/plugins/rspec/spec/spec/matchers/has_spec.rb
jnstq-acts_as_sms-0.1.4 test/vendor/plugins/rspec/spec/spec/matchers/has_spec.rb
merb-core-1.1.3 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/spec/spec/matchers/has_spec.rb
merb-core-1.1.2 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/spec/spec/matchers/has_spec.rb
merb-core-1.1.1 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/spec/spec/matchers/has_spec.rb
merb-core-1.1.0 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/spec/spec/matchers/has_spec.rb
merb-core-1.1.0.rc1 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/spec/spec/matchers/has_spec.rb
merb-core-1.1.0.pre spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/spec/spec/matchers/has_spec.rb
mack-0.8.2 lib/gems/rspec-1.1.11/spec/spec/matchers/has_spec.rb
pictrails-0.5.0 vendor/plugins/rspec/spec/spec/matchers/has_spec.rb
rspec-1.1.10 spec/spec/matchers/has_spec.rb
rspec-1.1.6 spec/spec/matchers/has_spec.rb
rspec-1.1.5 spec/spec/matchers/has_spec.rb
rspec-1.1.7 spec/spec/matchers/has_spec.rb
rspec-1.1.11 spec/spec/matchers/has_spec.rb
rspec-1.1.8 spec/spec/matchers/has_spec.rb