/spec/job_config_builder_spec.rb

https://github.com/simpsonjulian/jenkins.rb · Ruby · 150 lines · 126 code · 16 blank · 8 comment · 17 complexity · d31d8b2aa56e9560bbd936697ad65e27 MD5 · raw file

  1. require File.dirname(__FILE__) + "/spec_helper"
  2. describe Jenkins::JobConfigBuilder do
  3. include ConfigFixtureLoaders
  4. describe "explicit steps to match a ruby job" do
  5. before do
  6. @config = Jenkins::JobConfigBuilder.new(:rails) do |c|
  7. c.scm = "git://codebasehq.com/mocra/misc/mocra-web.git"
  8. c.steps = [
  9. [:build_shell_step, "step 1"],
  10. [:build_shell_step, "step 2"]
  11. ]
  12. end
  13. end
  14. it "builds config.xml" do
  15. steps = Hpricot.XML(@config.to_xml).search("command")
  16. steps.map(&:inner_text).should == ["step 1", "step 2"]
  17. end
  18. end
  19. describe "rails job; single axis" do
  20. before do
  21. @config = Jenkins::JobConfigBuilder.new(:rails) do |c|
  22. c.scm = "git://codebasehq.com/mocra/misc/mocra-web.git"
  23. end
  24. end
  25. it "builds config.xml" do
  26. config_xml("rails", "single").should == @config.to_xml
  27. end
  28. end
  29. describe "many rubies" do
  30. before do
  31. @config = Jenkins::JobConfigBuilder.new(:ruby) do |c|
  32. c.scm = "http://github.com/drnic/picasa_plucker.git"
  33. c.rubies = %w[1.8.7 1.9.2 rbx-head jruby]
  34. end
  35. end
  36. it "have have explicit rubies" do
  37. config_xml("ruby", "multi").should == @config.to_xml
  38. end
  39. it "and many labels/assigned_nodes" do
  40. @config.node_labels = %w[1.8.7 ubuntu]
  41. config_xml("ruby", "multi-ruby-multi-labels").should == @config.to_xml
  42. end
  43. end
  44. describe "assigned slave nodes for slave usage" do
  45. before do
  46. @config = Jenkins::JobConfigBuilder.new(:rails) do |c|
  47. c.assigned_node = "my-slave"
  48. end
  49. end
  50. it "builds config.xml" do
  51. Hpricot.XML(@config.to_xml).search("assignedNode").size.should == 1
  52. Hpricot.XML(@config.to_xml).search("assignedNode").text.should == "my-slave"
  53. Hpricot.XML(@config.to_xml).search("canRoam").text.should == "false"
  54. end
  55. end
  56. describe "no specific slave nodes" do
  57. before do
  58. @config = Jenkins::JobConfigBuilder.new(:rails) do |c|
  59. end
  60. end
  61. it "builds config.xml" do
  62. Hpricot.XML(@config.to_xml).search("assignedNode").size.should == 0
  63. end
  64. end
  65. describe "SCM behaviour" do
  66. describe "#public_scm = true => convert git@ into git:// until we have deploy keys" do
  67. before do
  68. @config = Jenkins::JobConfigBuilder.new(:rails) do |c|
  69. c.scm = "git@codebasehq.com:mocra/misc/mocra-web.git"
  70. c.public_scm = true
  71. end
  72. end
  73. it "builds config.xml" do
  74. config_xml("rails", "single").should == @config.to_xml
  75. end
  76. end
  77. # <branches>
  78. # <hudson.plugins.git.BranchSpec>
  79. # <name>master</name>
  80. # </hudson.plugins.git.BranchSpec>
  81. # <hudson.plugins.git.BranchSpec>
  82. # <name>other</name>
  83. # </hudson.plugins.git.BranchSpec>
  84. # </branches>
  85. describe "#scm-branches - set branches" do
  86. before do
  87. @config = Jenkins::JobConfigBuilder.new(:rails) do |c|
  88. c.scm = "git@codebasehq.com:mocra/misc/mocra-web.git"
  89. end
  90. end
  91. it "defaults to 'master'" do
  92. branch_names = Hpricot.XML(@config.to_xml).search("branches name")
  93. branch_names.size.should == 1
  94. branch_names.text.should == "master"
  95. branch_names.first.parent.name.should == "hudson.plugins.git.BranchSpec"
  96. end
  97. it "can have specific branches" do
  98. branches = @config.scm_branches = %w[master other branches]
  99. branch_names = Hpricot.XML(@config.to_xml).search("branches name")
  100. branch_names.size.should == 3
  101. branch_names.map(&:inner_text).should == branches
  102. end
  103. end
  104. end
  105. describe "setup ENV variables via envfile plugin" do
  106. before do
  107. @config = Jenkins::JobConfigBuilder.new(:rails) do |c|
  108. c.scm = "git://codebasehq.com/mocra/misc/mocra-web.git"
  109. c.steps = []
  110. c.envfile = "/path/to/env/file"
  111. end
  112. end
  113. it "builds config.xml" do
  114. xml_bite = <<-XML.gsub(/^ /, '')
  115. <buildWrappers>
  116. <hudson.plugins.envfile.EnvFileBuildWrapper>
  117. <filePath>/path/to/env/file</filePath>
  118. </hudson.plugins.envfile.EnvFileBuildWrapper>
  119. </buildWrappers>
  120. XML
  121. Hpricot.XML(@config.to_xml).search("buildWrappers").to_s.should == xml_bite.strip
  122. end
  123. end
  124. describe "erlang job; single axis" do
  125. before do
  126. @config = Jenkins::JobConfigBuilder.new(:erlang) do |c|
  127. c.scm = "git://codebasehq.com/mocra/misc/mocra-web.git"
  128. end
  129. end
  130. it "builds config.xml" do
  131. config_xml("erlang", "single").should == @config.to_xml
  132. end
  133. end
  134. end