machine_tag_tag_spec.rb 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. require 'spec_helper'
  2. describe MachineTag::Tag do
  3. it 'should create plain tags' do
  4. tag = MachineTag::Tag.new('a')
  5. expect(tag).to eq 'a'
  6. expect(tag.namespace).to be_nil
  7. expect(tag.predicate).to be_nil
  8. expect(tag.namespace_and_predicate).to be_nil
  9. expect(tag.value).to be_nil
  10. expect(tag.machine_tag?).to be_falsy
  11. end
  12. it 'should create machine tags' do
  13. tag = MachineTag::Tag.new('a:b=c')
  14. expect(tag).to eq 'a:b=c'
  15. expect(tag.namespace).to eq 'a'
  16. expect(tag.predicate).to eq 'b'
  17. expect(tag.namespace_and_predicate).to eq 'a:b'
  18. expect(tag.value).to eq 'c'
  19. expect(tag.machine_tag?).to be_truthy
  20. end
  21. it 'should handle a machine tag with a quoted value' do
  22. tag = MachineTag::Tag.new('a:b="c d"')
  23. expect(tag).to eq 'a:b="c d"'
  24. expect(tag.namespace).to eq 'a'
  25. expect(tag.predicate).to eq 'b'
  26. expect(tag.namespace_and_predicate).to eq 'a:b'
  27. expect(tag.value).to eq 'c d'
  28. expect(tag.machine_tag?).to be_truthy
  29. end
  30. describe '::machine_tag' do
  31. it 'should create machine tags' do
  32. tag = MachineTag::Tag.machine_tag('a', 'b', 'c')
  33. expect(tag).to eq 'a:b=c'
  34. expect(tag.namespace).to eq 'a'
  35. expect(tag.predicate).to eq 'b'
  36. expect(tag.namespace_and_predicate).to eq 'a:b'
  37. expect(tag.value).to eq 'c'
  38. expect(tag.machine_tag?).to be_truthy
  39. end
  40. it 'should not create machine tags with invalid namespaces' do
  41. expect do
  42. MachineTag::Tag.machine_tag('!', 'b', 'c')
  43. end.to raise_error(ArgumentError, 'Invalid machine tag namespace: "!"')
  44. end
  45. it 'should not create machine tags with invalid predicates' do
  46. expect do
  47. MachineTag::Tag.machine_tag('a', '!', 'c')
  48. end.to raise_error(ArgumentError, 'Invalid machine tag predicate: "!"')
  49. end
  50. end
  51. end