Skip to content

Commit

Permalink
move jenkins under ci namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
BowenMa committed Aug 31, 2011
1 parent eab793a commit 97f4ef2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 31 deletions.
2 changes: 1 addition & 1 deletion lib/jenkins-remote-api.rb
@@ -1,3 +1,3 @@
require 'mechanize'
require 'libxml'
Dir[File.dirname(__FILE__) + '/jenkins-remote-api/*.rb'].each {|file| require file }
Dir[File.dirname(__FILE__) + '/jenkins-remote-api/ci/*.rb'].each {|file| require file }
23 changes: 23 additions & 0 deletions lib/jenkins-remote-api/ci/jenkins.rb
@@ -0,0 +1,23 @@
module Ci
class Jenkins
include LibXML

def self.set_ci_addr(url)
@@ci_addr = url.end_with?("/") ? url : url + "/"
end

def self.ci_addr
@@ci_addr
end

def self.list_all_job_names
xml = ""
Mechanize.new.get(ci_addr + "api/xml") do |page|
xml = page.body
end
parser = LibXML::XML::Parser.string(xml)
doc = parser.parse
doc.find('//job').collect{|job| job.find_first('name').content }
end
end
end
22 changes: 0 additions & 22 deletions lib/jenkins-remote-api/jenkins.rb

This file was deleted.

16 changes: 8 additions & 8 deletions spec/jenkins_spec.rb
@@ -1,20 +1,20 @@
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe Jenkins do
describe Ci::Jenkins do

it "should set Jenkins ci address" do
Jenkins.set_ci_addr("http://some_ci_address:8080/")
Jenkins.ci_addr.should == "http://some_ci_address:8080/"
Ci::Jenkins.set_ci_addr("http://some_ci_address:8080/")
Ci::Jenkins.ci_addr.should == "http://some_ci_address:8080/"
end

it "should set Jenkins ci address end with slash" do
Jenkins.set_ci_addr("http://some_ci_address:8080")
Jenkins.ci_addr.should == "http://some_ci_address:8080/"
it "should set Ci::Jenkins ci address end with slash" do
Ci::Jenkins.set_ci_addr("http://some_ci_address:8080")
Ci::Jenkins.ci_addr.should == "http://some_ci_address:8080/"
end

it "should get all job's names for specific ci" do
ci_addr = "http://deadlock.netbeans.org/hudson/"
Jenkins.set_ci_addr(ci_addr)
Ci::Jenkins.set_ci_addr(ci_addr)
mechanize = mock("Mechanize")
Mechanize.stub(:new).and_return(mechanize)
xml = <<EOF
Expand All @@ -40,6 +40,6 @@
result = mock("some xml ouput")
result.stub(:body).and_return(xml)
mechanize.should_receive(:get).with(ci_addr + "api/xml").and_yield(result)
Jenkins.list_all_job_names.should == ["analytics-server", "apitest"]
Ci::Jenkins.list_all_job_names.should == ["analytics-server", "apitest"]
end
end

0 comments on commit 97f4ef2

Please sign in to comment.