-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
examples.rb
58 lines (46 loc) · 1.91 KB
/
examples.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# frozen_string_literal: true
module CCK
# CCK::Examples
# The helper methods to determine the paths for each relevant item
module Examples
class << self
# Return the paths for each example that is of 'gherkin' type
def gherkin
Dir.entries(cck_features_folder_location).select do |file_or_folder|
next if file_or_folder.start_with?('.')
gherkin_example?(File.join(cck_features_folder_location, file_or_folder))
end
end
# Return the paths for each example that is of 'markdown' type
# NB: At the moment this (1 example - 'markdown'), isn't compatible with cucumber-ruby
def markdown
Dir.entries(cck_features_folder_location).select do |file_or_folder|
next if file_or_folder.start_with?('.')
markdown_example?(File.join(cck_features_folder_location, file_or_folder))
end
end
# Return the path for a specific example scenario based on its name
#
# i.e. 'attachments' would return the fully qualified path to the attachments folder
# which contains the feature, the ndjson file and any applicable assets to run the example
def feature_code_for(example_name)
path = File.join(cck_features_folder_location, example_name)
return path if File.directory?(path)
raise ArgumentError, "No feature code directory found in gem for CCK example: #{example_name}"
end
private
def cck_features_folder_location
File.expand_path("#{File.dirname(__FILE__)}/../../features/")
end
def gherkin_example?(example_folder)
file_type_in_folder?('.feature', example_folder)
end
def markdown_example?(example_folder)
file_type_in_folder?('.md', example_folder)
end
def file_type_in_folder?(extension, folder)
Dir.entries(folder).any? { |file| File.extname(file) == extension }
end
end
end
end