guid_spec.rb 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. context '.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. context '.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. expect(instance).to receive(:hex)
  24. expect(described_class).to receive(:new).with(string).and_return(instance)
  25. described_class.hex(string)
  26. end
  27. end
  28. context '.string' do
  29. it 'responds to .string' do
  30. expect(described_class).to respond_to(:string)
  31. end
  32. it 'tunnels to instance method' do
  33. instance = double()
  34. expect(instance).to receive(:string)
  35. expect(described_class).to receive(:new).with(hex).and_return(instance)
  36. described_class.string(hex)
  37. end
  38. end
  39. context '#string' do
  40. let(:instance) { described_class.new(hex) }
  41. it 'responds to #string' do
  42. expect(instance).to respond_to(:string)
  43. end
  44. it 'converts to string' do
  45. expect(instance.string).to eq(string)
  46. end
  47. end
  48. context '#hex' do
  49. let(:instance) { described_class.new(string) }
  50. it 'responds to #hex' do
  51. expect(instance).to respond_to(:hex)
  52. end
  53. it 'converts to hex' do
  54. expect(instance.hex).to eq(hex)
  55. end
  56. end
  57. end