rspec-usecases 0.0.12 → 0.0.37
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/.github/workflows/main.yml +2 -0
- data/.gitignore +5 -0
- data/.rubocop.yml +7 -0
- data/Gemfile +19 -10
- data/Guardfile +1 -0
- data/STORIES.md +25 -4
- data/bin/console +1 -1
- data/docs/regexp-01.md +56 -0
- data/docs/samples.md +62 -0
- data/docs/test.debug.txt +93 -0
- data/docs/test.json +172 -0
- data/docs/test.md +39 -0
- data/lib/rspec/usecases.rb +20 -4
- data/lib/rspec/usecases/configure.rb +40 -0
- data/lib/rspec/usecases/contents/base_content.rb +145 -0
- data/lib/rspec/usecases/contents/code.rb +33 -0
- data/lib/rspec/usecases/contents/outcome.rb +27 -0
- data/lib/rspec/usecases/document.rb +173 -0
- data/lib/rspec/usecases/documentor.rb +35 -0
- data/lib/rspec/usecases/generator/base_generator.rb +58 -0
- data/lib/rspec/usecases/generator/debug_generator.rb +106 -0
- data/lib/rspec/usecases/generator/json_generator.rb +39 -0
- data/lib/rspec/usecases/generator/markdown_generator.rb +136 -0
- data/lib/rspec/usecases/groups/base_group.rb +116 -0
- data/lib/rspec/usecases/groups/group.rb +14 -0
- data/lib/rspec/usecases/groups/usecase.rb +30 -0
- data/lib/rspec/usecases/helpers/uc_file_as_markdown_content.rb +26 -0
- data/lib/rspec/usecases/helpers/uc_grab_lines.rb +54 -0
- data/lib/rspec/usecases/options/debug_options.rb +33 -0
- data/lib/rspec/usecases/options/document_options.rb +24 -0
- data/lib/rspec/usecases/options/dynamic_options.rb +102 -0
- data/lib/rspec/usecases/options/json_options.rb +32 -0
- data/lib/rspec/usecases/options/markdown_options.rb +37 -0
- data/lib/rspec/usecases/version.rb +1 -1
- data/rspec-usecases.gemspec +6 -0
- metadata +45 -9
- data/lib/rspec/usecases/content.rb +0 -155
- data/lib/rspec/usecases/content_code.rb +0 -42
- data/lib/rspec/usecases/content_outcome.rb +0 -30
- data/lib/rspec/usecases/usecase.rb +0 -103
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Rspec
|
4
|
+
module Usecases
|
5
|
+
module Groups
|
6
|
+
# Group can be used as a basic container, it is
|
7
|
+
# similar in nature to describe and context but
|
8
|
+
# it will enter the flatten_group_hierarchy as
|
9
|
+
# it is a known usecase type
|
10
|
+
class Group < Rspec::Usecases::Groups::BaseGroup
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Rspec
|
4
|
+
module Usecases
|
5
|
+
module Groups
|
6
|
+
# A usecase stores documentation for a single code usage scenario.
|
7
|
+
class Usecase < Rspec::Usecases::Groups::BaseGroup
|
8
|
+
# Usage contains a sample on how to call some code
|
9
|
+
attr_reader :usage
|
10
|
+
|
11
|
+
# Usage description gives extra details to support the usage example
|
12
|
+
attr_reader :usage_description
|
13
|
+
|
14
|
+
def build_attributes(example_group)
|
15
|
+
super(example_group)
|
16
|
+
|
17
|
+
@usage = example_group.metadata[:usage] || ''
|
18
|
+
@usage_description = example_group.metadata[:usage_description] || ''
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_h
|
22
|
+
{
|
23
|
+
usage: usage,
|
24
|
+
usage_description: usage_description
|
25
|
+
}.merge(super.to_h)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Rspec
|
4
|
+
module Usecases
|
5
|
+
# These helpers can be used from RSpec tests
|
6
|
+
module Helpers
|
7
|
+
# Builds markdown ```content block``` by injecting content
|
8
|
+
# from an existing file.
|
9
|
+
#
|
10
|
+
# @param [String] filename to read content from
|
11
|
+
# @param [Array<Integer>] lines (optional) - specific list of line numbers to grab using a 1 based index
|
12
|
+
# @param [String] code_type (optional) - what type of content is this, eg. javascript, ruby, css
|
13
|
+
def uc_file_as_markdown_content(filename, lines: nil, code_type: nil)
|
14
|
+
content = File.read(filename)
|
15
|
+
|
16
|
+
content = uc_grab_lines(content, lines) if lines
|
17
|
+
|
18
|
+
# To Deprecate: It may not be smart to support the code_type arg
|
19
|
+
# it is probably better to pass content into markdown
|
20
|
+
# components in raw format and let them apply this value
|
21
|
+
content = "```#{code_type}\n#{content}\n```" unless code_type.nil?
|
22
|
+
content
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Rspec
|
4
|
+
module Usecases
|
5
|
+
# These helpers can be used from RSpec tests
|
6
|
+
module Helpers
|
7
|
+
# Grab lines from content into lines array and then extract specific lines
|
8
|
+
#
|
9
|
+
# Note that this is a 1 based index, instead of a traditional zero based index
|
10
|
+
#
|
11
|
+
# An array of [to, from] can be passed to grab specific lines
|
12
|
+
# from the content
|
13
|
+
#
|
14
|
+
# content = <<~TEXT.strip
|
15
|
+
# line 1
|
16
|
+
# line 2
|
17
|
+
# #{' '}
|
18
|
+
# line 4
|
19
|
+
# line 5
|
20
|
+
# TEXT
|
21
|
+
#
|
22
|
+
# @example - grab specific line numbers
|
23
|
+
#
|
24
|
+
# lines = uc_grab_lines(content, [1, 3, 5])
|
25
|
+
# it { lines.to match_array(['line 1', '', 'line 5']) }
|
26
|
+
#
|
27
|
+
# @example - specific and range of line numbers
|
28
|
+
#
|
29
|
+
# lines = uc_grab_lines(content, [1, *(3..4), 5])
|
30
|
+
# it { lines.to match_array(['line 1', '', 'line 4', 'line 5']) }
|
31
|
+
#
|
32
|
+
# @raise [Rspec::Usecases::Error] if lines to include contains a value less than 1
|
33
|
+
# @raise [Rspec::Usecases::Error] if lines to include contains a value greater than the content.line_count
|
34
|
+
#
|
35
|
+
# @param [Array<Integer>] lines_to_include is a list of line numbers to pluck from string
|
36
|
+
# rubocop:disable Metrics/AbcSize
|
37
|
+
def uc_grab_lines(content, lines_to_include)
|
38
|
+
content_lines = content.lines
|
39
|
+
|
40
|
+
line_nos = lines_to_include.sort.collect
|
41
|
+
|
42
|
+
raise(Rspec::Usecases::Error, 'Line numbers must start from 1') if line_nos.min < 1
|
43
|
+
|
44
|
+
raise(Rspec::Usecases::Error, "Line number out of range - content_length: #{content_lines.length} - line_no: #{line_nos.max}") if
|
45
|
+
content_lines.length <= line_nos.max - 1
|
46
|
+
|
47
|
+
output_lines = line_nos.map { |line_no| content_lines[line_no - 1].chomp }
|
48
|
+
|
49
|
+
output_lines.join("\n")
|
50
|
+
end
|
51
|
+
# rubocop:enable Metrics/AbcSize
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Rspec
|
4
|
+
module Usecases
|
5
|
+
# Debug Options
|
6
|
+
module Options
|
7
|
+
# Options for debugging usecases objects
|
8
|
+
class DebugOptions < Rspec::Usecases::Options::DynamicOptions
|
9
|
+
def initialize(config)
|
10
|
+
super(:debug, config, {
|
11
|
+
format: :detail,
|
12
|
+
print: true,
|
13
|
+
write: false,
|
14
|
+
file: '',
|
15
|
+
open: false
|
16
|
+
})
|
17
|
+
end
|
18
|
+
|
19
|
+
def printable?
|
20
|
+
self.print == true
|
21
|
+
end
|
22
|
+
|
23
|
+
def writable?
|
24
|
+
write == true
|
25
|
+
end
|
26
|
+
|
27
|
+
def openable?
|
28
|
+
self.open == true
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Rspec
|
4
|
+
module Usecases
|
5
|
+
module Options
|
6
|
+
# Document Options
|
7
|
+
class DocumentOptions
|
8
|
+
attr_reader :json
|
9
|
+
attr_reader :debug
|
10
|
+
attr_reader :markdown
|
11
|
+
|
12
|
+
def initialize(config)
|
13
|
+
@json = Rspec::Usecases::Options::JsonOptions.new(config[:json])
|
14
|
+
@debug = Rspec::Usecases::Options::DebugOptions.new(config[:debug])
|
15
|
+
@markdown = Rspec::Usecases::Options::MarkdownOptions.new(config[:markdown])
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_h
|
19
|
+
Rspec::Usecases::Options::DynamicOptions.struct_to_hash(OpenStruct.new(json: json, debug: debug, markdown: markdown))
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Rspec
|
4
|
+
module Usecases
|
5
|
+
# Dynamic Option
|
6
|
+
module Options
|
7
|
+
# Dynamic option will convert a value
|
8
|
+
class DynamicOptions < OpenStruct
|
9
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
10
|
+
def initialize(option_key, value, api = {})
|
11
|
+
super()
|
12
|
+
|
13
|
+
# This will load app the default values
|
14
|
+
parse(api)
|
15
|
+
|
16
|
+
self.empty = value.nil? || (value.is_a?(Hash) && value.empty?)
|
17
|
+
|
18
|
+
if !value.nil? && (value.is_a?(TrueClass) || value.is_a?(FalseClass))
|
19
|
+
self.empty = value.is_a?(FalseClass)
|
20
|
+
return
|
21
|
+
end
|
22
|
+
|
23
|
+
return if empty?
|
24
|
+
return if value == option_key
|
25
|
+
|
26
|
+
parse(value)
|
27
|
+
end
|
28
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
29
|
+
|
30
|
+
def active?
|
31
|
+
!empty?
|
32
|
+
end
|
33
|
+
|
34
|
+
def empty?
|
35
|
+
empty
|
36
|
+
end
|
37
|
+
|
38
|
+
def to_h
|
39
|
+
DynamicOptions.struct_to_hash(self)
|
40
|
+
end
|
41
|
+
|
42
|
+
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/AbcSize
|
43
|
+
def self.struct_to_hash(data)
|
44
|
+
# No test yet
|
45
|
+
if data.is_a?(Array)
|
46
|
+
return data.map { |v| v.is_a?(OpenStruct) ? struct_to_hash(v) : v }
|
47
|
+
end
|
48
|
+
|
49
|
+
data.each_pair.with_object({}) do |(key, value), hash|
|
50
|
+
case value
|
51
|
+
when OpenStruct
|
52
|
+
hash[key] = struct_to_hash(value)
|
53
|
+
when Array
|
54
|
+
# No test yet
|
55
|
+
values = value.map { |v| v.is_a?(OpenStruct) ? struct_to_hash(v) : v }
|
56
|
+
hash[key] = values
|
57
|
+
else
|
58
|
+
hash[key] = value
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/AbcSize
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def parse(value)
|
67
|
+
case value
|
68
|
+
when Array
|
69
|
+
parse_array(value)
|
70
|
+
when Hash
|
71
|
+
parse_hash(value)
|
72
|
+
else
|
73
|
+
parse_value(value)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def parse_hash(data)
|
78
|
+
data.each do |k, v|
|
79
|
+
send("#{k}=", v)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def parse_array(values)
|
84
|
+
values.map do |value|
|
85
|
+
case value
|
86
|
+
when Symbol, String
|
87
|
+
parse_symbol_or_string(value)
|
88
|
+
when Hash
|
89
|
+
parse_hash(value)
|
90
|
+
else
|
91
|
+
raise Rspec::Usecases::Error, 'Unknown option paramater'
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def parse_symbol_or_string(value)
|
97
|
+
send("#{value}=", true)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Rspec
|
4
|
+
module Usecases
|
5
|
+
module Options
|
6
|
+
# Options for turning usecases into JSON objects
|
7
|
+
class JsonOptions < Rspec::Usecases::Options::DynamicOptions
|
8
|
+
def initialize(config)
|
9
|
+
super(:json, config, {
|
10
|
+
format: :detail,
|
11
|
+
print: true,
|
12
|
+
write: false,
|
13
|
+
file: '',
|
14
|
+
open: false
|
15
|
+
})
|
16
|
+
end
|
17
|
+
|
18
|
+
def printable?
|
19
|
+
self.print == true
|
20
|
+
end
|
21
|
+
|
22
|
+
def writable?
|
23
|
+
write == true
|
24
|
+
end
|
25
|
+
|
26
|
+
def openable?
|
27
|
+
self.open == true
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Rspec
|
4
|
+
module Usecases
|
5
|
+
module Options
|
6
|
+
# Options for generating MarkDown files from usecases
|
7
|
+
class MarkdownOptions < Rspec::Usecases::Options::DynamicOptions
|
8
|
+
def initialize(config)
|
9
|
+
super(:markdown, config, {
|
10
|
+
format: :detail,
|
11
|
+
print: true,
|
12
|
+
write: false,
|
13
|
+
file: '',
|
14
|
+
pretty: false,
|
15
|
+
open: false
|
16
|
+
})
|
17
|
+
end
|
18
|
+
|
19
|
+
def printable?
|
20
|
+
self.print == true
|
21
|
+
end
|
22
|
+
|
23
|
+
def writable?
|
24
|
+
write == true
|
25
|
+
end
|
26
|
+
|
27
|
+
def prettier?
|
28
|
+
pretty == true
|
29
|
+
end
|
30
|
+
|
31
|
+
def openable?
|
32
|
+
self.open == true
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/rspec-usecases.gemspec
CHANGED
@@ -37,6 +37,12 @@ Gem::Specification.new do |spec|
|
|
37
37
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
38
38
|
spec.require_paths = ['lib']
|
39
39
|
# spec.extensions = ['ext/rspec_usecases/extconf.rb']
|
40
|
+
spec.extra_rdoc_files = ['README.md', 'STORIES.md', 'USAGE.md']
|
41
|
+
spec.rdoc_options += [
|
42
|
+
'--title', 'rspec-usecases by appydave.com',
|
43
|
+
'--main', 'README.md',
|
44
|
+
'--files STORIES.MD USAGE.MD'
|
45
|
+
]
|
40
46
|
|
41
47
|
# spec.add_dependency 'tty-box', '~> 0.5.0'
|
42
48
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-usecases
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.37
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Cruwys
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: " Rspec Usecases helps to write self-documenting code usage examples
|
14
14
|
that execute as normal unit tests while outputting documentation in varied formats\n"
|
@@ -16,7 +16,10 @@ email:
|
|
16
16
|
- david@ideasmen.com.au
|
17
17
|
executables: []
|
18
18
|
extensions: []
|
19
|
-
extra_rdoc_files:
|
19
|
+
extra_rdoc_files:
|
20
|
+
- README.md
|
21
|
+
- STORIES.md
|
22
|
+
- USAGE.md
|
20
23
|
files:
|
21
24
|
- ".github/workflows/main.yml"
|
22
25
|
- ".gitignore"
|
@@ -31,18 +34,46 @@ files:
|
|
31
34
|
- Rakefile
|
32
35
|
- STORIES.md
|
33
36
|
- USAGE.md
|
37
|
+
- _/app
|
38
|
+
- _/def-ruby-gem
|
39
|
+
- _/tem-ruby-gem
|
34
40
|
- bin/console
|
35
41
|
- bin/k
|
36
42
|
- bin/kgitsync
|
37
43
|
- bin/khotfix
|
44
|
+
- bin/runonce/common.sh
|
45
|
+
- bin/runonce/setup-chmod.sh
|
46
|
+
- bin/runonce/setup-git.sh
|
38
47
|
- bin/setup
|
48
|
+
- docs/regexp-01.md
|
49
|
+
- docs/samples.md
|
50
|
+
- docs/test.debug.txt
|
51
|
+
- docs/test.json
|
52
|
+
- docs/test.md
|
53
|
+
- generate_markdown.md
|
39
54
|
- hooks/pre-commit
|
40
55
|
- hooks/update-version
|
41
56
|
- lib/rspec/usecases.rb
|
42
|
-
- lib/rspec/usecases/
|
43
|
-
- lib/rspec/usecases/
|
44
|
-
- lib/rspec/usecases/
|
45
|
-
- lib/rspec/usecases/
|
57
|
+
- lib/rspec/usecases/configure.rb
|
58
|
+
- lib/rspec/usecases/contents/base_content.rb
|
59
|
+
- lib/rspec/usecases/contents/code.rb
|
60
|
+
- lib/rspec/usecases/contents/outcome.rb
|
61
|
+
- lib/rspec/usecases/document.rb
|
62
|
+
- lib/rspec/usecases/documentor.rb
|
63
|
+
- lib/rspec/usecases/generator/base_generator.rb
|
64
|
+
- lib/rspec/usecases/generator/debug_generator.rb
|
65
|
+
- lib/rspec/usecases/generator/json_generator.rb
|
66
|
+
- lib/rspec/usecases/generator/markdown_generator.rb
|
67
|
+
- lib/rspec/usecases/groups/base_group.rb
|
68
|
+
- lib/rspec/usecases/groups/group.rb
|
69
|
+
- lib/rspec/usecases/groups/usecase.rb
|
70
|
+
- lib/rspec/usecases/helpers/uc_file_as_markdown_content.rb
|
71
|
+
- lib/rspec/usecases/helpers/uc_grab_lines.rb
|
72
|
+
- lib/rspec/usecases/options/debug_options.rb
|
73
|
+
- lib/rspec/usecases/options/document_options.rb
|
74
|
+
- lib/rspec/usecases/options/dynamic_options.rb
|
75
|
+
- lib/rspec/usecases/options/json_options.rb
|
76
|
+
- lib/rspec/usecases/options/markdown_options.rb
|
46
77
|
- lib/rspec/usecases/version.rb
|
47
78
|
- rspec-usecases.gemspec
|
48
79
|
homepage: http://appydave.com/gems/rspec-usecases
|
@@ -53,7 +84,12 @@ metadata:
|
|
53
84
|
source_code_uri: https://github.com/klueless-io/rspec-usecases
|
54
85
|
changelog_uri: https://github.com/klueless-io/rspec-usecases/commits/master
|
55
86
|
post_install_message:
|
56
|
-
rdoc_options:
|
87
|
+
rdoc_options:
|
88
|
+
- "--title"
|
89
|
+
- rspec-usecases by appydave.com
|
90
|
+
- "--main"
|
91
|
+
- README.md
|
92
|
+
- "--files STORIES.MD USAGE.MD"
|
57
93
|
require_paths:
|
58
94
|
- lib
|
59
95
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -67,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
67
103
|
- !ruby/object:Gem::Version
|
68
104
|
version: '0'
|
69
105
|
requirements: []
|
70
|
-
rubygems_version: 3.2.
|
106
|
+
rubygems_version: 3.2.7
|
71
107
|
signing_key:
|
72
108
|
specification_version: 4
|
73
109
|
summary: Rspec Usecases helps to write self-documenting code usage examples that execute
|