guid_spec.rb 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. require 'rails_helper'
  2. RSpec.describe Ldap::Guid do
  3. let(:string) { 'f742b361-32c6-4a92-baaa-eaae7df657ee' }
  4. let(:hex) { "a\xB3B\xF7\xC62\x92J\xBA\xAA\xEA\xAE}\xF6W\xEE".b }
  5. describe '.valid?' do
  6. it 'responds to .valid?' do
  7. expect(described_class).to respond_to(:valid?)
  8. end
  9. it 'detects valid uid string' do
  10. expect(described_class.valid?(string)).to be true
  11. end
  12. it 'detects invalid uid string' do
  13. invalid = 'AC2342'
  14. expect(described_class.valid?(invalid)).to be false
  15. end
  16. end
  17. describe '.hex' do
  18. it 'responds to .hex' do
  19. expect(described_class).to respond_to(:hex)
  20. end
  21. it 'tunnels to instance method' do
  22. instance = double()
  23. allow(instance).to receive(:hex)
  24. allow(described_class).to receive(:new).with(string).and_return(instance)
  25. described_class.hex(string)
  26. expect(instance).to have_received(:hex)
  27. end
  28. end
  29. describe '.string' do
  30. it 'responds to .string' do
  31. expect(described_class).to respond_to(:string)
  32. end
  33. it 'tunnels to instance method' do
  34. instance = double()
  35. allow(instance).to receive(:string)
  36. allow(described_class).to receive(:new).with(hex).and_return(instance)
  37. described_class.string(hex)
  38. expect(instance).to have_received(:string)
  39. end
  40. end
  41. describe '#string' do
  42. let(:instance) { described_class.new(hex) }
  43. it 'responds to #string' do
  44. expect(instance).to respond_to(:string)
  45. end
  46. it 'converts to string' do
  47. expect(instance.string).to eq(string)
  48. end
  49. end
  50. describe '#hex' do
  51. let(:instance) { described_class.new(string) }
  52. it 'responds to #hex' do
  53. expect(instance).to respond_to(:hex)
  54. end
  55. it 'converts to hex' do
  56. expect(instance.hex).to eq(hex)
  57. end
  58. end
  59. end