features/step_definitions/hudson_steps.rb in hudson-0.3.0.beta.14 vs features/step_definitions/hudson_steps.rb in hudson-0.3.0.beta.15
- old
+ new
@@ -1,10 +1,11 @@
Given /^I have a Hudson server running$/ do
unless @hudson_port
port = 3010
begin
res = Net::HTTP.start("localhost", port) { |http| http.get('/api/json') }
+ Hudson::Api.base_uri "http://localhost:#{port}"
rescue Errno::ECONNREFUSED => e
puts "\n\n\nERROR: To run tests, launch hudson in test mode: 'rake hudson:server:test'\n\n\n"
exit
end
@hudson_port = port.to_s
@@ -12,47 +13,31 @@
end
end
Given /^the Hudson server has no current jobs$/ do
if port = @hudson_port
- require "open-uri"
- require "yajl"
- hudson_info = Yajl::Parser.new.parse(open("http://#{@hudson_host}:#{@hudson_port}/api/json"))
-
- hudson_info['jobs'].each do |job|
- job_url = job['url']
- res = Net::HTTP.start("localhost", port) { |http| http.post("#{job_url}doDelete/api/json", {}) }
+ Hudson::Api.summary['jobs'].each do |job|
+ Hudson::Api.delete_job(job['name'])
end
- hudson_info = Yajl::Parser.new.parse(open("http://#{@hudson_host}:#{@hudson_port}/api/json"))
- hudson_info['jobs'].should == []
+ Hudson::Api.summary['jobs'].should == []
else
puts "WARNING: Run 'I have a Hudson server running' step first."
end
end
Given /^the Hudson server has no slaves$/ do
if port = @hudson_port
- require "open-uri"
- require "yajl"
- base_url = "http://#{@hudson_host}:#{@hudson_port}"
- hudson_info = Yajl::Parser.new.parse(open("#{base_url}/api/json"))
- (hudson_info['jobs'] || []).each do |job|
- job_url = job['url']
- res = Net::HTTP.start("localhost", port) { |http| http.post("#{job_url}doDelete/api/json", {}) }
+ Hudson::Api.summary['jobs'].each do |job|
+ Hudson::Api.delete_job(job['name'])
end
- hudson_info = Yajl::Parser.new.parse(open("#{base_url}/api/json"))
- hudson_info['jobs'].should == []
+ Hudson::Api.summary['jobs'].should == []
- hudson_info = Yajl::Parser.new.parse(open("#{base_url}/computer/api/json"))
- hudson_info['computer'].each do |node|
- name = node["displayName"]
- next if name == "master"
- job_url = "#{base_url}/computer/#{CGI::escape(name).gsub('+', '%20')}"
- res = Net::HTTP.start("localhost", port) { |http| http.post("#{job_url}/doDelete/api/json", {}) }
+ Hudson::Api.nodes['computer'].each do |node|
+ name = node['displayName']
+ Hudson::Api.delete_node(name) unless name == "master"
end
- hudson_info = Yajl::Parser.new.parse(open("#{base_url}/computer/api/json"))
- hudson_info['computer'].size.should == 1
+ Hudson::Api.nodes['computer'].size.should == 1
else
puts "WARNING: Run 'I have a Hudson server running' step first."
end
end
@@ -89,11 +74,11 @@
Then /^I should see a hudson server on port (\d+)$/ do |port|
require 'json'
try(15, 2) do
- res = Net::HTTP.start("localhost", port) { |http| http.get('/api/json') }
- JSON.parse(res.body)['nodeDescription'].should == "the master Hudson node"
+ Hudson::Api.base_uri "http://localhost:#{port}"
+ Hudson::Api.summary['nodeDescription'].should == "the master Hudson node"
end
end
When /^I (re|)create a job$/ do |override|
override = override.blank? ? "" : " --override"