cukesparse 2.0.5 → 2.1.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.
- checksums.yaml +4 -4
- data/bin/cukesparse +1 -1
- data/cukesparse.gemspec +1 -1
- data/lib/cukesparse.rb +106 -146
- data/lib/cukesparse/version.rb +1 -1
- data/spec/cukesparse/add_multiple_spec.rb +6 -6
- data/spec/cukesparse/argv_spec.rb +14 -0
- data/spec/cukesparse/check_for_parameters_spec.rb +0 -1
- data/spec/cukesparse/check_for_task_spec.rb +2 -3
- data/spec/cukesparse/debug_spec.rb +25 -0
- data/spec/cukesparse/execute_spec.rb +2 -2
- data/spec/cukesparse/load_config_spec.rb +2 -2
- data/spec/cukesparse/parse_argv_spec.rb +80 -80
- data/spec/cukesparse/reset_spec.rb +26 -0
- data/spec/cukesparse/set_cucumber_defaults_spec.rb +33 -20
- data/spec/cukesparse/set_runtime_defaults_spec.rb +28 -28
- data/spec/cukesparse/split_parameters_spec.rb +12 -12
- data/spec/fixtures/valid_tasks.yml +11 -0
- data/spec/helper.rb +2 -1
- metadata +9 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c80cf3026666d2482f06451e9e0524afe3deafbe
|
4
|
+
data.tar.gz: 57b144f542d1d48a8b8e0cab9622c5419356300d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c23ce187c948f68a99fd36c3222b7767e289de7f3062ef1900f9a5d00838a0714f1c108497ef5f3502f3bb47ff703b20be96ccab131ee3f56cca2611c4524eff
|
7
|
+
data.tar.gz: adcf9a9adfe34e55e13cdfd54a35c960fc87ffcb300a4279f63732a4a893bec937157172cd6781e35c963c05f465a5a4884504e0852338b9833ab22066808740
|
data/bin/cukesparse
CHANGED
data/cukesparse.gemspec
CHANGED
@@ -3,7 +3,7 @@ require File.dirname(__FILE__) + "/lib/cukesparse/version"
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = 'cukesparse'
|
5
5
|
s.version = Cukesparse::VERSION
|
6
|
-
s.date = '2013-08-
|
6
|
+
s.date = '2013-08-30'
|
7
7
|
s.summary = 'Cukesparse - cucumber command line parser'
|
8
8
|
s.description = 'A simple command line parser to pass arguments into Cucumber'
|
9
9
|
s.author = 'Jonathan Chrisp'
|
data/lib/cukesparse.rb
CHANGED
@@ -2,16 +2,17 @@ require 'clik'
|
|
2
2
|
require 'colored'
|
3
3
|
require 'yaml'
|
4
4
|
|
5
|
+
|
5
6
|
module Cukesparse
|
6
7
|
class << self
|
7
8
|
attr_accessor :config_file, :config, :task, :parameters, :command
|
8
9
|
|
9
|
-
#
|
10
|
-
def
|
11
|
-
|
10
|
+
# Returns current config file
|
11
|
+
def config_file
|
12
|
+
@config_file ||= 'config/tasks.yml'
|
12
13
|
end
|
13
14
|
|
14
|
-
#
|
15
|
+
# Returns current argv
|
15
16
|
def argv
|
16
17
|
ARGV
|
17
18
|
end
|
@@ -21,42 +22,29 @@ module Cukesparse
|
|
21
22
|
# @param [Symbol] key the key to store in options
|
22
23
|
# @param [String] val the arguments passed in for key
|
23
24
|
def add_multiple key, val
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
end
|
29
|
-
else
|
30
|
-
(@parameters[key] ||= []).push '--' + key.to_s + ' ' + val.to_s
|
25
|
+
return (@parameters[key] ||= []).push '--' + key + ' ' + val unless val.is_a? Array
|
26
|
+
|
27
|
+
val.each do |v|
|
28
|
+
(@parameters[key] ||= []).push '--' + key + ' ' + v
|
31
29
|
end
|
32
30
|
end
|
33
31
|
|
34
32
|
# Executes cukesparse by checking arguments passed
|
35
33
|
def execute
|
36
|
-
|
37
|
-
if argv.empty?
|
38
|
-
|
39
|
-
return
|
40
|
-
end
|
34
|
+
load_config
|
35
|
+
return puts 'Cukesparse - a simple command line parser to pass arguments into Cucumber!'.yellow if argv.empty?
|
36
|
+
return puts "You have the following tasks within your config file: #{@config.keys.join(', ')}".yellow if argv.dup.shift == 'tasks'
|
41
37
|
|
42
|
-
|
43
|
-
case argv.dup.shift
|
44
|
-
when 'tasks'
|
45
|
-
load_config
|
46
|
-
puts "You have the following tasks within your config file: #{@config.keys.join(', ')}".yellow
|
47
|
-
return
|
48
|
-
else
|
49
|
-
load_config.parse_argv.build_command
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
# Builds the command line string
|
54
|
-
def build_command
|
38
|
+
parse_argv
|
55
39
|
check_for_task
|
56
40
|
check_for_parameters
|
57
41
|
set_cucumber_defaults
|
58
42
|
set_runtime_defaults
|
43
|
+
build_command
|
44
|
+
end
|
59
45
|
|
46
|
+
# Builds the command line string
|
47
|
+
def build_command
|
60
48
|
unless @task.empty? && @parameters.empty?
|
61
49
|
@command.push 'bundle exec cucumber'
|
62
50
|
@command.push '--require features/'
|
@@ -65,31 +53,22 @@ module Cukesparse
|
|
65
53
|
@command.push task['defaults'].join(' ') if task.has_key? 'defaults'
|
66
54
|
end
|
67
55
|
|
68
|
-
if @parameters.has_key?
|
69
|
-
|
70
|
-
|
71
|
-
system @command.join(' ')
|
72
|
-
exit $?.exitstatus
|
73
|
-
end
|
56
|
+
return debug if @parameters.has_key? 'debug'
|
57
|
+
system @command.join(' ')
|
58
|
+
exit $?.exitstatus
|
74
59
|
end
|
75
60
|
|
76
61
|
# Checks for task in arguments
|
77
62
|
def check_for_task
|
78
63
|
task = argv & @config.keys
|
79
|
-
if task.empty?
|
80
|
-
|
81
|
-
|
82
|
-
puts 'WARN: Multiple tasks have been passed!'.yellow
|
83
|
-
else
|
84
|
-
@task = @config[task[0]]
|
85
|
-
end
|
64
|
+
return abort 'ERROR: No task was passed to cukesparse!'.red.underline if task.empty?
|
65
|
+
return puts 'WARN: Multiple tasks have been passed!'.yellow if task.length > 1
|
66
|
+
return @task = @config[task[0]]
|
86
67
|
end
|
87
68
|
|
88
69
|
# Checks parameters and returns boolean
|
89
70
|
def check_for_parameters
|
90
|
-
unless @parameters.any?
|
91
|
-
puts 'WARN: No parameters passed to cukesparse'.yellow
|
92
|
-
end
|
71
|
+
return puts 'WARN: No parameters passed to cukesparse'.yellow unless @parameters.any?
|
93
72
|
end
|
94
73
|
|
95
74
|
# Outputs the debug information
|
@@ -106,108 +85,97 @@ module Cukesparse
|
|
106
85
|
|
107
86
|
# Loads the config file
|
108
87
|
def load_config
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
abort 'Your tasks file is missing!'.red.underline
|
115
|
-
end
|
116
|
-
self
|
88
|
+
@config = YAML.load_file config_file
|
89
|
+
rescue Psych::SyntaxError
|
90
|
+
abort 'Your tasks file did not parse as expected!'.red.underline
|
91
|
+
rescue Errno::ENOENT
|
92
|
+
abort 'Your tasks file is missing!'.red.underline
|
117
93
|
end
|
118
94
|
|
119
95
|
# Parses the options passed via command line
|
120
96
|
def parse_argv
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
abort 'Error processing passed CLI arguments!'.red.underline
|
163
|
-
else
|
164
|
-
self
|
165
|
-
end
|
97
|
+
cli argv,
|
98
|
+
# Cucumber options
|
99
|
+
'-t' => lambda{ |t| add_multiple('tags', t) },
|
100
|
+
'-n --name' => lambda{ |n| add_multiple('name', n) },
|
101
|
+
'-f --format' => ->(f){ @parameters['format'] = "--format #{f}" },
|
102
|
+
'-d --dry-run' => ->{ @parameters['dry_run'] = "--dry-run" },
|
103
|
+
'-v --verbose' => ->{ @parameters['verbose'] = "--verbose" },
|
104
|
+
'-s --strict' => ->{ @parameters['strict'] = "--strict" },
|
105
|
+
'-g --guess' => ->{ @parameters['guess'] = "--guess" },
|
106
|
+
'-x --expand' => ->{ @parameters['expand'] = "--expand" },
|
107
|
+
|
108
|
+
# All options below have been added for custom project but can be used for example
|
109
|
+
# Global options
|
110
|
+
'-e --environment' => ->(e){ @parameters['environment'] = "ENVIRONMENT=#{e}" },
|
111
|
+
'-l --loglevel' => ->(l){ @parameters['log_level'] = "LOG_LEVEL=#{l}" },
|
112
|
+
'-c --controller' => ->(c){ @parameters['controller'] = "CONTROLLER=#{c}" },
|
113
|
+
'-h --headless' => ->{ @parameters['headless'] = "HEADLESS=TRUE" },
|
114
|
+
|
115
|
+
# Database options
|
116
|
+
'--cleanup' => ->{ @parameters['cleanup'] = "CLEANUP=TRUE" },
|
117
|
+
'--no-cleanup' => ->{ @parameters['cleanup'] = "CLEANUP=FALSE" },
|
118
|
+
'--database' => ->{ @parameters['database'] = "DATABASE=TRUE" },
|
119
|
+
'--jenkins' => ->{ @parameters['jenkins'] = "JENKINS=TRUE" },
|
120
|
+
|
121
|
+
# Retry options
|
122
|
+
'--retries' => ->(r){ @parameters['retries'] = "RETRIES=#{r}" },
|
123
|
+
'--timeout' => ->(t){ @parameters['timeout'] = "TIMEOUT=#{t}" },
|
124
|
+
|
125
|
+
# Driver Options
|
126
|
+
'--screen' => ->(s){ split_parameters(s, 'screen') },
|
127
|
+
'--position' => ->(p){ split_parameters(p, 'position') },
|
128
|
+
'--screenwidth' => ->(w){ @parameters['screen_width'] = "SCREENWIDTH=#{w}" },
|
129
|
+
'--screenheight' => ->(h){ @parameters['screen_height'] = "SCREENHEIGHT=#{h}" },
|
130
|
+
'--xposition' => ->(x){ @parameters['xposition'] = "XPOSITION=#{x}" },
|
131
|
+
'--yposition' => ->(y){ @parameters['yposition'] = "YPOSITION=#{y}" },
|
132
|
+
'-H --highlight' => ->{ @parameters['highlight'] = "HIGHLIGHT=TRUE" },
|
133
|
+
|
134
|
+
# Debug
|
135
|
+
'--debug' => ->{ @parameters['debug'] = "DEBUG=TRUE" }
|
136
|
+
rescue
|
137
|
+
abort 'Error processing passed CLI arguments!'.red.underline
|
166
138
|
end
|
167
139
|
|
168
140
|
# Updates parameters based on config runtime defaults
|
169
141
|
def set_runtime_defaults
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
142
|
+
return puts 'WARN: The task has no runtime defaults!'.yellow unless @task.has_key? 'runtime_defaults'
|
143
|
+
|
144
|
+
@task['runtime_defaults'].each do |key, val|
|
145
|
+
case key
|
146
|
+
when 'screen', 'position'
|
147
|
+
split_parameters(val, key)
|
148
|
+
else
|
149
|
+
unless @parameters.has_key? key
|
150
|
+
@parameters[key] = key.upcase + '=' + val.to_s
|
179
151
|
end
|
180
152
|
end
|
181
|
-
else
|
182
|
-
puts 'WARN: The task has no runtime defaults!'.yellow
|
183
153
|
end
|
184
154
|
end
|
185
155
|
|
186
156
|
# Updates parameters based on config cucumber defaults
|
187
157
|
def set_cucumber_defaults
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
else
|
206
|
-
puts 'WARN: The cucumber default ' + key.to_s + ' isn\'t a known option!'.yellow
|
158
|
+
return puts 'WARN: The task has no cucumber defaults!'.yellow unless @task.has_key? 'cucumber_defaults'
|
159
|
+
|
160
|
+
@task['cucumber_defaults'].each do |key, val|
|
161
|
+
case key
|
162
|
+
when 'tags', 'name'
|
163
|
+
add_multiple key, val
|
164
|
+
when 'format'
|
165
|
+
unless @parameters.has_key? key
|
166
|
+
@parameters[key] = '--' + key.downcase + ' ' + val.to_s
|
167
|
+
end
|
168
|
+
when 'strict', 'verbose', 'guess', 'expand'
|
169
|
+
unless @parameters.has_key? key && @parameters[key] == true
|
170
|
+
@parameters[key] = '--' + key.downcase
|
171
|
+
end
|
172
|
+
when 'dry_run'
|
173
|
+
unless @parameters.has_key? key && @parameters[key] == true
|
174
|
+
@parameters[key] = '--dry-run'
|
207
175
|
end
|
176
|
+
else
|
177
|
+
puts "WARN: The cucumber default #{key} isn't a known option!".yellow
|
208
178
|
end
|
209
|
-
else
|
210
|
-
puts 'WARN: The task has no cucumber defaults!'.yellow
|
211
179
|
end
|
212
180
|
end
|
213
181
|
|
@@ -224,29 +192,21 @@ module Cukesparse
|
|
224
192
|
end
|
225
193
|
|
226
194
|
case sym
|
227
|
-
when
|
228
|
-
@parameters[
|
229
|
-
@parameters[
|
230
|
-
when
|
231
|
-
@parameters[
|
232
|
-
@parameters[
|
195
|
+
when 'screen'
|
196
|
+
@parameters['screenwidth'] = "SCREENWIDTH=#{params[0]}"
|
197
|
+
@parameters['screenheight'] = "SCREENHEIGHT=#{params[1]}"
|
198
|
+
when 'position'
|
199
|
+
@parameters['xposition'] = "XPOSITION=#{params[0]}"
|
200
|
+
@parameters['yposition'] = "YPOSITION=#{params[1]}"
|
233
201
|
end
|
234
202
|
end
|
235
203
|
|
204
|
+
# Resets cukesparse
|
236
205
|
def reset!
|
237
|
-
@config =
|
206
|
+
@config = {}
|
238
207
|
@parameters = {}
|
239
208
|
@task = {}
|
240
209
|
@command = []
|
241
210
|
end
|
242
211
|
end
|
243
|
-
|
244
|
-
# defaults
|
245
|
-
self.parameters = {}
|
246
|
-
self.task = {}
|
247
|
-
self.command = []
|
248
|
-
end
|
249
|
-
|
250
|
-
Cukesparse.configure do |config|
|
251
|
-
config.config_file = 'config/tasks.yml'
|
252
212
|
end
|
data/lib/cukesparse/version.rb
CHANGED
@@ -8,17 +8,17 @@ describe '.add_multiple' do
|
|
8
8
|
|
9
9
|
context "when run with a single value" do
|
10
10
|
it "will add a key to parameters with the correct array value" do
|
11
|
-
Cukesparse.add_multiple(
|
12
|
-
Cukesparse.parameters.should have_key(
|
13
|
-
Cukesparse.parameters[
|
11
|
+
Cukesparse.add_multiple('tags', 'abc')
|
12
|
+
Cukesparse.parameters.should have_key('tags')
|
13
|
+
Cukesparse.parameters['tags'].should eql ['--tags abc']
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
17
|
context "when run with multiple values" do
|
18
18
|
it "will add a key to parameters with the correct array values" do
|
19
|
-
Cukesparse.add_multiple(
|
20
|
-
Cukesparse.parameters.should have_key(
|
21
|
-
Cukesparse.parameters[
|
19
|
+
Cukesparse.add_multiple('tags', ['abc', 'def', 'hij'])
|
20
|
+
Cukesparse.parameters.should have_key('tags')
|
21
|
+
Cukesparse.parameters['tags'].should eql ['--tags abc', '--tags def', '--tags hij']
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
@@ -8,7 +8,6 @@ describe '.check_for_parameters' do
|
|
8
8
|
|
9
9
|
context "when run with no paramaters defined" do
|
10
10
|
it "will return an warning if no parameters are provided" do
|
11
|
-
Cukesparse.instance_variable_set(:@parameters, {})
|
12
11
|
Cukesparse.should_receive("puts").with("\e[0;33;49mWARN: No parameters passed to cukesparse\e[0m")
|
13
12
|
Cukesparse.check_for_parameters
|
14
13
|
end
|
@@ -9,7 +9,6 @@ describe '.check_for_task' do
|
|
9
9
|
context "when run with no task defined" do
|
10
10
|
it "will return an error if no task is provided" do
|
11
11
|
ARGV.push('incorrect_task')
|
12
|
-
Cukesparse.config = {}
|
13
12
|
Cukesparse.should_receive("abort").with("\e[4;31;49mERROR: No task was passed to cukesparse!\e[0m")
|
14
13
|
Cukesparse.check_for_task
|
15
14
|
end
|
@@ -18,7 +17,7 @@ describe '.check_for_task' do
|
|
18
17
|
context "when run with multiple tasks defined" do
|
19
18
|
it "will return an error if multiple tasks are provided" do
|
20
19
|
ARGV.push('test_task', 'test_task1')
|
21
|
-
Cukesparse.
|
20
|
+
Cukesparse.config_file = File.join(fixture_path, 'valid_tasks.yml')
|
22
21
|
Cukesparse.load_config
|
23
22
|
Cukesparse.should_receive("puts").with("\e[0;33;49mWARN: Multiple tasks have been passed!\e[0m")
|
24
23
|
Cukesparse.check_for_task
|
@@ -28,7 +27,7 @@ describe '.check_for_task' do
|
|
28
27
|
context "when task is defined the @task instance variable will return a hash" do
|
29
28
|
it "will set the task in @task" do
|
30
29
|
ARGV.push('test_task')
|
31
|
-
Cukesparse.
|
30
|
+
Cukesparse.config_file = File.join(fixture_path, 'valid_tasks.yml')
|
32
31
|
Cukesparse.load_config
|
33
32
|
Cukesparse.check_for_task
|
34
33
|
Cukesparse.task.should be_an_instance_of Hash
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe '.debug' do
|
4
|
+
before :each do
|
5
|
+
ARGV.clear
|
6
|
+
Cukesparse.reset!
|
7
|
+
end
|
8
|
+
|
9
|
+
context "when run with task and --debug parameter" do
|
10
|
+
it "will return the correct output" do
|
11
|
+
ARGV.push('test_task1', '--debug')
|
12
|
+
Cukesparse.config_file = File.join(fixture_path, 'valid_tasks.yml')
|
13
|
+
Cukesparse.should_receive("puts").with("\e[0;33;49mDEBUG: Outputting ARGV passed\e[0m")
|
14
|
+
Cukesparse.should_receive("puts").with("[\"test_task1\", \"--debug\"]")
|
15
|
+
Cukesparse.should_receive("puts").with("\e[0;33;49mDEBUG: Outputting parsed config file\e[0m")
|
16
|
+
Cukesparse.should_receive("puts").with("{\"test_task\"=>{\"feature_order\"=>[\"features/featureOne\", \"features/featureTwo\", \"features/featureThree\"], \"cucumber_defaults\"=>{\"format\"=>\"pretty\", \"name\"=>[\"feature1\", \"feature2\"], \"tags\"=>[\"tags1\", \"tags2\"], \"strict\"=>true, \"verbose\"=>true, \"dry_run\"=>true, \"guess\"=>true, \"expand\"=>true}, \"runtime_defaults\"=>{\"environment\"=>\"release\", \"log_level\"=>\"debug\", \"cleanup\"=>true, \"database\"=>true, \"jenkins\"=>true, \"retries\"=>5, \"timeout\"=>60, \"screen\"=>\"1280/1024\", \"screenwidth\"=>1280, \"screenheight\"=>1024, \"position\"=>\"0/0\", \"xposition\"=>0, \"yposition\"=>0, \"highlight\"=>true}, \"defaults\"=>[\"--format html\", \"--out coverage/report.html\", \"-P -s\"]}, \"test_task1\"=>{\"feature_order\"=>[\"features/featureOne\", \"features/featureTwo\", \"features/featureThree\"], \"cucumber_defaults\"=>{\"format\"=>\"pretty\"}, \"runtime_defaults\"=>{\"environment\"=>\"release\", \"log_level\"=>\"debug\"}, \"defaults\"=>[\"--format html\", \"--out coverage/report.html\", \"-P -s\"]}, \"cucumber_default_unknown\"=>{\"feature_order\"=>[\"features/featureOne\", \"features/featureTwo\", \"features/featureThree\"], \"cucumber_defaults\"=>{\"testing\"=>\"pretty\"}, \"runtime_defaults\"=>{\"environment\"=>\"release\", \"log_level\"=>\"debug\"}, \"defaults\"=>[\"--format html\", \"--out coverage/report.html\", \"-P -s\"]}, \"no_defaults\"=>{\"feature_order\"=>[\"features/featureOne\", \"features/featureTwo\", \"features/featureThree\"]}}")
|
17
|
+
Cukesparse.should_receive("puts").with("\e[0;33;49mDEBUG: Outputting parameters created\e[0m")
|
18
|
+
Cukesparse.should_receive("puts").with("{\"debug\"=>\"DEBUG=TRUE\", \"format\"=>\"--format pretty\", \"environment\"=>\"ENVIRONMENT=release\", \"log_level\"=>\"LOG_LEVEL=debug\"}")
|
19
|
+
Cukesparse.should_receive("puts").with("\e[0;33;49mDEBUG: Outputting command created\e[0m")
|
20
|
+
Cukesparse.should_receive("puts").with("bundle exec cucumber --require features/ features/featureOne features/featureTwo features/featureThree DEBUG=TRUE --format pretty ENVIRONMENT=release LOG_LEVEL=debug --format html --out coverage/report.html -P -s")
|
21
|
+
Cukesparse.execute
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|