PageRenderTime 26ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/gems/capistrano-2.5.9/test/task_definition_test.rb

https://github.com/wangmh/webistrano
Ruby | 101 lines | 81 code | 20 blank | 0 comment | 0 complexity | cb32f1d8dc6bca8101f0933a521628c4 MD5 | raw file
  1. require "utils"
  2. require 'capistrano/task_definition'
  3. class TaskDefinitionTest < Test::Unit::TestCase
  4. def setup
  5. @namespace = namespace
  6. end
  7. def test_fqn_at_top_level_should_be_task_name
  8. task = new_task(:testing)
  9. assert_equal "testing", task.fully_qualified_name
  10. end
  11. def test_fqn_in_namespace_should_include_namespace_fqn
  12. ns = namespace("outer:inner")
  13. task = new_task(:testing, ns)
  14. assert_equal "outer:inner:testing", task.fully_qualified_name
  15. end
  16. def test_fqn_at_top_level_when_default_should_be_default
  17. task = new_task(:default)
  18. assert_equal "default", task.fully_qualified_name
  19. end
  20. def test_fqn_in_namespace_when_default_should_be_namespace_fqn
  21. ns = namespace("outer:inner")
  22. task = new_task(:default, ns)
  23. ns.stubs(:default_task => task)
  24. assert_equal "outer:inner", task.fully_qualified_name
  25. end
  26. def test_task_should_require_block
  27. assert_raises(ArgumentError) do
  28. Capistrano::TaskDefinition.new(:testing, @namespace)
  29. end
  30. end
  31. def test_description_should_return_empty_string_if_not_given
  32. assert_equal "", new_task(:testing).description
  33. end
  34. def test_description_should_return_desc_attribute
  35. assert_equal "something", new_task(:testing, @namespace, :desc => "something").description
  36. end
  37. def test_description_should_strip_leading_and_trailing_whitespace
  38. assert_equal "something", new_task(:testing, @namespace, :desc => " something ").description
  39. end
  40. def test_description_should_normalize_newlines
  41. assert_equal "a\nb\nc", new_task(:testing, @namespace, :desc => "a\nb\r\nc").description
  42. end
  43. def test_description_should_detect_and_remove_indentation
  44. desc = <<-DESC
  45. Here is some indented text \
  46. and I want all of this to \
  47. run together on a single line, \
  48. without any extraneous spaces.
  49. additional indentation will
  50. be preserved.
  51. DESC
  52. task = new_task(:testing, @namespace, :desc => desc)
  53. assert_equal "Here is some indented text and I want all of this to run together on a single line, without any extraneous spaces.\n\n additional indentation will\n be preserved.", task.description
  54. end
  55. def test_description_munging_should_be_sensitive_to_code_blocks
  56. desc = <<-DESC
  57. Here is a line \
  58. wrapped with spacing in it.
  59. foo bar
  60. baz bang
  61. DESC
  62. task = new_task(:testing, @namespace, :desc => desc)
  63. assert_equal "Here is a line wrapped with spacing in it.\n\n foo bar\n baz bang", task.description
  64. end
  65. def test_brief_description_should_return_first_sentence_in_description
  66. desc = "This is the task. It does all kinds of things."
  67. task = new_task(:testing, @namespace, :desc => desc)
  68. assert_equal "This is the task.", task.brief_description
  69. end
  70. def test_brief_description_should_truncate_if_length_given
  71. desc = "This is the task that does all kinds of things. And then some."
  72. task = new_task(:testing, @namespace, :desc => desc)
  73. assert_equal "This is the task ...", task.brief_description(20)
  74. end
  75. def test_brief_description_should_not_break_at_period_in_middle_of_sentence
  76. task = new_task(:testing, @namespace, :desc => "Take file.txt and copy it.")
  77. assert_equal "Take file.txt and copy it.", task.brief_description
  78. task = new_task(:testing, @namespace, :desc => "Take file.txt and copy it. Then do something else.")
  79. assert_equal "Take file.txt and copy it.", task.brief_description
  80. end
  81. end