Class: Cukable::Converter
- Inherits:
-
Object
- Object
- Cukable::Converter
- Includes:
- Conversion, Helper
- Defined in:
- lib/cukable/conversion.rb
Overview
Main front-end for converting features, used by the cuke2fit script.
Instance Method Summary collapse
-
#create_accelerator(fitnesse_path) ⇒ Object
Create an empty
AaaAcceleratorpage under the given path. -
#create_feature_root(fitnesse_path) ⇒ Object
Create a page at the top level of the converted features, containing variable definitions needed to invoke rubyslim.
-
#create_setup_page(fitnesse_path) ⇒ Object
Create a SetUp page as a child of the given path.
-
#create_suite_stubs(fitnesse_path) ⇒ Object
Create a stub
content.txtfile in the given directory, and all ancestor directories, if acontent.txtdoes not already exist. -
#create_wiki_page(path, content, type = 'normal') ⇒ Object
Create a new wiki page at the given path, with the given content.
-
#features_to_fitnesse(features_path, fitnesse_path) ⇒ Object
Convert all .feature files in
features_pathto FitNesse wiki pages underfitnesse_path.
Methods included from Conversion
#feature_to_fitnesse, #fitnesse_to_features
Methods included from Helper
#clean_cell, #clean_filename, #literalize, #remove_cruft, #table_digest, #unescape, #wikify, #wikify_path
Instance Method Details
#create_accelerator(fitnesse_path) ⇒ Object
Create an empty AaaAccelerator page under the given path.
306 307 308 309 310 |
# File 'lib/cukable/conversion.rb', line 306
def create_accelerator(fitnesse_path)
accel_path = File.join(fitnesse_path, 'AaaAccelerator')
FileUtils.mkdir_p(accel_path)
create_wiki_page(accel_path, '', 'test')
end
|
#create_feature_root(fitnesse_path) ⇒ Object
Create a page at the top level of the converted features, containing variable definitions needed to invoke rubyslim
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 |
# File 'lib/cukable/conversion.rb', line 273
def create_feature_root(fitnesse_path)
FileUtils.mkdir_p(fitnesse_path)
content = [
'These variables must be defined for rubyslim to work:',
'!define TEST_SYSTEM {slim}',
'!define TEST_RUNNER {rubyslim}',
'!define COMMAND_PATTERN {rubyslim}',
'',
'Extra command-line arguments to pass to Cucumber:',
'!define CUCUMBER_ARGS {}',
'',
'!contents -R9 -p -f -h',
].join("\n")
create_wiki_page(fitnesse_path, content, 'suite')
end
|
#create_setup_page(fitnesse_path) ⇒ Object
Create a SetUp page as a child of the given path.
291 292 293 294 295 296 297 298 299 300 301 302 |
# File 'lib/cukable/conversion.rb', line 291
def create_setup_page(fitnesse_path)
setup_path = File.join(fitnesse_path, 'SetUp')
FileUtils.mkdir_p(setup_path)
content = [
'!| import |',
'| Cukable |',
'',
'| script | Cuke |',
'| accelerate; | ${PAGE_PATH}.${PAGE_NAME} | ${CUCUMBER_ARGS} |',
].join("\n")
create_wiki_page(setup_path, content)
end
|
#create_suite_stubs(fitnesse_path) ⇒ Object
Create a stub content.txt file in the given directory, and all
ancestor directories, if a content.txt does not already exist.
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/cukable/conversion.rb', line 250
def create_suite_stubs(fitnesse_path)
# Content string to put in each stub file
content = '!contents -R9 -p -f -h'
# Starting with `fitnesse_path`
path = fitnesse_path
# Until there are no more ancestor directories
while path != '.'
# If there is no content.txt file, create one
if !File.exists?(File.join(path, 'content.txt'))
create_wiki_page(path, content, 'suite')
end
# If there is no accelerator child, create one
if !File.directory?(File.join(path, 'AaaAccelerator'))
create_accelerator(path)
end
# Get the parent path
path = File.dirname(path)
end
end
|
#create_wiki_page(path, content, type = 'normal') ⇒ Object
Create a new wiki page at the given path, with the given content.
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/cukable/conversion.rb', line 208
def create_wiki_page(path, content, type='normal')
FileUtils.mkdir_p(path)
# Write the content
File.open(File.join(path, 'content.txt'), 'w') do |file|
file.write(content)
end
# Write the properties.xml
File.open(File.join(path, 'properties.xml'), 'w') do |file|
file.puts '<?xml version="1.0"?>'
file.puts '<properties>'
file.puts ' <Edit>true</Edit>'
file.puts ' <Files>true</Files>'
file.puts ' <Properties>true</Properties>'
file.puts ' <RecentChanges>true</RecentChanges>'
file.puts ' <Refactor>true</Refactor>'
file.puts ' <Search>true</Search>'
if type == 'test'
file.puts ' <Test/>'
elsif type == 'suite'
file.puts ' <Suite/>'
end
file.puts ' <Versions>true</Versions>'
file.puts ' <WhereUsed>true</WhereUsed>'
file.puts '</properties>'
end
end
|
#features_to_fitnesse(features_path, fitnesse_path) ⇒ Object
Convert all .feature files in features_path to FitNesse wiki pages
under fitnesse_path.
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/cukable/conversion.rb', line 164
def features_to_fitnesse(features_path, fitnesse_path)
# Status messages to return
messages = []
# Ensure FitNesse directory already exists
if !File.directory?(fitnesse_path)
raise ArgumentError, "FitNesse path must be an existing directory."
end
# Create a root-level suite and SetUp page
root_path = File.join(fitnesse_path, wikify_path(features_path))
create_feature_root(root_path)
create_setup_page(root_path)
# Get all .feature files
features = Dir.glob(File.join(features_path, '**', '*feature'))
# Create a test page for each .feature file
features.each do |feature_path|
# Determine the appropriate wiki path name
wiki_path = File.join(fitnesse_path, wikify_path(feature_path))
# Fill ancestors of the wiki path with stubs for suites
create_suite_stubs(File.dirname(wiki_path))
# Convert the .feature to wikitext
content = feature_to_fitnesse(File.open(feature_path)).join("\n")
# Write the wikitext to a wiki page
create_wiki_page(wiki_path, content, 'test')
# Show user some status output
messages << "OK: #{feature_path} => #{wiki_path}"
end
return messages
end
|