Skip to content

Commit

Permalink
Refactor and add acceptance tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cynipe committed Jul 11, 2014
1 parent 6692034 commit 49fd593
Show file tree
Hide file tree
Showing 13 changed files with 938 additions and 165 deletions.
89 changes: 73 additions & 16 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,18 +1,75 @@
# Created by http://www.gitignore.io

### Ruby ###
*.gem
*.rbc
.bundle
.config
.yardoc
Gemfile.lock
InstalledFiles
_yardoc
coverage
doc/
lib/bundler/man
pkg
rdoc
spec/reports
test/tmp
test/version_tmp
tmp
vendor
/.config
/coverage/
/InstalledFiles
/pkg/
/spec/reports/
/test/tmp/
/test/version_tmp/
/tmp/
/example/Gemfile.lock

## Specific to RubyMotion:
.dat*
.repl_history
build/

## Documentation cache and generated files:
/.yardoc/
/_yardoc/
/doc/
/rdoc/

## Environment normalisation:
/.bundle/
/lib/bundler/man/

# for a library or gem, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# Gemfile.lock
# .ruby-version
# .ruby-gemset

# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
.rvmrc


### OSX ###
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear on external disk
.Spotlight-V100
.Trashes

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk


### Vagrant ###
.vagrant/


### vim ###
[._]*.s[a-w][a-z]
[._]s[a-w][a-z]
*.un~
Session.vim
.netrwhist
*~

Expand Down
23 changes: 23 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box_url = 'https://github.com/2creatives/vagrant-centos/releases/download/v6.5.3/centos65-x86_64-20140116.box'
config.vm.box = 'centos65-x86_64-20140116'

config.vm.provider :virtualbox do |vb|
vb.customize ['modifyvm', :id, '--memory', '512']
end

config.vm.network 'forwarded_port', guest: 8080, host: 8080
config.vm.provision :shell, :inline => (<<-SCRIPT).gsub(/^ */, '')
curl -o /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo >/dev/null 2&>1
rpm --import http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key
yum -y install java-1.7.0-openjdk jenkins
service jenkins start
SCRIPT
end

162 changes: 162 additions & 0 deletions features/config_jobs.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
Feature: Configuring Jobs

Scenario: Configuring jobs to newly created Jenkins
Given the plain Jenkins server
And a file named "Capfile" with:
"""
require 'jenkins-capistrano'
load 'config/deploy'
"""
And a file named "config/deploy.rb" with:
"""
set :jenkins_host, 'http://localhost:8080'
"""
And a file named "config/jenkins/jobs/job1.xml" with:
"""
<?xml version="1.0" encoding="UTF-8"?><project>
<actions/>
<description>Created</description>
<keepDependencies>false</keepDependencies>
<properties/>
<scm class="hudson.scm.NullSCM"/>
<canRoam>true</canRoam>
<disabled>false</disabled>
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
<jdk>Default</jdk>
<triggers/>
<concurrentBuild>false</concurrentBuild>
<builders/>
<publishers/>
</project>
"""
When I successfully run `bundle exec cap jenkins:config_jobs`
Then the output should contain:
"""
job job1 created.
"""
And the Jenkins has following jobs:
| Name | Description | Disabled |
| job1 | Created | false |

Scenario: Configuring jobs already created
Given the Jenkins server has following jobs:
| Name | Description | Disabled |
| job1 | Created | false |
And a file named "Capfile" with:
"""
require 'jenkins-capistrano'
load 'config/deploy'
"""
And a file named "config/deploy.rb" with:
"""
set :jenkins_host, 'http://localhost:8080'
"""
And a file named "config/jenkins/jobs/job1.xml" with:
"""
<?xml version="1.0" encoding="UTF-8"?><project>
<actions/>
<description>Updated</description>
<keepDependencies>false</keepDependencies>
<properties/>
<scm class="hudson.scm.NullSCM"/>
<canRoam>true</canRoam>
<disabled>false</disabled>
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
<jdk>Default</jdk>
<triggers/>
<concurrentBuild>false</concurrentBuild>
<builders/>
<publishers/>
</project>
"""
When I successfully run `bundle exec cap jenkins:config_jobs`
Then the Jenkins has following jobs:
| Name | Description | Disabled |
| job1 | Updated | false |
And the output should contain:
"""
job job1 created.
"""

Scenario: Disabling the specified job
Given the plain Jenkins server
And a file named "Capfile" with:
"""
require 'jenkins-capistrano'
load 'config/deploy'
"""
And a file named "config/deploy.rb" with:
"""
set :jenkins_host, 'http://localhost:8080'
set :disabled_jobs, %w(job1)
"""
And a file named "config/jenkins/jobs/job1.xml" with:
"""
<?xml version="1.0" encoding="UTF-8"?><project>
<actions/>
<description>Disabled</description>
<keepDependencies>false</keepDependencies>
<properties/>
<scm class="hudson.scm.NullSCM"/>
<canRoam>true</canRoam>
<disabled>false</disabled>
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
<jdk>Default</jdk>
<triggers/>
<concurrentBuild>false</concurrentBuild>
<builders/>
<publishers/>
</project>
"""
When I successfully run `bundle exec cap jenkins:config_jobs`
Then the Jenkins has following jobs:
| Name | Description | Disabled |
| job1 | Disabled | true |
And the output should contain:
"""
job job1 created.
-> disabled
"""

Scenario: Configuring the jobs with teamplated config.xmls
Given the plain Jenkins server
And a file named "Capfile" with:
"""
require 'jenkins-capistrano'
load 'config/deploy'
"""
And a file named "config/deploy.rb" with:
"""
set :jenkins_host, 'http://localhost:8080'
set :jenkins_template_vars, { :templated => 'Yay!!' }
"""
And a file named "config/jenkins/jobs/job1.xml.erb" with:
"""
<?xml version="1.0" encoding="UTF-8"?><project>
<actions/>
<description><%= @templated %></description>
<keepDependencies>false</keepDependencies>
<properties/>
<scm class="hudson.scm.NullSCM"/>
<canRoam>true</canRoam>
<disabled>false</disabled>
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
<jdk>Default</jdk>
<triggers/>
<concurrentBuild>false</concurrentBuild>
<builders/>
<publishers/>
</project>
"""
When I successfully run `bundle exec cap jenkins:config_jobs`
Then the Jenkins has following jobs:
| Name | Description | Disabled |
| job1 | Yay!! | false |
And the output should contain:
"""
job job1 created.
"""
Loading

0 comments on commit 49fd593

Please sign in to comment.