Sha256: f794ab862b79f3cc5edb01b1d24d369d6cddd35c89a6e6ccda68852812f2f2c2

Contents?: true

Size: 682 Bytes

Versions: 62

Compression:

Stored size: 682 Bytes

Contents

require 'mspec/guards/guard'

# Despite that these are inverses, the two classes are
# used to simplify MSpec guard reporting modes

class EndianGuard < SpecGuard
  def pattern
    @pattern ||= [1].pack('L')
  end
  private :pattern
end

class BigEndianGuard < EndianGuard
  def match?
    pattern[-1] == ?\001
  end
end

class LittleEndianGuard < EndianGuard
  def match?
    pattern[-1] == ?\000
  end
end

class Object
  def big_endian
    g = BigEndianGuard.new
    g.name = :big_endian
    yield if g.yield?
  ensure
    g.unregister
  end

  def little_endian
    g = LittleEndianGuard.new
    g.name = :little_endian
    yield if g.yield?
  ensure
    g.unregister
  end
end

Version data entries

62 entries across 62 versions & 3 rubygems

Version Path
rhodes-3.5.1.12 lib/extensions/mspec/mspec/guards/endian.rb
rhodes-3.3.5 lib/extensions/mspec/mspec/guards/endian.rb
rhodes-3.4.2 lib/extensions/mspec/mspec/guards/endian.rb
rhodes-3.3.4 lib/extensions/mspec/mspec/guards/endian.rb
rhodes-3.3.3 lib/extensions/mspec/mspec/guards/endian.rb
rhodes-3.3.3.beta.4 lib/extensions/mspec/mspec/guards/endian.rb
rhodes-3.3.3.beta.3 lib/extensions/mspec/mspec/guards/endian.rb
rhodes-3.3.3.beta.2 lib/extensions/mspec/mspec/guards/endian.rb
rhodes-3.3.3.beta.1 lib/extensions/mspec/mspec/guards/endian.rb
rhodes-3.3.2 lib/extensions/mspec/mspec/guards/endian.rb
rhodes-3.3.2.beta.7 lib/extensions/mspec/mspec/guards/endian.rb
rhodes-3.3.2.beta.6 lib/extensions/mspec/mspec/guards/endian.rb
rhodes-3.3.2.beta.5 lib/extensions/mspec/mspec/guards/endian.rb
rhodes-3.3.2.beta.4 lib/extensions/mspec/mspec/guards/endian.rb
rhodes-3.3.2.beta.3 lib/extensions/mspec/mspec/guards/endian.rb
rhodes-3.3.2.beta.2 lib/extensions/mspec/mspec/guards/endian.rb
rhodes-3.3.2.beta.1 lib/extensions/mspec/mspec/guards/endian.rb
rhodes-3.3.1 lib/extensions/mspec/mspec/guards/endian.rb
rhodes-3.3.0 lib/extensions/mspec/mspec/guards/endian.rb
rhodes-3.3.0.beta.3 lib/extensions/mspec/mspec/guards/endian.rb