rutema_elements 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +6 -0
- data/Manifest.txt +10 -0
- data/README.txt +87 -0
- data/Rakefile +19 -0
- data/lib/rutema/elements/general.rb +109 -0
- data/lib/rutema/elements/win32.rb +184 -0
- data/test/data/sample.sql +0 -0
- data/test/test_get_url.rb +84 -0
- data/test/test_selenium.rb +0 -0
- data/test/test_sqlcmd.rb +40 -0
- data/test/test_standard.rb +48 -0
- metadata +97 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
rutema_elements http://patir.rubyforge.org/rutema
|
2
|
+
|
3
|
+
== DESCRIPTION:
|
4
|
+
Rutema Elements modules are the easiest way to add functionality to rutema parsers.
|
5
|
+
Just derive your parser from the basic rutema parser and include the module of your choice
|
6
|
+
|
7
|
+
class MyParser < Rutema::MinimalXMLParser
|
8
|
+
include Rutema::Elements::IIS
|
9
|
+
include Rutema::Elements::Standard
|
10
|
+
end
|
11
|
+
|
12
|
+
and voila! your parser now understands how to reset IIS, wait and fail!
|
13
|
+
|
14
|
+
== FEATURES/PROBLEMS:
|
15
|
+
Easy addition of extra functionality for rutema
|
16
|
+
|
17
|
+
== SYNOPSIS:
|
18
|
+
See http://patir.rubyforge.org/rutema/parser.html for information on how these modules fit into a parser
|
19
|
+
Check the RDocs for information on how to configure plus examples of usage for each element.
|
20
|
+
|
21
|
+
== REQUIREMENTS:
|
22
|
+
* rutema
|
23
|
+
|
24
|
+
== INSTALL:
|
25
|
+
* gem i rutema_elements
|
26
|
+
|
27
|
+
== LICENSE:
|
28
|
+
(The Ruby License)
|
29
|
+
|
30
|
+
rutema_elements is copyright (c) 2008 Vassilis Rizopoulos
|
31
|
+
|
32
|
+
You can redistribute it and/or modify it under either the terms of the GPL
|
33
|
+
(see COPYING.txt file), or the conditions below:
|
34
|
+
|
35
|
+
1. You may make and give away verbatim copies of the source form of the
|
36
|
+
software without restriction, provided that you duplicate all of the
|
37
|
+
original copyright notices and associated disclaimers.
|
38
|
+
|
39
|
+
2. You may modify your copy of the software in any way, provided that
|
40
|
+
you do at least ONE of the following:
|
41
|
+
|
42
|
+
a) place your modifications in the Public Domain or otherwise
|
43
|
+
make them Freely Available, such as by posting said
|
44
|
+
modifications to Usenet or an equivalent medium, or by allowing
|
45
|
+
the author to include your modifications in the software.
|
46
|
+
|
47
|
+
b) use the modified software only within your corporation or
|
48
|
+
organization.
|
49
|
+
|
50
|
+
c) rename any non-standard executables so the names do not conflict
|
51
|
+
with standard executables, which must also be provided.
|
52
|
+
|
53
|
+
d) make other distribution arrangements with the author.
|
54
|
+
|
55
|
+
3. You may distribute the software in object code or executable
|
56
|
+
form, provided that you do at least ONE of the following:
|
57
|
+
|
58
|
+
a) distribute the executables and library files of the software,
|
59
|
+
together with instructions (in the manual page or equivalent)
|
60
|
+
on where to get the original distribution.
|
61
|
+
|
62
|
+
b) accompany the distribution with the machine-readable source of
|
63
|
+
the software.
|
64
|
+
|
65
|
+
c) give non-standard executables non-standard names, with
|
66
|
+
instructions on where to get the original software distribution.
|
67
|
+
|
68
|
+
d) make other distribution arrangements with the author.
|
69
|
+
|
70
|
+
4. You may modify and include the part of the software into any other
|
71
|
+
software (possibly commercial). But some files in the distribution
|
72
|
+
are not written by the author, so that they are not under this terms.
|
73
|
+
|
74
|
+
They are gc.c(partly), utils.c(partly), regex.[ch], st.[ch] and some
|
75
|
+
files under the ./missing directory. See each file for the copying
|
76
|
+
condition.
|
77
|
+
|
78
|
+
5. The scripts and library files supplied as input to or produced as
|
79
|
+
output from the software do not automatically fall under the
|
80
|
+
copyright of the software, but belong to whomever generated them,
|
81
|
+
and may be sold commercially, and may be aggregated with this
|
82
|
+
software.
|
83
|
+
|
84
|
+
6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
|
85
|
+
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
86
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
87
|
+
PURPOSE.
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# Copyright (c) 2007 Vassilis Rizopoulos. All rights reserved.
|
2
|
+
# -*- ruby -*-
|
3
|
+
$:.unshift File.join(File.dirname(__FILE__),"lib")
|
4
|
+
require 'rutema/elements/general'
|
5
|
+
require 'rubygems'
|
6
|
+
require 'hoe'
|
7
|
+
|
8
|
+
Hoe.new('rutema_elements', "#{Rutema::Elements::Version::STRING}") do |p|
|
9
|
+
p.rubyforge_name = 'patir'
|
10
|
+
p.author = "Vassilis Rizopoulos"
|
11
|
+
p.email = "riva@braveworld.net"
|
12
|
+
p.summary = 'rutema elements provides modules that can be used with custom parsers to add elements to rutema specifications'
|
13
|
+
p.description = p.paragraphs_of('README.txt', 1..5).join("\n\n")
|
14
|
+
p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
|
15
|
+
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
|
16
|
+
p.extra_deps<<['rutema',">=1.0.0"]
|
17
|
+
p.extra_deps<<['patir',">=0.6.1"]
|
18
|
+
end
|
19
|
+
# vim: syntax=Ruby
|
@@ -0,0 +1,109 @@
|
|
1
|
+
# Copyright (c) 2008 Vassilis Rizopoulos. All rights reserved.
|
2
|
+
require 'rubygems'
|
3
|
+
require 'patir/command'
|
4
|
+
require 'rutema/system'
|
5
|
+
require 'open-uri'
|
6
|
+
module Rutema
|
7
|
+
#The Elements module provides the namespace for the various functional modules
|
8
|
+
module Elements
|
9
|
+
module Version
|
10
|
+
MAJOR=0
|
11
|
+
MINOR=1
|
12
|
+
TINY=0
|
13
|
+
STRING=[ MAJOR, MINOR, TINY ].join( "." )
|
14
|
+
end
|
15
|
+
module Web
|
16
|
+
#Performs an HTTP GET for the given URL.
|
17
|
+
#
|
18
|
+
#It's usually used as a quick "it's alive" sign. It can also be used as a smart wait when restarting web servers.
|
19
|
+
#===Configuration
|
20
|
+
#No configuration necessary
|
21
|
+
#
|
22
|
+
#===Extras
|
23
|
+
#Requires the attribute address pointing to the URL to fetch
|
24
|
+
#
|
25
|
+
#Optionally the following attributes can be defined:
|
26
|
+
# retry - sets the number of times to attempt to fetch the URL before failing
|
27
|
+
# pause - sets the duration of sleep between retry attemps (in seconds)
|
28
|
+
#
|
29
|
+
#===Example Elements
|
30
|
+
# <get_url address="http://localhost" retry="5" pause="3"/>
|
31
|
+
def element_get_url step
|
32
|
+
address=step.address if step.has_address?
|
33
|
+
address||=@configuration.tools.get_url[:configuration][:address] if @configuration.tools.get_url && @configuration.tools.get_url[:configuration]
|
34
|
+
raise Rutema::ParserError,"No address attribute and no configuration present for get_url step" unless address
|
35
|
+
retries= step.retry.to_i if step.has_retry?
|
36
|
+
retries||=0
|
37
|
+
pause_time = step.pause.to_i if step.has_retry? && step.has_pause?
|
38
|
+
uri = URI.parse(step.address)
|
39
|
+
step.cmd=url_command(uri,retries,pause_time)
|
40
|
+
return step
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
def url_command url,retries,pause_time
|
45
|
+
Patir::RubyCommand.new("get_url",File.expand_path(File.dirname(__FILE__))) do |cmd|
|
46
|
+
cmd.output<<"Opening URL #{url.to_s}"
|
47
|
+
tries=0
|
48
|
+
suc=get_url(url,cmd)
|
49
|
+
while !suc && tries < retries
|
50
|
+
tries+=1
|
51
|
+
sleep pause_time if pause_time
|
52
|
+
suc=get_url(url,cmd)
|
53
|
+
end
|
54
|
+
raise "get_url failed" unless suc
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def get_url url,cmd
|
59
|
+
begin
|
60
|
+
#get the base URL to start the server
|
61
|
+
cmd.output<<"\n#{url.read}"
|
62
|
+
return true
|
63
|
+
rescue Timeout::Error, OpenURI::HTTPError, Errno::ECONNREFUSED
|
64
|
+
cmd.error<<$!.message
|
65
|
+
cmd.error<<"\n"
|
66
|
+
return false
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
module Standard
|
71
|
+
#Waits for a while
|
72
|
+
#
|
73
|
+
#===Configuration
|
74
|
+
#No configuration necessary
|
75
|
+
#
|
76
|
+
#===Extras
|
77
|
+
#Requires the attribute timeout setting the time to wait in seconds
|
78
|
+
#
|
79
|
+
#===Example Elements
|
80
|
+
# <wait timeout="5"/>
|
81
|
+
def element_wait step
|
82
|
+
raise Rutema::ParserError,"No timeout attribute for wait step" unless step.has_timeout?
|
83
|
+
step.cmd=Patir::RubyCommand.new("wait",File.expand_path(File.dirname(__FILE__))) do |cmd|
|
84
|
+
sleep step.timeout
|
85
|
+
end
|
86
|
+
return step
|
87
|
+
end
|
88
|
+
#Fails a test
|
89
|
+
#
|
90
|
+
#===Configuration
|
91
|
+
#No configuration necessary
|
92
|
+
#
|
93
|
+
#===Extras
|
94
|
+
#The attribute text can be used to set the error message for the step
|
95
|
+
#
|
96
|
+
#===Example Elements
|
97
|
+
# <fail/>
|
98
|
+
# <fail text="On Purpose!"/>
|
99
|
+
def element_fail step
|
100
|
+
step.cmd=Patir::RubyCommand.new("fail",File.expand_path(File.dirname(__FILE__))) do |cmd|
|
101
|
+
msg="Fail! "
|
102
|
+
msg<<step.text if step.has_text?
|
103
|
+
raise msg
|
104
|
+
end
|
105
|
+
return step
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,184 @@
|
|
1
|
+
# Copyright (c) 2008 Vassilis Rizopoulos. All rights reserved.
|
2
|
+
require 'rubygems'
|
3
|
+
require 'patir/command'
|
4
|
+
require 'rutema/system'
|
5
|
+
|
6
|
+
module Rutema
|
7
|
+
module Elements
|
8
|
+
#Elements to drive Microsoft's SQLServer
|
9
|
+
module SQLServer
|
10
|
+
#Calls sqlcmd.
|
11
|
+
#
|
12
|
+
#Requires the script attribute pointing to the SQL script to execute. Path can be relative to the specification file.
|
13
|
+
#===Configuration
|
14
|
+
#Requires a configuration.tool entry with :name=>"sqlcmd"
|
15
|
+
#and a :configuration entry pointing to a hash containing the configuration parameters.
|
16
|
+
#Configuration parameters are:
|
17
|
+
# :host - the host to run the command against (sqlcmd -H)
|
18
|
+
# :server - the SQLServer (named instance) (sqlcmd -S)
|
19
|
+
# :username - the SQLServer user (sqlcmd -U)
|
20
|
+
# :password - (sqlcmd -P)
|
21
|
+
# :script_root - The path relative to which pathnames for scripts are calculated. If it's missing paths are relative to the specification file. Optional
|
22
|
+
#===Example Configuration Entry
|
23
|
+
# configuration.tool={:name=>"sqlcmd",:configuration=>{:host=>"guineapig",:server=>"DB",:user=>"foo",:password=>"bar"}}
|
24
|
+
#
|
25
|
+
#===Extras
|
26
|
+
#Not defining any options (e.g. not defining the configuration.tool entry) results in the script running locally without options
|
27
|
+
#
|
28
|
+
#The configuration options can be overriden by element attributes (host,server,username etc.).
|
29
|
+
#Additionally the following attributes can be defined:
|
30
|
+
# database - the database to run the script against ( sqlcmd -d )
|
31
|
+
# level - Sets the errorlevel for the script (sqlcmd -V)
|
32
|
+
#
|
33
|
+
#===Example Elements
|
34
|
+
# <sqlcmd script="some.sql"/>
|
35
|
+
# <sqlcmd script="some.sql" host="localhost"/> - overriding host
|
36
|
+
# <sqlcmd script="some.sql" database="MyDB" level="18"/> - hypersensitive error checking and explicitly executed on MyDB
|
37
|
+
def element_sqlcmd step
|
38
|
+
raise Rutema::ParserError,"Missing required script attribute in sqlcmd step" unless step.has_script?
|
39
|
+
cfg=@configuration.tools.sqlcmd[:configuration].dup if @configuration.tools.sqlcmd && @configuration.tools.sqlcmd[:configuration]
|
40
|
+
cfg||=Hash.new
|
41
|
+
#see if there is a script root directory
|
42
|
+
if cfg[:script_root]
|
43
|
+
raise Rutema::ParserError,"Script root drectory '#{cfg[:script_root]}' does not exist. Error in the configuration for sqlcmd steps" unless File.exists?(cfg[:script_root])
|
44
|
+
script_path=File.expand_path(File.join(cfg[:script_root],step.script))
|
45
|
+
else
|
46
|
+
script_path=File.expand_path(step.script)
|
47
|
+
end
|
48
|
+
#we want a specific DB script to run
|
49
|
+
step.script=script_path
|
50
|
+
raise Rutema::ParserError,"Cannot find script file '#{step.script}' for sqlcmd step" unless File.exists?(step.script)
|
51
|
+
#check for overrides
|
52
|
+
cfg[:host] = step.host if step.has_host?
|
53
|
+
cfg[:server] = step.host if step.has_server?
|
54
|
+
cfg[:username] = step.host if step.has_username?
|
55
|
+
cfg[:password] = step.host if step.has_password?
|
56
|
+
#add the optional attributes
|
57
|
+
cfg[:database] = step.database if step.has_database?
|
58
|
+
cfg[:level] = step.level if step.has_level?
|
59
|
+
#add the script
|
60
|
+
cfg[:script]=step.script
|
61
|
+
#get the command object
|
62
|
+
step.cmd=sqlcmd_command(cfg)
|
63
|
+
return step
|
64
|
+
end
|
65
|
+
private
|
66
|
+
#Returns the Patir::ShellCommand with the correct commandline
|
67
|
+
def sqlcmd_command cfg
|
68
|
+
cmdline="sqlcmd -i \"#{File.expand_path(cfg[:script]).gsub("/","\\\\")}\" -b "
|
69
|
+
cmdline<<" -H #{cfg[:host]}" if cfg[:host] && cfg[:host]!="local"
|
70
|
+
cmdline<<" -S #{cfg[:server]}" if cfg[:server]
|
71
|
+
cmdline<<" -U #{cfg[:username]}" if cfg[:username]
|
72
|
+
cmdline<<" -P #{cfg[:password]}" if cfg[:password]
|
73
|
+
cmdline<<" -d #{cfg[:database]}" if cfg[:database]
|
74
|
+
cmdline<<" -V#{cfg[:level]}" if cfg[:level]
|
75
|
+
#make sure the script executes at the directory where it is.
|
76
|
+
return Patir::ShellCommand.new(:cmd=>cmdline,:working_directory=>File.dirname(File.expand_path(cfg[:script])))
|
77
|
+
end
|
78
|
+
end
|
79
|
+
#Elements to drive MSTest
|
80
|
+
module MSTest
|
81
|
+
#Calls an MSTest assembly.
|
82
|
+
#
|
83
|
+
#Requires the attribute assembly pointing to the assembly to execute. Path can be relative to the specification file.
|
84
|
+
#===Configuration
|
85
|
+
#Requires a configuration.tool entry with :name=>"mstest"
|
86
|
+
#and a :configuration entry pointing to a hash containing the configuration parameters.
|
87
|
+
#
|
88
|
+
#Configuration parameters are:
|
89
|
+
# :path - the path to the mstest utility. Required
|
90
|
+
# :shared_path - a {:local=>"localpath",:share=>"sharepath"} entry. Optional
|
91
|
+
# :assembly_root - the path relative to which the assembly paths are calculated. If it's not defined then the paths are calculated relative to the specification file. Optional
|
92
|
+
#===Example Configuration Entry
|
93
|
+
# configuration.tool={:name=>"mstest",:configuration=>{:path=>"/to/mstest.exe",assembly_root=>"c:/assemblies"}}
|
94
|
+
#
|
95
|
+
#===Extras
|
96
|
+
#The shared_path hash is a workaround for calling assemblies when the current working directory is on a shared drive
|
97
|
+
#(i.e. when running certain tasks in a TFS build)
|
98
|
+
#
|
99
|
+
#An example will illustrate it's usage better:
|
100
|
+
#
|
101
|
+
#{:share=>"//host/tests",:local=>"c:/tests"} will result in :share being substituted with :local on the assembly pathname
|
102
|
+
#so \\hosts\tests\assembly.dll becomes c:\tests\assembly.dll
|
103
|
+
#
|
104
|
+
#Note that entries should be defined with '/' instead of '\'.
|
105
|
+
#===Examples
|
106
|
+
# <mstest assembly="tests.dll"/>
|
107
|
+
def element_mstest step
|
108
|
+
raise Rutema::ParserError,"Missing required attribute 'assembly'" unless step.has_assembly?
|
109
|
+
raise Rutema::ParserError,"Missing tool configuration for mstest (no configuration.tool entry)" unless @configuration.tools.mstest && @configuration.tools.mstest[:configuration]
|
110
|
+
cfg=@configuration.tools.mstest[:configuration].dup
|
111
|
+
raise Rutema::ParserError,"Cannot find mstest in '#{@configuration.tools.mstest[:path]}'" unless File.exists?(cfg[:path])
|
112
|
+
#if there is an assembly root defined than calculate the paths relative to that
|
113
|
+
if cfg[:assembly_root]
|
114
|
+
raise Rutema::ParserError, "assembly_root entry '#{cfg[:assembly_root]}' defined for mstest does not exist. Error in the configuration for mstest steps" unless File.exists?(cfg[:assembly_root])
|
115
|
+
assembly_path=File.expand_path(File.join(cfg[:assembly_root],step.assembly))
|
116
|
+
else
|
117
|
+
assembly_path=File.expand_path(step.assembly)
|
118
|
+
end
|
119
|
+
#check that the assembly exists first
|
120
|
+
raise Rutema::ParserError,"Cannot find assembly file '#{assembly_path}' in mstest step" unless File.exists?(assembly_path)
|
121
|
+
#check to see if we apply the workaround
|
122
|
+
if cfg[:shared_path]
|
123
|
+
tfsbuild=cfg[:shared_path]
|
124
|
+
raise Rutema::ParserError,"Missing :share key for tfsbuild configuration" unless shared_path[:share]
|
125
|
+
raise Rutema::ParserError,"Missing :local key for tfsbuild configuration" unless shared_path[:local]
|
126
|
+
@logger.debug("Shared path manipulation (#{shared_path[:share]}=>#{shared_path[:local]}")
|
127
|
+
@logger.debug("Assembly path is '#{assembly_path}'")
|
128
|
+
assembly_path.gsub!(tfsbuild[:share],tfsbuild[:local])
|
129
|
+
end
|
130
|
+
#make the path windows compatible
|
131
|
+
assembly_path.gsub!('/',"\\\\")
|
132
|
+
#create the command line and the command instance
|
133
|
+
cmdline="\"#{cfg[:path]}\" /testcontainer:\"#{assembly_path}\""
|
134
|
+
@logger.debug("Parsed mstest call as '#{cmdline}'")
|
135
|
+
step.cmd=Patir::ShellCommand.new(:cmd=>cmdline,:working_directory=>File.dirname(assembly_path))
|
136
|
+
return step
|
137
|
+
end
|
138
|
+
end
|
139
|
+
#Elements to drive IIS
|
140
|
+
module IIS
|
141
|
+
#Resets an IIS server
|
142
|
+
#===Configuration
|
143
|
+
#Uses a configuration.tool entry with :name=>"iisreset"
|
144
|
+
#and a :configuration entry pointing to a hash containing the configuration parameters.
|
145
|
+
#
|
146
|
+
#Configuration parameters are:
|
147
|
+
# :server - the IIS to reset
|
148
|
+
#===Example Configuration Entry
|
149
|
+
# configuration.tool={:name=>"iisreset",:configuration=>{:server=>"localhost"}}
|
150
|
+
#
|
151
|
+
#===Extras
|
152
|
+
#The configuration options can be overriden by element attributes (i.e. server="localhost" etc.).
|
153
|
+
#Additionally the following attributes can be defined:
|
154
|
+
# start - when present the element will perform an iisreset /start
|
155
|
+
# stop - when present the element will perform an iisreset /stop
|
156
|
+
#
|
157
|
+
#===Examples
|
158
|
+
# <iisreset/> - resets according to the configuration
|
159
|
+
# <iisreset start="true"/> - starts the server defined in the configuration
|
160
|
+
# <iisreset server="localhost" stop="true"/> - stops localhost
|
161
|
+
def element_iisreset step
|
162
|
+
cfg=@configuration.tools.iisreset[:configuration].dup if @configuration.tools.iisreset && @configuration.tools.iisreset[:configuration]
|
163
|
+
cfg||=Hash.new
|
164
|
+
cfg[:server]=step.server if step.has_server?
|
165
|
+
raise Rutema::ParserError,"No server attribute and no configuration present for iisreset step" unless cfg[:server]
|
166
|
+
raise Rutema::ParserError,"Only one of 'stop' or 'start' can be defined in an iisreset step" if step.has_stop? && step.has_start?
|
167
|
+
cfg[:stop]=true if step.has_stop?
|
168
|
+
cfg[:start]=true if step.has_start?
|
169
|
+
step.cmd=iisreset_command(cfg)
|
170
|
+
return step
|
171
|
+
end
|
172
|
+
private
|
173
|
+
#returns the Patir::ShellCommand with the correct commandline
|
174
|
+
def iisreset_command cfg
|
175
|
+
cmdline="iisreset "
|
176
|
+
cmdline<<" /STOP" if cfg[:stop]
|
177
|
+
cmdline<<" /START" if cfg[:start]
|
178
|
+
cmdline<<" #{cfg[:server]}"
|
179
|
+
|
180
|
+
return Patir::ShellCommand.new(:cmd=>cmdline)
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
File without changes
|
@@ -0,0 +1,84 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__),"..","lib")
|
2
|
+
require 'test/unit'
|
3
|
+
require 'rutema/elements/general'
|
4
|
+
require 'rubygems'
|
5
|
+
require 'mocha'
|
6
|
+
|
7
|
+
class TestGetUrl <Test::Unit::TestCase
|
8
|
+
include Rutema::Elements::Web
|
9
|
+
def test_missing_configuration
|
10
|
+
@configuration=mock()
|
11
|
+
@configuration.expects(:get_url).returns(nil)
|
12
|
+
@configuration.expects(:tools).returns(@configuration)
|
13
|
+
step = mock()
|
14
|
+
step.expects(:has_address?).returns(false)
|
15
|
+
assert_raise(Rutema::ParserError) { element_get_url(step) }
|
16
|
+
end
|
17
|
+
def test_empty_configuration
|
18
|
+
@configuration=mock()
|
19
|
+
@configuration.expects(:get_url).returns({}).times(2)
|
20
|
+
@configuration.expects(:tools).returns(@configuration).times(2)
|
21
|
+
step = mock()
|
22
|
+
step.expects(:has_address?).returns(false)
|
23
|
+
assert_raise(Rutema::ParserError) { element_get_url(step) }
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_empty_configuration_with_address
|
27
|
+
@configuration=mock()
|
28
|
+
@configuration.expects(:get_url).returns({}).times(2)
|
29
|
+
@configuration.expects(:tools).returns(@configuration).times(2)
|
30
|
+
step = mock_simple_step
|
31
|
+
step.expects(:address).returns("http://localhost:9137")
|
32
|
+
step.expects(:has_retry?).returns(false).times(2)
|
33
|
+
assert_nothing_raised(){ element_get_url(step) }
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_retry_checking
|
37
|
+
mock_configuration
|
38
|
+
step=mock_simple_step
|
39
|
+
step.expects(:address).returns("http://localhost")
|
40
|
+
step.expects(:has_pause?).returns(false)
|
41
|
+
step.expects(:has_retry?).returns(true).times(2)
|
42
|
+
step.expects(:retry).returns(3)
|
43
|
+
assert_nothing_raised(){ element_get_url(step) }
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_pause_checking
|
47
|
+
mock_configuration
|
48
|
+
step=mock_simple_step
|
49
|
+
step.expects(:address).returns("http://localhost")
|
50
|
+
step.expects(:has_pause?).returns(true)
|
51
|
+
step.expects(:has_retry?).returns(true).times(2)
|
52
|
+
step.expects(:retry).returns(3)
|
53
|
+
step.expects(:pause).returns(3)
|
54
|
+
assert_nothing_raised(){ element_get_url(step) }
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_running_with_retry
|
58
|
+
mock_configuration
|
59
|
+
step=OpenStruct.new
|
60
|
+
step.expects(:has_address?).returns(true)
|
61
|
+
step.expects(:address).returns("http://localhost:9137").times(2)
|
62
|
+
step.expects(:has_pause?).returns(true)
|
63
|
+
step.expects(:has_retry?).returns(true).times(2)
|
64
|
+
step.expects(:retry).returns(3)
|
65
|
+
step.expects(:pause).returns(3)
|
66
|
+
assert_nothing_raised(){ element_get_url(step) }
|
67
|
+
c=step.cmd
|
68
|
+
assert_nothing_raised() { c.run }
|
69
|
+
assert(!c.success?, "Should not be succesfull.")
|
70
|
+
end
|
71
|
+
private
|
72
|
+
def mock_configuration
|
73
|
+
@configuration=mock()
|
74
|
+
@configuration.expects(:get_url).returns({:address=>"http://localhost"}).times(2)
|
75
|
+
@configuration.expects(:tools).returns(@configuration).times(2)
|
76
|
+
end
|
77
|
+
def mock_simple_step
|
78
|
+
step=mock()
|
79
|
+
step.expects(:has_address?).returns(true)
|
80
|
+
step.expects(:address).returns("http://localhost")
|
81
|
+
step.expects(:cmd=)
|
82
|
+
return step
|
83
|
+
end
|
84
|
+
end
|
File without changes
|
data/test/test_sqlcmd.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__),"..","lib")
|
2
|
+
require 'test/unit'
|
3
|
+
require 'rutema/elements/win32'
|
4
|
+
require 'rubygems'
|
5
|
+
require 'mocha'
|
6
|
+
|
7
|
+
class TestSqlcmd <Test::Unit::TestCase
|
8
|
+
include Rutema::Elements::SQLServer
|
9
|
+
def test_missing_configuration
|
10
|
+
sqlcmd_conf=mock()
|
11
|
+
sqlcmd_conf.expects(:sqlcmd).returns(nil)
|
12
|
+
@configuration=mock()
|
13
|
+
@configuration.expects(:tools).returns(sqlcmd_conf)
|
14
|
+
step=mock_simple_step
|
15
|
+
assert_nothing_raised() { element_sqlcmd(step) }
|
16
|
+
end
|
17
|
+
def test_empty_configuration
|
18
|
+
sqlcmd_conf=mock()
|
19
|
+
sqlcmd_conf.expects(:sqlcmd).returns({}).times(2)
|
20
|
+
@configuration=mock()
|
21
|
+
@configuration.expects(:tools).returns(sqlcmd_conf).times(2)
|
22
|
+
step=mock_simple_step
|
23
|
+
assert_nothing_raised() { element_sqlcmd(step) }
|
24
|
+
end
|
25
|
+
private
|
26
|
+
def mock_simple_step
|
27
|
+
step=mock()
|
28
|
+
step.expects(:has_script?).returns(true)
|
29
|
+
step.expects(:script).returns(File.join(File.dirname(__FILE__),"data","sample.sql")).times(3)
|
30
|
+
step.expects(:script=)
|
31
|
+
step.expects(:has_database?).returns(false)
|
32
|
+
step.expects(:has_host?).returns(false)
|
33
|
+
step.expects(:has_server?).returns(false)
|
34
|
+
step.expects(:has_password?).returns(false)
|
35
|
+
step.expects(:has_username?).returns(false)
|
36
|
+
step.expects(:has_level?).returns(false)
|
37
|
+
step.expects(:cmd=)
|
38
|
+
return step
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__),"..","lib")
|
2
|
+
require 'test/unit'
|
3
|
+
require 'rutema/elements/general'
|
4
|
+
require 'rubygems'
|
5
|
+
require 'mocha'
|
6
|
+
|
7
|
+
class TestStandard <Test::Unit::TestCase
|
8
|
+
include Rutema::Elements::Standard
|
9
|
+
def test_fail
|
10
|
+
step=OpenStruct.new
|
11
|
+
step.expects(:has_text?).returns(false)
|
12
|
+
assert_nothing_raised(){ element_fail(step) }
|
13
|
+
c=step.cmd
|
14
|
+
assert_not_nil(c)
|
15
|
+
assert_nothing_raised() { c.run }
|
16
|
+
assert(!c.success?, "Command did not fail.")
|
17
|
+
assert_equal("\nFail! ",c.error)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_fail_with_text
|
21
|
+
step=OpenStruct.new
|
22
|
+
step.expects(:has_text?).returns(true)
|
23
|
+
step.expects(:text).returns("Text")
|
24
|
+
assert_nothing_raised(){ element_fail(step) }
|
25
|
+
c=step.cmd
|
26
|
+
assert_not_nil(c)
|
27
|
+
assert_nothing_raised() { c.run }
|
28
|
+
assert(!c.success?, "Command did not fail.")
|
29
|
+
assert_equal("\nFail! Text",c.error)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_wait
|
33
|
+
step=OpenStruct.new
|
34
|
+
step.expects(:has_timeout?).returns(true)
|
35
|
+
step.expects(:timeout).returns(2)
|
36
|
+
assert_nothing_raised(){ element_wait(step) }
|
37
|
+
c=step.cmd
|
38
|
+
assert_not_nil(c)
|
39
|
+
t1=Time.now
|
40
|
+
assert_nothing_raised() { c.run }
|
41
|
+
assert(c.exec_time>=2)
|
42
|
+
end
|
43
|
+
def test_wait_no_timeout
|
44
|
+
step=mock()
|
45
|
+
step.expects(:has_timeout?).returns(false)
|
46
|
+
assert_raise(Rutema::ParserError){ element_wait(step) }
|
47
|
+
end
|
48
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rutema_elements
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Vassilis Rizopoulos
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-10-28 00:00:00 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rutema
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.0.0
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: patir
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.6.1
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: hoe
|
37
|
+
type: :development
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 1.8.1
|
44
|
+
version:
|
45
|
+
description: "== DESCRIPTION: Rutema Elements modules are the easiest way to add functionality to rutema parsers. Just derive your parser from the basic rutema parser and include the module of your choice class MyParser < Rutema::MinimalXMLParser include Rutema::Elements::IIS include Rutema::Elements::Standard end and voila! your parser now understands how to reset IIS, wait and fail! == FEATURES/PROBLEMS: Easy addition of extra functionality for rutema == SYNOPSIS: See http://patir.rubyforge.org/rutema/parser.html for information on how these modules fit into a parser Check the RDocs for information on how to configure plus examples of usage for each element."
|
46
|
+
email: riva@braveworld.net
|
47
|
+
executables: []
|
48
|
+
|
49
|
+
extensions: []
|
50
|
+
|
51
|
+
extra_rdoc_files:
|
52
|
+
- History.txt
|
53
|
+
- Manifest.txt
|
54
|
+
- README.txt
|
55
|
+
files:
|
56
|
+
- History.txt
|
57
|
+
- Manifest.txt
|
58
|
+
- README.txt
|
59
|
+
- Rakefile
|
60
|
+
- lib/rutema/elements/win32.rb
|
61
|
+
- lib/rutema/elements/general.rb
|
62
|
+
- test/test_sqlcmd.rb
|
63
|
+
- test/test_get_url.rb
|
64
|
+
- test/test_standard.rb
|
65
|
+
- test/data/sample.sql
|
66
|
+
has_rdoc: true
|
67
|
+
homepage:
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options:
|
70
|
+
- --main
|
71
|
+
- README.txt
|
72
|
+
require_paths:
|
73
|
+
- lib
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: "0"
|
79
|
+
version:
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: "0"
|
85
|
+
version:
|
86
|
+
requirements: []
|
87
|
+
|
88
|
+
rubyforge_project: patir
|
89
|
+
rubygems_version: 1.3.0
|
90
|
+
signing_key:
|
91
|
+
specification_version: 2
|
92
|
+
summary: rutema elements provides modules that can be used with custom parsers to add elements to rutema specifications
|
93
|
+
test_files:
|
94
|
+
- test/test_get_url.rb
|
95
|
+
- test/test_selenium.rb
|
96
|
+
- test/test_sqlcmd.rb
|
97
|
+
- test/test_standard.rb
|