dtf 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/dtf +2 -4
- data/lib/dtf.rb +57 -42
- data/lib/dtf/version.rb +1 -1
- data/spec/acceptance/verify_sub_commands.feature +6 -1
- data/spec/steps/feature_steps.rb +28 -14
- metadata +1 -1
data/bin/dtf
CHANGED
@@ -6,8 +6,6 @@
|
|
6
6
|
|
7
7
|
require 'dtf'
|
8
8
|
|
9
|
-
|
10
|
-
@cmd, @cmd_opts = @parser.parse_cmds # Parse the command-line, and return the cmd & its specific cmd_opts
|
9
|
+
cmd, cmd_opts = Dtf::OptionsParser.new.parse_cmds(ARGV)
|
11
10
|
|
12
|
-
|
13
|
-
@new_cmd.execute(@cmd_opts) # Pass @cmd_opts to that command's execute method
|
11
|
+
Dtf::Command.create_cmd(cmd, cmd_opts).execute # Create a command named after contents of @cmd var
|
data/lib/dtf.rb
CHANGED
@@ -7,16 +7,11 @@ module Dtf
|
|
7
7
|
load "#{File.join(File.dirname(__FILE__), "/config/environment.rb")}"
|
8
8
|
|
9
9
|
module Command
|
10
|
-
def self.create_cmd(cmd)
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
puts "DTF has no registered command by that name."
|
16
|
-
puts "Please see 'dtf -h' for the list of recognized commands."
|
17
|
-
else
|
18
|
-
return new_cmd
|
19
|
-
end
|
10
|
+
def self.create_cmd(cmd, options)
|
11
|
+
Dtf::Command.const_get(cmd.camelize).new(cmd, options)
|
12
|
+
rescue NameError
|
13
|
+
puts "DTF has no registered command by that name."
|
14
|
+
puts "Please see 'dtf -h' for the list of recognized commands."
|
20
15
|
end
|
21
16
|
|
22
17
|
# This sub-command is used to add a User to the Test Framework system
|
@@ -28,18 +23,23 @@ module Dtf
|
|
28
23
|
# '--full-name' is the Real Name of the created User.
|
29
24
|
# '--email-address' is the email address of the created User, and *must* be unique in the system.
|
30
25
|
class CreateUser
|
31
|
-
def
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
26
|
+
def initialize(cmd_name, options)
|
27
|
+
@cmd_name = cmd_name
|
28
|
+
@cmd_opts = options
|
29
|
+
end
|
30
|
+
|
31
|
+
def execute
|
32
|
+
if [:user_name_given, :full_name_given, :email_address_given].all? { |sym| @cmd_opts.key?(sym) } then
|
33
|
+
user = User.where(user_name: @cmd_opts[:user_name],
|
34
|
+
full_name: @cmd_opts[:full_name],
|
35
|
+
email_address: @cmd_opts[:email_address]).create
|
36
36
|
|
37
37
|
# Check to make sure user was actually saved to the db
|
38
38
|
if user.persisted? then
|
39
|
-
puts "Created user \'#{cmd_opts[:user_name]}\' for \'#{cmd_opts[:full_name]}\'"
|
39
|
+
puts "Created user \'#{@cmd_opts[:user_name]}\' for \'#{@cmd_opts[:full_name]}\'"
|
40
40
|
else
|
41
41
|
# Oops, it wasn't! Notify user and display any error message(s)
|
42
|
-
$stderr.puts "ERROR: #{cmd_opts[:user_name].to_s} was NOT created! Please fix the following errors and try again:"
|
42
|
+
$stderr.puts "ERROR: #{@cmd_opts[:user_name].to_s} was NOT created! Please fix the following errors and try again:"
|
43
43
|
user.errors.full_messages.each do |msg|
|
44
44
|
$stderr.puts "#{msg}"
|
45
45
|
end
|
@@ -47,7 +47,7 @@ module Dtf
|
|
47
47
|
abort()
|
48
48
|
end
|
49
49
|
else
|
50
|
-
Dtf::ErrorSystem.raise_error(@
|
50
|
+
Dtf::ErrorSystem.raise_error(@cmd_name) # This error here is thrown when not all params are provided
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
@@ -66,18 +66,23 @@ module Dtf
|
|
66
66
|
# This *optional* parameter is for providing a description of the Verification Suite's use.
|
67
67
|
# e.g. --description "RSpec Verification"
|
68
68
|
class CreateVs
|
69
|
-
def
|
70
|
-
|
71
|
-
|
72
|
-
|
69
|
+
def initialize(cmd_name, options)
|
70
|
+
@cmd_name = cmd_name
|
71
|
+
@cmd_opts = options
|
72
|
+
end
|
73
|
+
|
74
|
+
def execute
|
75
|
+
if [:user_name_given, :name_given].all? { |sym| @cmd_opts.key?(sym) } then
|
76
|
+
user = User.find_by_user_name(@cmd_opts[:user_name])
|
77
|
+
vs = user.verification_suites.create(name: @cmd_opts[:name], description: @cmd_opts[:description])
|
73
78
|
if vs.persisted? then
|
74
|
-
puts "VS named \'#{cmd_opts[:name]}\' allocated to user \'#{cmd_opts[:user_name]}\'"
|
79
|
+
puts "VS named \'#{@cmd_opts[:name]}\' allocated to user \'#{@cmd_opts[:user_name]}\'"
|
75
80
|
else
|
76
81
|
$stderr.puts "ERROR: Failed to save Verification Suite. Check DB logfile for errors"
|
77
82
|
abort()
|
78
83
|
end
|
79
84
|
else
|
80
|
-
Dtf::ErrorSystem.raise_error(@
|
85
|
+
Dtf::ErrorSystem.raise_error(@cmd_name)
|
81
86
|
end
|
82
87
|
end
|
83
88
|
end
|
@@ -99,15 +104,20 @@ module Dtf
|
|
99
104
|
# This flag will find all Verification Suites owned by the user being deleted, and reassign them
|
100
105
|
# to 'Library Owner' (user_name: library_owner) which is the generic in-house User shipped with DTF.
|
101
106
|
class DeleteUser
|
102
|
-
def
|
103
|
-
|
107
|
+
def initialize(cmd_name, options)
|
108
|
+
@cmd_name = cmd_name
|
109
|
+
@cmd_opts = options
|
110
|
+
end
|
111
|
+
|
112
|
+
def execute
|
113
|
+
if [:user_name_given, :delete_all].all? { |sym| @cmd_opts.key?(sym) } then
|
104
114
|
# NOTE: :delete_all is 'true' by default. passing '--no-delete-all' sets it to false,
|
105
115
|
# and adds the :delete_all_given key to the cmd_opts hash, set to true.
|
106
116
|
# This means NOT to delete all VSs associated with this user. We delete them by default.
|
107
|
-
if cmd_opts[:delete_all] == false && cmd_opts[:delete_all_given] == true
|
117
|
+
if @cmd_opts[:delete_all] == false && @cmd_opts[:delete_all_given] == true
|
108
118
|
puts "Called with '--no-delete-all' set! NOT deleting all owned VSs!"
|
109
119
|
puts "Reassigning VSs to Library. New owner will be \'Library Owner\'"
|
110
|
-
user = User.find_by_user_name(cmd_opts[:user_name])
|
120
|
+
user = User.find_by_user_name(@cmd_opts[:user_name])
|
111
121
|
lib_owner = User.find_by_user_name("library_owner")
|
112
122
|
user.verification_suites.all.each do |vs|
|
113
123
|
vs.user_id = lib_owner.id
|
@@ -115,8 +125,8 @@ module Dtf
|
|
115
125
|
end
|
116
126
|
User.delete(user)
|
117
127
|
else
|
118
|
-
puts "Called with '--delete-all' set or on by default! Deleting all VSs owned by #{cmd_opts[:user_name]}"
|
119
|
-
user = User.find_by_user_name(cmd_opts[:user_name])
|
128
|
+
puts "Called with '--delete-all' set or on by default! Deleting all VSs owned by #{@cmd_opts[:user_name]}"
|
129
|
+
user = User.find_by_user_name(@cmd_opts[:user_name])
|
120
130
|
if ! user.nil? then
|
121
131
|
user.verification_suites.all.each do |vs|
|
122
132
|
VerificationSuite.delete(vs)
|
@@ -125,12 +135,12 @@ module Dtf
|
|
125
135
|
User.delete(user)
|
126
136
|
end
|
127
137
|
else
|
128
|
-
$stderr.puts "ERROR: No user named \'#{cmd_opts[:user_name].to_s}\' found!"
|
138
|
+
$stderr.puts "ERROR: No user named \'#{@cmd_opts[:user_name].to_s}\' found!"
|
129
139
|
abort()
|
130
140
|
end
|
131
141
|
end
|
132
142
|
else
|
133
|
-
Dtf::ErrorSystem.raise_error(@
|
143
|
+
Dtf::ErrorSystem.raise_error(@cmd_name)
|
134
144
|
end
|
135
145
|
end
|
136
146
|
end
|
@@ -143,14 +153,19 @@ module Dtf
|
|
143
153
|
# The '--user-name' parameter is the user_name of the User that owns the Verification Suite you wish to delete
|
144
154
|
# The '--id' parameter is the ID # of the Verification Suite you wish to delete, as provided by @vs.id
|
145
155
|
class DeleteVs
|
146
|
-
def
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
156
|
+
def initialize(cmd_name, options)
|
157
|
+
@cmd_name = cmd_name
|
158
|
+
@cmd_opts = options
|
159
|
+
end
|
160
|
+
|
161
|
+
def execute
|
162
|
+
if [:user_name_given, :id_given].all? { |sym| @cmd_opts.key?(sym) } then
|
163
|
+
puts "Deleting #{@cmd_opts[:user_name]}\'s VS with ID \'#{@cmd_opts[:id]}\'"
|
164
|
+
user = User.find_by_user_name(@cmd_opts[:user_name])
|
165
|
+
vs = user.verification_suites.find(@cmd_opts[:id])
|
151
166
|
VerificationSuite.delete(vs)
|
152
167
|
else
|
153
|
-
Dtf::ErrorSystem.raise_error(@
|
168
|
+
Dtf::ErrorSystem.raise_error(@cmd_name)
|
154
169
|
end
|
155
170
|
end
|
156
171
|
end
|
@@ -194,7 +209,7 @@ module Dtf
|
|
194
209
|
# and provides the help system for options/parameters.
|
195
210
|
#
|
196
211
|
# Returned Values: @cmd [Type: String] and @cmd_opts [Type: Hash]
|
197
|
-
def parse_cmds(arg
|
212
|
+
def parse_cmds(arg)
|
198
213
|
# Global options default to '--version|-v' and '--help|-h'
|
199
214
|
global_opts = Trollop::options do
|
200
215
|
version "DTF v#{Dtf::VERSION}"
|
@@ -214,8 +229,8 @@ module Dtf
|
|
214
229
|
stop_on SUB_COMMANDS
|
215
230
|
end
|
216
231
|
|
217
|
-
|
218
|
-
|
232
|
+
cmd = arg.shift
|
233
|
+
cmd_opts = case cmd
|
219
234
|
when "create_user"
|
220
235
|
Trollop::options do
|
221
236
|
opt(:user_name, desc="Username for new TF user - REQUIRED", opts={:type => :string, :short => '-u'})
|
@@ -244,7 +259,7 @@ module Dtf
|
|
244
259
|
Trollop::die "Unknown DTF sub-command: #{@cmd.inspect}"
|
245
260
|
end
|
246
261
|
|
247
|
-
return
|
262
|
+
return cmd, cmd_opts # Explicitly return cmd and its cmd_opts
|
248
263
|
end
|
249
264
|
end
|
250
265
|
|
data/lib/dtf/version.rb
CHANGED
@@ -10,11 +10,16 @@ Feature: Verify sub commands
|
|
10
10
|
Given I execute 'create_user'
|
11
11
|
Then I should find 'testuser' in the database
|
12
12
|
|
13
|
-
Scenario: Execution of delete_user succeeds
|
13
|
+
Scenario: Execution of delete_user succeeds ( WITHOUT setting --no-delete-all flag [Default] )
|
14
14
|
send "I execute 'create_user'"
|
15
15
|
Given I execute 'delete_user'
|
16
16
|
Then I should not find 'testuser' in the database
|
17
17
|
|
18
|
+
Scenario: Execution of delete_user succeeds ( WITH setting --no-delete-all flag )
|
19
|
+
send "I execute 'create_user'"
|
20
|
+
Given I execute 'delete_user' setting --no-delete-all
|
21
|
+
Then I should not find 'testuser' in the database
|
22
|
+
|
18
23
|
Scenario: Execution of create_vs succeeds
|
19
24
|
send "I create 'create_user'"
|
20
25
|
Given I execute 'create_vs'
|
data/spec/steps/feature_steps.rb
CHANGED
@@ -26,12 +26,11 @@ step "I execute 'create_user'" do
|
|
26
26
|
email_address: "me@example.com",
|
27
27
|
user_name_given: true,
|
28
28
|
full_name_given: true,
|
29
|
-
email_address_given: true
|
30
|
-
delete_all: true
|
29
|
+
email_address_given: true
|
31
30
|
}
|
32
31
|
|
33
|
-
|
34
|
-
|
32
|
+
new_cmd = Dtf::Command.create_cmd(@cmd, @cmd_opts)
|
33
|
+
new_cmd.execute
|
35
34
|
end
|
36
35
|
|
37
36
|
step "I should find 'testuser' in the database" do
|
@@ -41,17 +40,31 @@ end
|
|
41
40
|
|
42
41
|
step "I execute 'delete_user'" do
|
43
42
|
send "I execute 'create_user'"
|
44
|
-
end
|
45
43
|
|
46
|
-
step "I should not find 'testuser' in the database" do
|
47
44
|
@cmd = "delete_user"
|
48
45
|
@cmd_opts = { user_name: "testuser",
|
49
|
-
delete_all_given: true,
|
50
46
|
user_name_given: true,
|
51
|
-
delete_all:
|
47
|
+
delete_all: true
|
52
48
|
}
|
53
|
-
|
54
|
-
|
49
|
+
new_cmd = Dtf::Command.create_cmd(@cmd, @cmd_opts)
|
50
|
+
new_cmd.execute
|
51
|
+
end
|
52
|
+
|
53
|
+
step "I execute 'delete_user' setting --no-delete-all" do
|
54
|
+
send "I execute 'create_user'"
|
55
|
+
|
56
|
+
@cmd = "delete_user"
|
57
|
+
@cmd_opts = {user_name: "testuser",
|
58
|
+
user_name_given: true,
|
59
|
+
delete_all: false,
|
60
|
+
delete_all_given: true
|
61
|
+
}
|
62
|
+
|
63
|
+
new_cmd = Dtf::Command.create_cmd(@cmd, @cmd_opts)
|
64
|
+
new_cmd.execute
|
65
|
+
end
|
66
|
+
|
67
|
+
step "I should not find 'testuser' in the database" do
|
55
68
|
end
|
56
69
|
|
57
70
|
step "I execute 'create_vs'" do
|
@@ -65,8 +78,9 @@ step "I execute 'create_vs'" do
|
|
65
78
|
description_given: true
|
66
79
|
}
|
67
80
|
|
68
|
-
|
69
|
-
|
81
|
+
new_cmd = Dtf::Command.create_cmd(@cmd, @cmd_opts)
|
82
|
+
new_cmd.execute
|
83
|
+
|
70
84
|
end
|
71
85
|
|
72
86
|
step "I should find a VS in the database" do
|
@@ -82,8 +96,8 @@ step "I execute 'delete_vs'" do
|
|
82
96
|
user_name_given: true,
|
83
97
|
id_given: true
|
84
98
|
}
|
85
|
-
|
86
|
-
|
99
|
+
new_cmd = Dtf::Command.create_cmd(@cmd, @cmd_opts)
|
100
|
+
new_cmd.execute
|
87
101
|
end
|
88
102
|
|
89
103
|
step "I should not find a VS in the database" do
|