Sha256: 7d9d3f36c5d73d676a79323aaf61c91f40babce55449ee58c8ef6fbe1866a5b9

Contents?: true

Size: 793 Bytes

Versions: 7

Compression:

Stored size: 793 Bytes

Contents

RSpec::Matchers.define :have_constant do | const, klass |
  match do | owner |
    const_defined = owner.const_defined?( const )
    klass_match = owner.const_get( const ).class == klass unless klass.nil?
    klass.nil? ? const_defined : ( const_defined && klass_match )
  end

  failure_message_for_should do | actual |
    msg = "constant #{ expected[ 0 ] } not defined in #{ actual }"
    msg += " as a #{ expected[ 1 ] }" unless expected[ 1 ].nil?
    msg
  end

  failure_message_for_should_not do | actual |
    msg = "constant #{ expected[ 0 ] } is defined in #{ actual }"
    msg += " as a #{ expected[ 1 ] }" unless expected[ 1 ].nil?
    msg
  end

  description do
    msg = "have constant #{ const }"
    msg += " defined with class #{ klass }" unless klass.nil?
    msg
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
trema-0.4.6 spec/support/matchers/constant.rb
trema-0.4.5 spec/support/matchers/constant.rb
trema-0.4.4 spec/support/matchers/constant.rb
trema-0.4.3 spec/support/matchers/constant.rb
trema-0.4.2 spec/support/matchers/constant.rb
trema-0.4.1 spec/support/matchers/constant.rb
trema-0.4.0 spec/support/matchers/constant.rb