akqa-jenkins 0.6.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. data/.gitignore +8 -0
  2. data/Changelog.md +54 -0
  3. data/Gemfile +3 -0
  4. data/Gemfile.lock +56 -0
  5. data/README.md +159 -0
  6. data/Rakefile +82 -0
  7. data/bin/jenkins +11 -0
  8. data/cucumber.yml +8 -0
  9. data/features/build_details.feature +42 -0
  10. data/features/configure.feature +36 -0
  11. data/features/default_host.feature +26 -0
  12. data/features/development.feature +14 -0
  13. data/features/launch_server.feature +16 -0
  14. data/features/listing_jobs.feature +34 -0
  15. data/features/manage_jobs.feature +214 -0
  16. data/features/manage_slave_nodes.feature +82 -0
  17. data/features/step_definitions/common_steps.rb +192 -0
  18. data/features/step_definitions/fixture_project_steps.rb +8 -0
  19. data/features/step_definitions/jenkins_steps.rb +116 -0
  20. data/features/step_definitions/scm_steps.rb +12 -0
  21. data/features/support/common.rb +37 -0
  22. data/features/support/env.rb +19 -0
  23. data/features/support/hooks.rb +16 -0
  24. data/features/support/jenkins_helpers.rb +6 -0
  25. data/features/support/matchers.rb +10 -0
  26. data/fixtures/jenkins/envfile.hpi +0 -0
  27. data/fixtures/jenkins/git.hpi +0 -0
  28. data/fixtures/jenkins/github.hpi +0 -0
  29. data/fixtures/jenkins/greenballs.hpi +0 -0
  30. data/fixtures/jenkins/rake.hpi +0 -0
  31. data/fixtures/jenkins/ruby.hpi +0 -0
  32. data/fixtures/projects/erlang/rebar.config +1 -0
  33. data/fixtures/projects/non-bundler/Rakefile +4 -0
  34. data/fixtures/projects/rails-3/.gitignore +4 -0
  35. data/fixtures/projects/rails-3/Gemfile +30 -0
  36. data/fixtures/projects/rails-3/Gemfile.lock +74 -0
  37. data/fixtures/projects/rails-3/README +256 -0
  38. data/fixtures/projects/rails-3/Rakefile +7 -0
  39. data/fixtures/projects/rails-3/app/controllers/application_controller.rb +3 -0
  40. data/fixtures/projects/rails-3/app/helpers/application_helper.rb +2 -0
  41. data/fixtures/projects/rails-3/app/views/layouts/application.html.erb +14 -0
  42. data/fixtures/projects/rails-3/config.ru +4 -0
  43. data/fixtures/projects/rails-3/config/application.rb +42 -0
  44. data/fixtures/projects/rails-3/config/boot.rb +13 -0
  45. data/fixtures/projects/rails-3/config/database.yml +22 -0
  46. data/fixtures/projects/rails-3/config/environment.rb +5 -0
  47. data/fixtures/projects/rails-3/config/environments/development.rb +26 -0
  48. data/fixtures/projects/rails-3/config/environments/production.rb +49 -0
  49. data/fixtures/projects/rails-3/config/environments/test.rb +35 -0
  50. data/fixtures/projects/rails-3/config/initializers/backtrace_silencers.rb +7 -0
  51. data/fixtures/projects/rails-3/config/initializers/inflections.rb +10 -0
  52. data/fixtures/projects/rails-3/config/initializers/mime_types.rb +5 -0
  53. data/fixtures/projects/rails-3/config/initializers/secret_token.rb +7 -0
  54. data/fixtures/projects/rails-3/config/initializers/session_store.rb +8 -0
  55. data/fixtures/projects/rails-3/config/locales/en.yml +5 -0
  56. data/fixtures/projects/rails-3/config/routes.rb +58 -0
  57. data/fixtures/projects/rails-3/db/seeds.rb +7 -0
  58. data/fixtures/projects/rails-3/doc/README_FOR_APP +2 -0
  59. data/fixtures/projects/rails-3/lib/tasks/.gitkeep +0 -0
  60. data/fixtures/projects/rails-3/public/404.html +26 -0
  61. data/fixtures/projects/rails-3/public/422.html +26 -0
  62. data/fixtures/projects/rails-3/public/500.html +26 -0
  63. data/fixtures/projects/rails-3/public/favicon.ico +0 -0
  64. data/fixtures/projects/rails-3/public/images/rails.png +0 -0
  65. data/fixtures/projects/rails-3/public/index.html +239 -0
  66. data/fixtures/projects/rails-3/public/javascripts/application.js +2 -0
  67. data/fixtures/projects/rails-3/public/javascripts/controls.js +965 -0
  68. data/fixtures/projects/rails-3/public/javascripts/dragdrop.js +974 -0
  69. data/fixtures/projects/rails-3/public/javascripts/effects.js +1123 -0
  70. data/fixtures/projects/rails-3/public/javascripts/prototype.js +6001 -0
  71. data/fixtures/projects/rails-3/public/javascripts/rails.js +175 -0
  72. data/fixtures/projects/rails-3/public/robots.txt +5 -0
  73. data/fixtures/projects/rails-3/public/stylesheets/.gitkeep +0 -0
  74. data/fixtures/projects/rails-3/script/rails +6 -0
  75. data/fixtures/projects/rails-3/test/performance/browsing_test.rb +9 -0
  76. data/fixtures/projects/rails-3/test/test_helper.rb +13 -0
  77. data/fixtures/projects/rails-3/vendor/plugins/.gitkeep +0 -0
  78. data/fixtures/projects/ruby/Gemfile +3 -0
  79. data/fixtures/projects/ruby/Gemfile.lock +10 -0
  80. data/fixtures/projects/ruby/Rakefile +4 -0
  81. data/jenkins.gemspec +33 -0
  82. data/lib/jenkins.rb +6 -0
  83. data/lib/jenkins/api.rb +250 -0
  84. data/lib/jenkins/cli.rb +291 -0
  85. data/lib/jenkins/cli/formatting.rb +53 -0
  86. data/lib/jenkins/config.rb +27 -0
  87. data/lib/jenkins/core_ext/hash.rb +9 -0
  88. data/lib/jenkins/core_ext/object/blank.rb +77 -0
  89. data/lib/jenkins/hudson-cli.jar +0 -0
  90. data/lib/jenkins/job_config_builder.rb +292 -0
  91. data/lib/jenkins/project_scm.rb +22 -0
  92. data/lib/jenkins/remote.rb +11 -0
  93. data/lib/jenkins/version.rb +3 -0
  94. data/spec/fixtures/ec2_global.config.xml +103 -0
  95. data/spec/fixtures/erlang.single.config.xml +59 -0
  96. data/spec/fixtures/rails.multi.config.xml +82 -0
  97. data/spec/fixtures/rails.single.config.triggers.xml +84 -0
  98. data/spec/fixtures/rails.single.config.xml +80 -0
  99. data/spec/fixtures/ruby.multi-ruby-multi-labels.config.xml +84 -0
  100. data/spec/fixtures/ruby.multi.config.xml +77 -0
  101. data/spec/fixtures/ruby.single.config.xml +58 -0
  102. data/spec/fixtures/therubyracer.config.xml +77 -0
  103. data/spec/hash_key_cleaner_spec.rb +25 -0
  104. data/spec/job_config_builder_spec.rb +150 -0
  105. data/spec/spec_helper.rb +15 -0
  106. metadata +283 -0
