values_at_spec.rb 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. require 'spec_helper_acceptance'
  2. describe 'values_at function' do
  3. describe 'success' do
  4. pp1 = <<-DOC
  5. $one = ['a','b','c','d','e']
  6. $two = 1
  7. $output = values_at($one,$two)
  8. notice(inline_template('<%= @output.inspect %>'))
  9. DOC
  10. it 'returns a specific value' do
  11. expect(apply_manifest(pp1, :catch_failures => true).stdout).to match(%r{\["b"\]})
  12. end
  13. pp2 = <<-DOC
  14. $one = ['a','b','c','d','e']
  15. $two = -1
  16. $output = values_at($one,$two)
  17. notice(inline_template('<%= @output.inspect %>'))
  18. DOC
  19. it 'returns a specific negative index value' do
  20. pending("negative numbers don't work")
  21. expect(apply_manifest(pp2, :catch_failures => true).stdout).to match(%r{\["e"\]})
  22. end
  23. pp3 = <<-DOC
  24. $one = ['a','b','c','d','e']
  25. $two = "1-3"
  26. $output = values_at($one,$two)
  27. notice(inline_template('<%= @output.inspect %>'))
  28. DOC
  29. it 'returns a range of values' do
  30. expect(apply_manifest(pp3, :catch_failures => true).stdout).to match(%r{\["b", "c", "d"\]})
  31. end
  32. pp4 = <<-DOC
  33. $one = ['a','b','c','d','e']
  34. $two = ["1-3",0]
  35. $output = values_at($one,$two)
  36. notice(inline_template('<%= @output.inspect %>'))
  37. DOC
  38. it 'returns a negative specific value and range of values' do
  39. expect(apply_manifest(pp4, :catch_failures => true).stdout).to match(%r{\["b", "c", "d", "a"\]})
  40. end
  41. end
  42. describe 'failure' do
  43. pp5 = <<-DOC
  44. $one = ['a','b','c','d','e']
  45. $output = values_at($one)
  46. notice(inline_template('<%= @output.inspect %>'))
  47. DOC
  48. it 'handles improper number of arguments' do
  49. expect(apply_manifest(pp5, :expect_failures => true).stderr).to match(%r{Wrong number of arguments})
  50. end
  51. pp6 = <<-DOC
  52. $one = ['a','b','c','d','e']
  53. $two = []
  54. $output = values_at($one,$two)
  55. notice(inline_template('<%= @output.inspect %>'))
  56. DOC
  57. it 'handles non-indicies arguments' do
  58. expect(apply_manifest(pp6, :expect_failures => true).stderr).to match(%r{at least one positive index})
  59. end
  60. it 'detects index ranges smaller than the start range'
  61. it 'handles index ranges larger than array'
  62. it 'handles non-integer indicies'
  63. end
  64. end