PageRenderTime 52ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/spec/lib/gitlab/dependency_linker/requirements_txt_linker_spec.rb

https://gitlab.com/YarNayar/gitlab-ce
Ruby | 95 lines | 68 code | 11 blank | 16 comment | 2 complexity | 2c3e6e145a01140d1b1e2f1f4285d82d MD5 | raw file
  1. require 'rails_helper'
  2. describe Gitlab::DependencyLinker::RequirementsTxtLinker, lib: true do
  3. describe '.support?' do
  4. it 'supports requirements.txt' do
  5. expect(described_class.support?('requirements.txt')).to be_truthy
  6. end
  7. it 'supports doc-requirements.txt' do
  8. expect(described_class.support?('doc-requirements.txt')).to be_truthy
  9. end
  10. it 'does not support other files' do
  11. expect(described_class.support?('requirements')).to be_falsey
  12. end
  13. end
  14. describe '#link' do
  15. let(:file_name) { "requirements.txt" }
  16. let(:file_content) do
  17. <<-CONTENT.strip_heredoc
  18. #
  19. ####### example-requirements.txt #######
  20. #
  21. ###### Requirements without Version Specifiers ######
  22. nose
  23. nose-cov
  24. beautifulsoup4
  25. #
  26. ###### Requirements with Version Specifiers ######
  27. # See https://www.python.org/dev/peps/pep-0440/#version-specifiers
  28. docopt == 0.6.1 # Version Matching. Must be version 0.6.1
  29. keyring >= 4.1.1 # Minimum version 4.1.1
  30. coverage != 3.5 # Version Exclusion. Anything except version 3.5
  31. Mopidy-Dirble ~= 1.1 # Compatible release. Same as >= 1.1, == 1.*
  32. #
  33. ###### Refer to other requirements files ######
  34. -r other-requirements.txt
  35. #
  36. #
  37. ###### A particular file ######
  38. ./downloads/numpy-1.9.2-cp34-none-win32.whl
  39. http://wxpython.org/Phoenix/snapshot-builds/wxPython_Phoenix-3.0.3.dev1820+49a8884-cp34-none-win_amd64.whl
  40. #
  41. ###### Additional Requirements without Version Specifiers ######
  42. # Same as 1st section, just here to show that you can put things in any order.
  43. rejected
  44. green
  45. #
  46. Jinja2>=2.3
  47. Pygments>=1.2
  48. Sphinx>=1.3
  49. docutils>=0.7
  50. markupsafe
  51. pytest~=3.0
  52. foop!=3.0
  53. CONTENT
  54. end
  55. subject { Gitlab::Highlight.highlight(file_name, file_content) }
  56. def link(name, url)
  57. %{<a href="#{url}" rel="nofollow noreferrer noopener" target="_blank">#{name}</a>}
  58. end
  59. it 'links dependencies' do
  60. expect(subject).to include(link('nose', 'https://pypi.python.org/pypi/nose'))
  61. expect(subject).to include(link('nose-cov', 'https://pypi.python.org/pypi/nose-cov'))
  62. expect(subject).to include(link('beautifulsoup4', 'https://pypi.python.org/pypi/beautifulsoup4'))
  63. expect(subject).to include(link('docopt', 'https://pypi.python.org/pypi/docopt'))
  64. expect(subject).to include(link('keyring', 'https://pypi.python.org/pypi/keyring'))
  65. expect(subject).to include(link('coverage', 'https://pypi.python.org/pypi/coverage'))
  66. expect(subject).to include(link('Mopidy-Dirble', 'https://pypi.python.org/pypi/Mopidy-Dirble'))
  67. expect(subject).to include(link('rejected', 'https://pypi.python.org/pypi/rejected'))
  68. expect(subject).to include(link('green', 'https://pypi.python.org/pypi/green'))
  69. expect(subject).to include(link('Jinja2', 'https://pypi.python.org/pypi/Jinja2'))
  70. expect(subject).to include(link('Pygments', 'https://pypi.python.org/pypi/Pygments'))
  71. expect(subject).to include(link('Sphinx', 'https://pypi.python.org/pypi/Sphinx'))
  72. expect(subject).to include(link('docutils', 'https://pypi.python.org/pypi/docutils'))
  73. expect(subject).to include(link('markupsafe', 'https://pypi.python.org/pypi/markupsafe'))
  74. expect(subject).to include(link('pytest', 'https://pypi.python.org/pypi/pytest'))
  75. expect(subject).to include(link('foop', 'https://pypi.python.org/pypi/foop'))
  76. end
  77. it 'links URLs' do
  78. expect(subject).to include(link('http://wxpython.org/Phoenix/snapshot-builds/wxPython_Phoenix-3.0.3.dev1820+49a8884-cp34-none-win_amd64.whl', 'http://wxpython.org/Phoenix/snapshot-builds/wxPython_Phoenix-3.0.3.dev1820+49a8884-cp34-none-win_amd64.whl'))
  79. end
  80. it 'does not contain link with a newline as package name' do
  81. expect(subject).not_to include(link("\n", "https://pypi.python.org/pypi/\n"))
  82. end
  83. end
  84. end