@@ -0,0 +1,26 @@
1
+ Feature: Display default host information
2
+
3
+ Scenario: Display default host information if it is setup
4
+ Given I run local executable "jenkins" with arguments "configure --host localhost --port 3010"
5
+ When I run local executable "jenkins" with arguments "default_host"
6
+ Then I should see exactly
7
+ """
8
+ http://localhost:3010
9
+ """
10
+
11
+ Scenario: Display default secure host information if it is setup
12
+ Given I run local executable "jenkins" with arguments "configure --host localhost --port 3010 --ssl"
13
+ When I run local executable "jenkins" with arguments "default_host"
14
+ Then I should see exactly
15
+ """
16
+ https://localhost:3010
17
+ """
18
+
19
+ Scenario: Display warning if never used Jenkins.rb before
20
+ When I run local executable "jenkins" with arguments "default_host"
21
+ Then I should see exactly
22
+ """
23
+ ERROR: Either use --host or add remote servers.
24
+ """
25
+
26
+
@@ -0,0 +1,14 @@
1
+ Feature: Development processes of jenkins itself (rake tasks)
2
+
3
+ As a Newgem maintainer or contributor
4
+ I want rake tasks to maintain and release the gem
5
+ So that I can spend time on the tests and code, and not excessive time on maintenance processes
6
+
7
+ Scenario: Generate RubyGem
8
+ Given this project is active project folder
9
+ When I invoke task "rake clean" so that I start with nothing
10
+ And I invoke task "rake build"
11
+ Then file with name matching "pkg/jenkins-*.gem" is created
12
+ And file with name matching "jenkins.gemspec" is created
13
+ And the file "jenkins.gemspec" is a valid gemspec
14
+
@@ -0,0 +1,16 @@
1
+ Feature: Running a Jenkins Server
2
+ As a jenkins server administrator
3
+ I want to be able to easily control a jenkins server
4
+ In order to spend my time on how the process operates, not how to start stop and control it.
5
+
6
+ Scenario: Start a Jenkins Server (jenkins server)
7
+ Given env variable $HOME set to project path "home"
8
+ And "home/.jenkins" folder is deleted
9
+ And there is nothing listening on port 5001
10
+ And there is nothing listening on port 5002
11
+ And I cleanup any jenkins processes with control port 5002
12
+ When I run jenkins server with arguments "--port 5001 --control 5002 --daemon --logfile=server.log"
13
+ Then I should see a jenkins server on port 5001
14
+ And folder "home/.jenkins/server" is created
15
+ And folder "home/.jenkins/server/javatmp" is created
16
+
@@ -0,0 +1,34 @@
1
+ Feature: Listing jobs
2
+ I want to see the status of jobs on servers I'm interested in
3
+
4
+ Scenario: List jobs on a non-existent server (jenkins list)
5
+ When I run local executable "jenkins" with arguments "list --host localhost --port 9999"
6
+ Then I should see exactly
7
+ """
8
+ No connection available to the server.
9
+ """
10
+
11
+ Scenario: List jobs on a server with no jobs (jenkins list)
12
+ Given I have a Jenkins server running
13
+ And the Jenkins server has no current jobs
14
+ When I run local executable "jenkins" with arguments "list --host localhost --port 3010"
15
+ Then I should see exactly
16
+ """
17
+ http://localhost:3010: no jobs
18
+ """
19
+
20
+ Scenario: List jobs on a server with jobs (jenkins list)
21
+ Given I have a Jenkins server running
22
+ And the Jenkins server has no current jobs
23
+ And I am in the "ruby" project folder
24
+ And the project uses "git" scm
25
+ When I run local executable "jenkins" with arguments "create . --host localhost --port 3010"
26
+ When I run local executable "jenkins" with arguments "list"
27
+ Then I should see exactly
28
+ """
29
+ http://localhost:3010:
30
+ * ruby
31
+
32
+ """
33
+
34
+
@@ -0,0 +1,214 @@
1
+ Feature: Create and manage jobs
2
+ In order to reduce cost of getting a new project up onto Jenkins
3
+ As a project developer
4
+ I want to add a new project to Jenkins as a job
5
+
6
+ Background:
7
+ Given I have a Jenkins server running
8
+ And the Jenkins server has no current jobs
9
+
10
+ Scenario: Setup jenkins job for git scm (jenkins create)
11
+ Given I am in the "ruby" project folder
12
+ And the project uses "git" scm
13
+ When I run local executable "jenkins" with arguments "create . --host localhost --port 3010"
14
+ Then I should see exactly
15
+ """
16
+ Added ruby project 'ruby' to Jenkins.
17
+ Triggering initial build...
18
+ Trigger additional builds via:
19
+ URL: http://localhost:3010/job/ruby/build
20
+ CLI: jenkins build ruby
21
+ """
22
+ When I run local executable "jenkins" with arguments "list --host localhost --port 3010"
23
+ Then I should see "ruby"
24
+
25
+ Scenario: Create job via $JENKINS_HOST and $JENKINS_PORT (jenkins create)
26
+ Given I am in the "ruby" project folder
27
+ And the project uses "git" scm
28
+ And env variable $JENKINS_HOST set to "localhost"
29
+ And env variable $JENKINS_PORT set to "3010"
30
+ When I run local executable "jenkins" with arguments "create ."
31
+ Then I should see "http://localhost:3010/job/ruby/build"
32
+ When I run local executable "jenkins" with arguments "list"
33
+ Then I should see "ruby"
34
+
35
+ Scenario: Don't trigger initial job build (jenkins create --no-build)
36
+ Given I am in the "ruby" project folder
37
+ And the project uses "git" scm
38
+ When I run local executable "jenkins" with arguments "create . --no-build --host localhost --port 3010"
39
+ Then I should see exactly
40
+ """
41
+ Added ruby project 'ruby' to Jenkins.
42
+ Trigger builds via:
43
+ URL: http://localhost:3010/job/ruby/build
44
+ CLI: jenkins build ruby
45
+ """
46
+
47
+ Scenario: Setup jenkins job with explicit scm url/branches (jenkins create --scm URI --scm-branches='master,other')
48
+ Given I am in the "ruby" project folder
49
+ And the project uses "git" scm
50
+ When I run local executable "jenkins" with arguments "create . --scm git://localhost/myapp.git --scm-branches 'master,other' --host localhost --port 3010"
51
+ Then I should see "Added ruby project 'ruby' to Jenkins."
52
+ And the job "ruby" config "scm" should be:
53
+ """
54
+ <scm class="hudson.plugins.git.GitSCM">
55
+ <configVersion>1</configVersion>
56
+ <remoteRepositories>
57
+ <org.spearce.jgit.transport.RemoteConfig>
58
+ <string>origin</string>
59
+ <int>5</int>
60
+ <string>fetch</string>
61
+ <string>+refs/heads/*:refs/remotes/origin/*</string>
62
+ <string>receivepack</string>
63
+ <string>git-upload-pack</string>
64
+ <string>uploadpack</string>
65
+ <string>git-upload-pack</string>
66
+ <string>url</string>
67
+ <string>git://localhost/myapp.git</string>
68
+ <string>tagopt</string>
69
+ <string></string>
70
+ </org.spearce.jgit.transport.RemoteConfig>
71
+ </remoteRepositories>
72
+ <branches>
73
+ <hudson.plugins.git.BranchSpec>
74
+ <name>master</name>
75
+ </hudson.plugins.git.BranchSpec>
76
+ <hudson.plugins.git.BranchSpec>
77
+ <name>other</name>
78
+ </hudson.plugins.git.BranchSpec>
79
+ </branches>
80
+ <localBranch></localBranch>
81
+ <mergeOptions />
82
+ <recursiveSubmodules>false</recursiveSubmodules>
83
+ <doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations>
84
+ <authorOrCommitter>false</authorOrCommitter>
85
+ <clean>false</clean>
86
+ <wipeOutWorkspace>false</wipeOutWorkspace>
87
+ <pruneBranches>false</pruneBranches>
88
+ <buildChooser class="hudson.plugins.git.util.DefaultBuildChooser" />
89
+ <gitTool>Default</gitTool>
90
+ <submoduleCfg class="list" />
91
+ <relativeTargetDir></relativeTargetDir>
92
+ <excludedRegions></excludedRegions>
93
+ <excludedUsers></excludedUsers>
94
+ </scm>
95
+ """
96
+
97
+ Scenario: Setup jenkins job with multiple rubies (jenkins create --rubies '1.8.7,rbx-head,jruby')
98
+ Given I am in the "ruby" project folder
99
+ And the project uses "git" scm
100
+ When I run local executable "jenkins" with arguments "create . --rubies '1.8.7,rbx-head,jruby' --host localhost --port 3010"
101
+ Then I should see "Added ruby project 'ruby' to Jenkins."
102
+ And the job "ruby" config "axes" should be:
103
+ """
104
+ <axes>
105
+ <hudson.matrix.TextAxis>
106
+ <name>RUBY_VERSION</name>
107
+ <values>
108
+ <string>1.8.7</string>
109
+ <string>rbx-head</string>
110
+ <string>jruby</string>
111
+ </values>
112
+ </hudson.matrix.TextAxis>
113
+ </axes>
114
+ """
115
+
116
+ Scenario: Setup jenkins job with multiple rubies and multiple nodes (jenkins create --rubies.. --node_labels..)
117
+ Given I am in the "ruby" project folder
118
+ And the project uses "git" scm
119
+ When I run local executable "jenkins" with arguments "create . --rubies '1.8.7,rbx-head,jruby' --node-labels '1.8.7,ubuntu' --host localhost --port 3010"
120
+ Then I should see "Added ruby project 'ruby' to Jenkins."
121
+ And the job "ruby" config "axes" should be:
122
+ """
123
+ <axes>
124
+ <hudson.matrix.TextAxis>
125
+ <name>RUBY_VERSION</name>
126
+ <values>
127
+ <string>1.8.7</string>
128
+ <string>rbx-head</string>
129
+ <string>jruby</string>
130
+ </values>
131
+ </hudson.matrix.TextAxis>
132
+ <hudson.matrix.LabelAxis>
133
+ <name>label</name>
134
+ <values>
135
+ <string>1.8.7</string>
136
+ <string>ubuntu</string>
137
+ </values>
138
+ </hudson.matrix.LabelAxis>
139
+ </axes>
140
+ """
141
+
142
+ Scenario: Setup jenkins job for a specific node label (jenkins create --assigned_node)
143
+ Given I am in the "ruby" project folder
144
+ And the project uses "git" scm
145
+ When I run local executable "jenkins" with arguments "create . --assigned_node my_node --host localhost --port 3010"
146
+ Then I should see "Added ruby project 'ruby' to Jenkins."
147
+
148
+ Scenario: Select 'rails3' project type (jenkins create --template rails3)
149
+ Given I am in the "rails-3" project folder
150
+ And the project uses "git" scm
151
+ When I run local executable "jenkins" with arguments "create . --template rails3 --host localhost --port 3010"
152
+ Then I should see "Added rails3 project 'rails-3' to Jenkins."
153
+
154
+ Scenario: Select 'erlang' project type (jenkins create --template erlang)
155
+ Given I am in the "erlang" project folder
156
+ And the project uses "git" scm
157
+ When I run local executable "jenkins" with arguments "create . --template erlang --host localhost --port 3010"
158
+ Then I should see "Added erlang project 'erlang' to Jenkins."
159
+
160
+ Scenario: Create job without default steps (jenkins create --no-template)
161
+ Given I am in the "non-bundler" project folder
162
+ And the project uses "git" scm
163
+ When I run local executable "jenkins" with arguments "create . --no-template --host localhost --port 3010"
164
+ Then I should see "Added project 'non-bundler' to Jenkins."
165
+ And the job "non-bundler" config "builders" should be:
166
+ """
167
+ <builders>
168
+ <hudson.tasks.Shell>
169
+ <command>echo &quot;THERE ARE NO STEPS! Except this one...&quot;</command>
170
+ </hudson.tasks.Shell>
171
+ </builders>
172
+ """
173
+
174
+ Scenario: Reject projects that don't use bundler (jenkins create)
175
+ Given I am in the "non-bundler" project folder
176
+ And the project uses "git" scm
177
+ When I run local executable "jenkins" with arguments "create . --host localhost --port 3010"
178
+ Then I should see "Ruby/Rails projects without a Gemfile are currently unsupported."
179
+
180
+ Scenario: Attempt to create project without scm (jenkins create)
181
+ Given I am in the "ruby" project folder
182
+ When I run local executable "jenkins" with arguments "create . --host localhost --port 3010"
183
+ Then I should see "Cannot determine project SCM. Currently supported:"
184
+
185
+ Scenario: Recreate a job (jenkins create --override)
186
+ Given I am in the "ruby" project folder
187
+ When I create a job
188
+ Then I should see "Added ruby project 'ruby' to Jenkins."
189
+ When I recreate a job
190
+ Then I should see "Added ruby project 'ruby' to Jenkins."
191
+
192
+ Scenario: Trigger a job build (jenkins build)
193
+ Given I am in the "ruby" project folder
194
+ When I create a job
195
+ When I run local executable "jenkins" with arguments "build"
196
+ Then I should see "Build for 'ruby' running now..."
197
+
198
+ Scenario: Trigger a job build on invaild project (jenkins build)
199
+ Given I am in the "ruby" project folder
200
+ When I run local executable "jenkins" with arguments "build . --host localhost --port 3010"
201
+ Then I should see "ERROR: No job 'ruby' on server."
202
+
203
+ Scenario: Remove a job (jenkins remove)
204
+ Given I am in the "ruby" project folder
205
+ When I create a job
206
+ Then I should see "Added ruby project 'ruby' to Jenkins."
207
+ When I run local executable "jenkins" with arguments "remove ."
208
+ Then I should see "Removed project 'ruby' from Jenkins."
209
+
210
+ Scenario: Remove a job that doesn't exist gives error (jenkins remove)
211
+ Given I am in the "ruby" project folder
212
+ When I run local executable "jenkins" with arguments "remove . --host localhost --port 3010"
213
+ Then I should see "ERROR: Failed to delete project 'ruby'."
214
+
@@ -0,0 +1,82 @@
1
+ Feature: Adding slave nodes
2
+ In order to have different environments for different projects
3
+ As a developer
4
+ I want to add new slave nodes to my Jenkins instance
5
+
6
+ Background:
7
+ Given I have a Jenkins server running
8
+ And the Jenkins server has no slaves
9
+ When I run local executable "jenkins" with arguments "nodes --host localhost --port 3010"
10
+ Then I should see exactly
11
+ """
12
+ master
13
+ """
14
+
15
+ Scenario: Add slave via API (jenkins nodes)
16
+ When I create a new node with the following options on "http://localhost:3010":
17
+ | name | Slave 1 |
18
+ | label | app1 app2 app3 |
19
+ | slave_host | foo1.bar.com |
20
+ | slave_user | jenkins |
21
+ When I run local executable "jenkins" with arguments "nodes"
22
+ Then I should see exactly
23
+ """
24
+ master
25
+ Slave 1
26
+ """
27
+
28
+ Scenario: Add slave via CLI with name defaulted to URL (jenkins add_node)
29
+ When I run local executable "jenkins" with arguments "add_node foo1.bar.com --slave-user deploy --labels 'app1,app2'"
30
+ Then I should see exactly
31
+ """
32
+ Added slave node 'foo1.bar.com' to foo1.bar.com
33
+ """
34
+ When I run local executable "jenkins" with arguments "add_node foo1.bar.com --slave-user deploy --labels 'app1,app2'"
35
+ Then I should see exactly
36
+ """
37
+ Slave called 'foo1.bar.com' already exists
38
+ ERROR: Failed to add slave node foo1.bar.com
39
+ """
40
+ When I run local executable "jenkins" with arguments "nodes"
41
+ Then I should see exactly
42
+ """
43
+ master
44
+ foo1.bar.com
45
+ """
46
+
47
+ @wip
48
+ Scenario: Add a local Vagrant/VirtualBox VM as a slave (jenkins add_node --vagrant)
49
+ Given I am in the "rails-3" project folder
50
+ When I run local executable "jenkins" with arguments "add_node localhost --name rails-3 --vagrant --labels 'app1,app2'"
51
+ Then I should see exactly
52
+ """
53
+ Added slave node 'rails-3' to localhost
54
+ """
55
+ When I run local executable "jenkins" with arguments "nodes"
56
+ Then I should see exactly
57
+ """
58
+ master
59
+ rails-3
60
+ """
61
+ And the Jenkins config "slaves" should be:
62
+ """
63
+ <slaves>
64
+ <slave>
65
+ <name>rails-3</name>
66
+ <description>Automatically created by Jenkins.rb</description>
67
+ <remoteFS>/vagrant/tmp/jenkins-slave/</remoteFS>
68
+ <numExecutors>2</numExecutors>
69
+ <mode>EXCLUSIVE</mode>
70
+ <retentionStrategy class="hudson.slaves.RetentionStrategy$Always" />
71
+ <launcher class="hudson.plugins.sshslaves.SSHLauncher">
72
+ <host>localhost</host>
73
+ <port>2222</port>
74
+ <username>vagrant</username>
75
+ <password>rvDV+OTiBj3UtK5p7sl62Q==</password>
76
+ <privatekey>/Library/Ruby/Gems/1.8/gems/vagrant-0.6.7/keys/vagrant</privatekey>
77
+ </launcher>
78
+ <label>app1 app2</label>
79
+ <nodeProperties />
80
+ </slave>
81
+ </slaves>
82
+ """
@@ -0,0 +1,192 @@
1
+
2
+ Given /^this project is active project folder/ do
3
+ @active_project_folder = File.expand_path(File.dirname(__FILE__) + "/../..")
4
+ end
5
+
6
+ Given /^env variable \$([\w_]+) set to( project path|) "(.*)"/ do |env_var, path, value|
7
+ in_project_folder {
8
+ value = File.expand_path(value)
9
+ } unless path.empty?
10
+ ENV[env_var] = value
11
+ end
12
+
13
+ Given /"(.*)" folder is deleted/ do |folder|
14
+ in_project_folder { FileUtils.rm_rf folder }
15
+ end
16
+
17
+ When /^I invoke "(.*)" generator with arguments "(.*)"$/ do |generator, arguments|
18
+ @stdout = StringIO.new
19
+ in_project_folder do
20
+ if Object.const_defined?("APP_ROOT")
21
+ APP_ROOT.replace(FileUtils.pwd)
22
+ else
23
+ APP_ROOT = FileUtils.pwd
24
+ end
25
+ run_generator(generator, arguments.split(' '), SOURCES, :stdout => @stdout)
26
+ end
27
+ File.open(File.join(@tmp_root, "generator.out"), "w") do |f|
28
+ @stdout.rewind
29
+ f << @stdout.read
30
+ end
31
+ end
32
+
33
+ When /^I run executable "(.*)" with arguments "(.*)"/ do |executable, arguments|
34
+ @stdout = File.expand_path(File.join(@tmp_root, "executable.out"))
35
+ in_project_folder do
36
+ system "#{executable.inspect} #{arguments} > #{@stdout.inspect} 2> #{@stdout.inspect}"
37
+ end
38
+ end
39
+
40
+ When /^I run project executable "(.*)" with arguments "(.*)"/ do |executable, arguments|
41
+ @stdout = File.expand_path(File.join(@tmp_root, "executable.out"))
42
+ in_project_folder do
43
+ system "ruby #{executable.inspect} #{arguments} > #{@stdout.inspect} 2> #{@stdout.inspect}"
44
+ end
45
+ end
46
+
47
+ When /^I run local executable "(.*)" with arguments "(.*)"/ do |executable, arguments|
48
+ @stdout = File.expand_path(File.join(@tmp_root, "executable.out"))
49
+ executable = File.expand_path(File.join(File.dirname(__FILE__), "/../../bin", executable))
50
+ in_project_folder do
51
+ system "ruby #{executable.inspect} #{arguments} > #{@stdout.inspect} 2> #{@stdout.inspect}"
52
+ end
53
+ end
54
+
55
+ When /^I invoke task "rake (.*)"/ do |task|
56
+ @stdout = File.expand_path(File.join(@tmp_root, "tests.out"))
57
+ in_project_folder do
58
+ system "rake #{task} --trace > #{@stdout.inspect} 2> #{@stdout.inspect}"
59
+ end
60
+ end
61
+
62
+ Then /^folder "(.*)" (is|is not) created/ do |folder, is|
63
+ in_project_folder do
64
+ File.exists?(folder).should(is == 'is' ? be_true : be_false)
65
+ end
66
+ end
67
+
68
+ Then /^file "(.*)" (is|is not) created/ do |file, is|
69
+ in_project_folder do
70
+ File.exists?(file).should(is == 'is' ? be_true : be_false)
71
+ end
72
+ end
73
+
74
+ Then /^file with name matching "(.*)" is created/ do |pattern|
75
+ in_project_folder do
76
+ Dir[pattern].should_not be_empty
77
+ end
78
+ end
79
+
80
+ Then /^file "(.*)" contents (does|does not) match \/(.*)\// do |file, does, regex|
81
+ in_project_folder do
82
+ actual_output = File.read(file)
83
+ (does == 'does') ?
84
+ actual_output.should(match(/#{regex}/)) :
85
+ actual_output.should_not(match(/#{regex}/))
86
+ end
87
+ end
88
+
89
+ Then /gem file "(.*)" and generated file "(.*)" should be the same/ do |gem_file, project_file|
90
+ File.exists?(gem_file).should be_true
91
+ File.exists?(project_file).should be_true
92
+ gem_file_contents = File.read(File.dirname(__FILE__) + "/../../#{gem_file}")
93
+ project_file_contents = File.read(File.join(@active_project_folder, project_file))
94
+ project_file_contents.should == gem_file_contents
95
+ end
96
+
97
+ Then /^(does|does not) invoke generator "(.*)"$/ do |does_invoke, generator|
98
+ actual_output = get_command_output
99
+ does_invoke == "does" ?
100
+ actual_output.should(match(/dependency\s+#{generator}/)) :
101
+ actual_output.should_not(match(/dependency\s+#{generator}/))
102
+ end
103
+
104
+ Then /help options "(.*)" and "(.*)" are displayed/ do |opt1, opt2|
105
+ actual_output = get_command_output
106
+ actual_output.should match(/#{opt1}/)
107
+ actual_output.should match(/#{opt2}/)
108
+ end
109
+
110
+ Then /^I should see "([^\"]*)"$/ do |text|
111
+ actual_output = get_command_output
112
+ actual_output.should contain(text)
113
+ end
114
+
115
+ Then /^I should not see "([^\"]*)"$/ do |text|
116
+ actual_output =
117
+ actual_output.should_not contain(text)
118
+ end
119
+
120
+ Then /^I should see$/ do |text|
121
+ actual_output = get_command_output
122
+ actual_output.should contain(text)
123
+ end
124
+
125
+ Then /^I should not see$/ do |text|
126
+ actual_output = get_command_output
127
+ actual_output.should_not contain(text)
128
+ end
129
+
130
+ Then /^I should see exactly$/ do |text|
131
+ actual_output = get_command_output
132
+ actual_output.should == text
133
+ end
134
+
135
+ Then /^I should see all (\d+) tests pass/ do |expected_test_count|
136
+ expected = %r{^#{expected_test_count} tests, \d+ assertions, 0 failures, 0 errors}
137
+ actual_output = get_command_output
138
+ actual_output.should match(expected)
139
+ end
140
+
141
+ Then /^I should see all (\d+) examples pass/ do |expected_test_count|
142
+ expected = %r{^#{expected_test_count} examples?, 0 failures}
143
+ actual_output = get_command_output
144
+ actual_output.should match(expected)
145
+ end
146
+
147
+ Then /^yaml file "(.*)" contains (\{.*\})/ do |file, yaml|
148
+ in_project_folder do
149
+ yaml = eval yaml
150
+ YAML.load(File.read(file)).should == yaml
151
+ end
152
+ end
153
+
154
+ Then /^Rakefile can display tasks successfully/ do
155
+ @stdout = File.expand_path(File.join(@tmp_root, "rakefile.out"))
156
+ in_project_folder do
157
+ system "rake -T > #{@stdout.inspect} 2> #{@stdout.inspect}"
158
+ end
159
+ actual_output = get_command_output
160
+ actual_output.should match(/^rake\s+\w+\s+#\s.*/)
161
+ end
162
+
163
+ Then /^task "rake (.*)" is executed successfully/ do |task|
164
+ @stdout.should_not be_nil
165
+ actual_output = get_command_output
166
+ actual_output.should_not match(/^Don't know how to build task '#{task}'/)
167
+ actual_output.should_not match(/Error/i)
168
+ end
169
+
170
+ Then /^gem spec key "(.*)" contains \/(.*)\// do |key, regex|
171
+ in_project_folder do
172
+ gem_file = Dir["pkg/*.gem"].first
173
+ gem_spec = Gem::Specification.from_yaml(`gem spec #{gem_file}`)
174
+ spec_value = gem_spec.send(key.to_sym)
175
+ spec_value.to_s.should match(/#{regex}/)
176
+ end
177
+ end
178
+
179
+ Then /^the file "([^\"]*)" is a valid gemspec$/ do |filename|
180
+ spec = eval(File.read(filename))
181
+ spec.validate
182
+ end
183
+
184
+ When /^I create a new node with the following options on "http:\/\/(.+?):(\d+)":$/ do |host, port, table|
185
+ options = table.raw.inject({}) do |options, (key, value)|
186
+ options[(key.to_sym rescue key) || key] = value
187
+ options
188
+ end
189
+
190
+ Jenkins::Api.setup_base_url(:host => host, :port => port.to_i)
191
+ Jenkins::Api.add_node(options)
192
+ end