nrser 0.2.2 → 0.3.0
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/lib/nrser/char/alpha_numeric_sub.rb +1 -2
- data/lib/nrser/char.rb +0 -6
- data/lib/nrser/core_ext/array.rb +120 -0
- data/lib/nrser/core_ext/binding.rb +44 -0
- data/lib/nrser/{functions → core_ext}/enumerable/find_map.rb +18 -15
- data/lib/nrser/{ext → core_ext}/enumerable.rb +10 -24
- data/lib/nrser/core_ext/exception.rb +30 -0
- data/lib/nrser/core_ext/hash/extract_values_at.rb +49 -0
- data/lib/nrser/core_ext/hash/transform_values_with_keys.rb +24 -0
- data/lib/nrser/core_ext/hash.rb +50 -0
- data/lib/nrser/core_ext/module/method_objects.rb +96 -0
- data/lib/nrser/core_ext/module/names.rb +69 -0
- data/lib/nrser/core_ext/module/source_locations.rb +214 -0
- data/lib/nrser/core_ext/module.rb +2 -0
- data/lib/nrser/core_ext/object/lazy_var.rb +31 -0
- data/lib/nrser/core_ext/object.rb +46 -0
- data/lib/nrser/core_ext/open_struct.rb +6 -0
- data/lib/nrser/{ext → core_ext}/pathname.rb +8 -5
- data/lib/nrser/{ext → core_ext}/string.rb +6 -12
- data/lib/nrser/core_ext/symbol.rb +13 -0
- data/lib/nrser/core_ext/time.rb +46 -0
- data/lib/nrser/core_ext.rb +13 -0
- data/lib/nrser/errors/abstract_method_error.rb +150 -0
- data/lib/nrser/errors/argument_error.rb +42 -0
- data/lib/nrser/errors/nicer_error.rb +298 -72
- data/lib/nrser/errors/type_error.rb +46 -0
- data/lib/nrser/errors.rb +4 -53
- data/lib/nrser/ext/tree.rb +3 -0
- data/lib/nrser/functions/enumerable/associate.rb +6 -9
- data/lib/nrser/functions/enumerable/include_slice.rb +2 -3
- data/lib/nrser/functions/enumerable.rb +1 -3
- data/lib/nrser/functions/exception.rb +1 -1
- data/lib/nrser/functions/hash.rb +0 -6
- data/lib/nrser/functions/merge_by.rb +2 -2
- data/lib/nrser/functions/module/method_objects.rb +77 -0
- data/lib/nrser/functions/module.rb +1 -2
- data/lib/nrser/functions/open_struct.rb +25 -35
- data/lib/nrser/functions/proc.rb +1 -6
- data/lib/nrser/functions/string/looks_like.rb +32 -1
- data/lib/nrser/functions/string.rb +1 -40
- data/lib/nrser/functions/text/lines.rb +2 -1
- data/lib/nrser/functions.rb +0 -1
- data/lib/nrser/graph/tsorter.rb +41 -0
- data/lib/nrser/labs/core_ext/binding.rb +37 -0
- data/lib/nrser/labs/stash.rb +372 -0
- data/lib/nrser/{logging → log}/appender/sync.rb +3 -3
- data/lib/nrser/log/appender.rb +3 -0
- data/lib/nrser/{logging → log}/formatters/color.rb +47 -20
- data/lib/nrser/log/formatters/mixin.rb +270 -0
- data/lib/nrser/{logging → log}/formatters.rb +0 -0
- data/lib/nrser/log/logger.rb +229 -0
- data/lib/nrser/log/mixin.rb +56 -0
- data/lib/nrser/log.rb +723 -0
- data/lib/nrser/message.rb +24 -3
- data/lib/nrser/meta/source/location.rb +158 -0
- data/lib/nrser/meta.rb +1 -1
- data/lib/nrser/props/class_methods.rb +118 -0
- data/lib/nrser/props/immutable/hash.rb +111 -0
- data/lib/nrser/props/immutable/hash_variable.rb +82 -0
- data/lib/nrser/props/immutable/instance_variables.rb +48 -0
- data/lib/nrser/props/immutable/vector.rb +107 -0
- data/lib/nrser/props/instance_methods.rb +184 -0
- data/lib/nrser/props/metadata.rb +359 -0
- data/lib/nrser/props/mutable/instance_variables.rb +60 -0
- data/lib/nrser/props/mutable/stash.rb +199 -0
- data/lib/nrser/{meta/props → props}/prop.rb +217 -112
- data/lib/nrser/props/storage/instance_variable.rb +85 -0
- data/lib/nrser/props/storage/instance_variables.rb +67 -0
- data/lib/nrser/props/storage/key.rb +88 -0
- data/lib/nrser/props.rb +9 -0
- data/lib/nrser/refinements/sugar.rb +41 -0
- data/lib/nrser/refinements/types.rb +2 -2
- data/lib/nrser/refinements.rb +14 -16
- data/lib/nrser/rspex/example_group/describe_attribute.rb +24 -0
- data/lib/nrser/rspex/example_group/describe_called_with.rb +1 -6
- data/lib/nrser/rspex/example_group/{describe_use_case.rb → describe_case.rb} +6 -3
- data/lib/nrser/rspex/example_group/describe_class.rb +1 -0
- data/lib/nrser/rspex/example_group/describe_group.rb +29 -0
- data/lib/nrser/rspex/example_group/describe_instance_method.rb +2 -2
- data/lib/nrser/rspex/example_group/describe_message.rb +35 -0
- data/lib/nrser/rspex/example_group/describe_method.rb +23 -2
- data/lib/nrser/rspex/example_group/describe_module.rb +19 -0
- data/lib/nrser/rspex/example_group/describe_response_to.rb +32 -0
- data/lib/nrser/rspex/example_group/describe_section.rb +38 -0
- data/lib/nrser/rspex/example_group/describe_sent_to.rb +52 -0
- data/lib/nrser/rspex/example_group/describe_source_file.rb +49 -0
- data/lib/nrser/rspex/example_group/describe_spec_file.rb +41 -108
- data/lib/nrser/rspex/example_group/describe_when.rb +14 -7
- data/lib/nrser/rspex/example_group/describe_x.rb +39 -12
- data/lib/nrser/rspex/example_group/overrides.rb +66 -0
- data/lib/nrser/rspex/example_group.rb +20 -252
- data/lib/nrser/rspex/format.rb +83 -17
- data/lib/nrser/rspex.rb +4 -34
- data/lib/nrser/sugar/method_missing_forwarder.rb +50 -0
- data/lib/nrser/{env → sys/env}/path.rb +1 -2
- data/lib/nrser/{env.rb → sys/env.rb} +2 -1
- data/lib/nrser/sys.rb +5 -0
- data/lib/nrser/types/any.rb +36 -7
- data/lib/nrser/types/{array.rb → arrays.rb} +32 -81
- data/lib/nrser/types/attrs.rb +68 -15
- data/lib/nrser/types/booleans.rb +95 -34
- data/lib/nrser/types/bounded.rb +12 -10
- data/lib/nrser/types/combinators.rb +74 -37
- data/lib/nrser/types/errors/check_error.rb +86 -0
- data/lib/nrser/types/errors/from_string_error.rb +82 -0
- data/lib/nrser/types/factory.rb +91 -0
- data/lib/nrser/types/hashes.rb +171 -26
- data/lib/nrser/types/in.rb +25 -12
- data/lib/nrser/types/is.rb +50 -18
- data/lib/nrser/types/is_a.rb +52 -33
- data/lib/nrser/types/labels.rb +6 -33
- data/lib/nrser/types/maybe.rb +12 -4
- data/lib/nrser/types/nil.rb +24 -4
- data/lib/nrser/types/not.rb +6 -16
- data/lib/nrser/types/numbers.rb +94 -57
- data/lib/nrser/types/pairs.rb +57 -57
- data/lib/nrser/types/paths.rb +112 -133
- data/lib/nrser/types/responds.rb +64 -74
- data/lib/nrser/types/shape.rb +29 -24
- data/lib/nrser/types/strings.rb +25 -17
- data/lib/nrser/types/symbols.rb +19 -17
- data/lib/nrser/types/trees.rb +18 -70
- data/lib/nrser/types/tuples.rb +36 -40
- data/lib/nrser/types/type.rb +342 -91
- data/lib/nrser/types/when.rb +40 -18
- data/lib/nrser/types/where.rb +94 -9
- data/lib/nrser/types.rb +72 -63
- data/lib/nrser/version.rb +1 -1
- data/lib/nrser.rb +18 -18
- data/spec/lib/nrser/{functions/binding/template_spec.rb → core_ext/binding/erb_spec.rb} +5 -5
- data/spec/lib/nrser/{functions → core_ext}/enumerable/find_map_spec.rb +8 -6
- data/spec/lib/nrser/{refinements → core_ext}/hash_spec.rb +9 -22
- data/spec/lib/nrser/errors/abstract_method_error_spec.rb +12 -5
- data/spec/lib/nrser/functions/enumerable/{to_h_by_spec.rb → associate_spec.rb} +1 -1
- data/spec/lib/nrser/functions/merge_by_spec.rb +1 -1
- data/spec/lib/nrser/functions/tree/each_branch_spec.rb +3 -3
- data/spec/lib/nrser/functions/tree/transform_spec.rb +14 -15
- data/spec/lib/nrser/gem_ext/hamster/json_spec.rb +4 -0
- data/spec/lib/nrser/meta/source/location_spec.rb +86 -0
- data/spec/lib/nrser/props/immutable/hash_spec.rb +297 -0
- data/spec/lib/nrser/props/immutable/vector_spec.rb +296 -0
- data/spec/lib/nrser/{meta/props_spec.rb → props/original_props_spec.rb} +11 -16
- data/spec/lib/nrser/{meta/props → props}/to_and_from_data_spec.rb +10 -8
- data/spec/lib/nrser/refinements/array_spec.rb +2 -15
- data/spec/lib/nrser/refinements/erb_spec.rb +5 -7
- data/spec/lib/nrser/refinements/set_spec.rb +2 -15
- data/spec/lib/nrser/{env → sys/env}/path/insert_spec.rb +4 -2
- data/spec/lib/nrser/{env → sys/env}/path_spec.rb +4 -2
- data/spec/lib/nrser/types/array_spec.rb +8 -8
- data/spec/lib/nrser/types/paths_spec.rb +15 -18
- data/spec/spec_helper.rb +4 -0
- metadata +109 -69
- data/lib/nrser/ext/binding.rb +0 -36
- data/lib/nrser/ext/module.rb +0 -62
- data/lib/nrser/ext.rb +0 -8
- data/lib/nrser/functions/binding.rb +0 -76
- data/lib/nrser/functions/enumerable/map_keys.rb +0 -0
- data/lib/nrser/functions/enumerable/map_values.rb +0 -94
- data/lib/nrser/functions/hash/deep_merge.rb +0 -57
- data/lib/nrser/functions/hash/except_keys.rb +0 -44
- data/lib/nrser/functions/hash/slice_keys.rb +0 -43
- data/lib/nrser/functions/hash/stringify_keys.rb +0 -55
- data/lib/nrser/functions/hash/symbolize_keys.rb +0 -57
- data/lib/nrser/functions/hash/transform_keys.rb +0 -140
- data/lib/nrser/functions/module/methods.rb +0 -206
- data/lib/nrser/functions/module/source_locations.rb +0 -213
- data/lib/nrser/logging/appender.rb +0 -3
- data/lib/nrser/logging.rb +0 -353
- data/lib/nrser/meta/props/base.rb +0 -31
- data/lib/nrser/meta/props.rb +0 -357
- data/lib/nrser/refinements/array.rb +0 -133
- data/lib/nrser/refinements/binding.rb +0 -6
- data/lib/nrser/refinements/enumerator.rb +0 -5
- data/lib/nrser/refinements/exception.rb +0 -35
- data/lib/nrser/refinements/hash.rb +0 -150
- data/lib/nrser/refinements/module.rb +0 -5
- data/lib/nrser/refinements/object.rb +0 -42
- data/lib/nrser/refinements/open_struct.rb +0 -28
- data/lib/nrser/refinements/pathname.rb +0 -5
- data/lib/nrser/refinements/set.rb +0 -5
- data/lib/nrser/refinements/string.rb +0 -5
- data/lib/nrser/refinements/symbol.rb +0 -20
- data/lib/nrser/rspex/described.rb +0 -99
- data/spec/design/mapping_spec.rb +0 -42
- data/spec/lib/nrser/functions/hash_spec.rb +0 -41
- data/spec/lib/nrser/functions/string/truncate_spec.rb +0 -11
- data/spec/lib/nrser/refinements/truncate_spec.rb +0 -10
@@ -0,0 +1,85 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
|
5
|
+
# Declarations
|
6
|
+
# =======================================================================
|
7
|
+
|
8
|
+
module NRSER::Props::Storage; end
|
9
|
+
|
10
|
+
|
11
|
+
# Definitions
|
12
|
+
# =======================================================================
|
13
|
+
|
14
|
+
# @todo document NRSER::Props::Storage::Key module.
|
15
|
+
class NRSER::Props::Storage::InstanceVariable
|
16
|
+
|
17
|
+
DEFAULT_VAR_NAME = :@__NRSER_prop_values
|
18
|
+
|
19
|
+
# TODO document `var_name` attribute.
|
20
|
+
#
|
21
|
+
# @return [Symbol]
|
22
|
+
#
|
23
|
+
attr_reader :var_name
|
24
|
+
|
25
|
+
|
26
|
+
# TODO document `sub_storage` attribute.
|
27
|
+
#
|
28
|
+
# @return [attr_type]
|
29
|
+
#
|
30
|
+
attr_reader :sub_storage
|
31
|
+
|
32
|
+
|
33
|
+
def initialize var_name: DEFAULT_VAR_NAME,
|
34
|
+
sub_storage:
|
35
|
+
@var_name = var_name.to_sym
|
36
|
+
@sub_storage = sub_storage
|
37
|
+
end
|
38
|
+
|
39
|
+
# Instance Methods
|
40
|
+
# ======================================================================
|
41
|
+
|
42
|
+
|
43
|
+
def init instance, collection
|
44
|
+
if init? instance
|
45
|
+
raise NRSER::ConflictError.new binding.erb <<~END
|
46
|
+
Already initialized!
|
47
|
+
|
48
|
+
Instance:
|
49
|
+
|
50
|
+
<%= instance.pretty_inspect %>
|
51
|
+
|
52
|
+
Collection:
|
53
|
+
|
54
|
+
<%= collection.pretty_inspect %>
|
55
|
+
|
56
|
+
END
|
57
|
+
end
|
58
|
+
|
59
|
+
instance.instance_variable_set @var_name, collection
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
def immutable?
|
64
|
+
sub_storage.immutable?
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
def init? instance
|
69
|
+
instance.instance_variable_defined? @var_name
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
def get instance, prop
|
74
|
+
sub_storage.get instance.instance_variable_get( @var_name ), prop
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
def put instance, prop, value
|
79
|
+
sub_storage.put \
|
80
|
+
instance.instance_variable_get( @var_name ),
|
81
|
+
prop,
|
82
|
+
value
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# Requirements
|
5
|
+
# =======================================================================
|
6
|
+
|
7
|
+
# Stdlib
|
8
|
+
# -----------------------------------------------------------------------
|
9
|
+
|
10
|
+
# Deps
|
11
|
+
# -----------------------------------------------------------------------
|
12
|
+
|
13
|
+
# Project / Package
|
14
|
+
# -----------------------------------------------------------------------
|
15
|
+
|
16
|
+
|
17
|
+
# Refinements
|
18
|
+
# =======================================================================
|
19
|
+
|
20
|
+
|
21
|
+
# Declarations
|
22
|
+
# =======================================================================
|
23
|
+
|
24
|
+
module NRSER::Props::Storage; end
|
25
|
+
|
26
|
+
|
27
|
+
# Definitions
|
28
|
+
# =======================================================================
|
29
|
+
|
30
|
+
# @todo document NRSER::Props::Storage::Key module.
|
31
|
+
class NRSER::Props::Storage::InstanceVariables
|
32
|
+
|
33
|
+
def initialize immutable:
|
34
|
+
@immutable = !!immutable
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
def immutable?
|
39
|
+
@immutable
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
def get instance, prop
|
44
|
+
instance.instance_variable_get "@#{ prop.name }"
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
def put instance, prop, value
|
49
|
+
if immutable?
|
50
|
+
raise RuntimeError.new binding.erb <<~END
|
51
|
+
Properties of #{ instance.class.safe_name } are immutable.
|
52
|
+
|
53
|
+
Tried to set prop #{ prop.name } to value
|
54
|
+
|
55
|
+
<%= value.pretty_inspect %>
|
56
|
+
|
57
|
+
in instance
|
58
|
+
|
59
|
+
<%= instance.pretty_inspect %>
|
60
|
+
|
61
|
+
END
|
62
|
+
end
|
63
|
+
|
64
|
+
instance.instance_variable_set "@#{ prop.name }", value
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# Requirements
|
5
|
+
# =======================================================================
|
6
|
+
|
7
|
+
# Stdlib
|
8
|
+
# -----------------------------------------------------------------------
|
9
|
+
|
10
|
+
# Deps
|
11
|
+
# -----------------------------------------------------------------------
|
12
|
+
|
13
|
+
# Project / Package
|
14
|
+
# -----------------------------------------------------------------------
|
15
|
+
|
16
|
+
|
17
|
+
# Refinements
|
18
|
+
# =======================================================================
|
19
|
+
|
20
|
+
|
21
|
+
# Declarations
|
22
|
+
# =======================================================================
|
23
|
+
|
24
|
+
module NRSER::Props::Storage; end
|
25
|
+
|
26
|
+
|
27
|
+
# Definitions
|
28
|
+
# =======================================================================
|
29
|
+
|
30
|
+
# @todo document NRSER::Props::Storage::Key module.
|
31
|
+
class NRSER::Props::Storage::Key
|
32
|
+
|
33
|
+
def initialize immutable:, key_type:, get: :[], put: :[]=
|
34
|
+
@immutable = !!immutable
|
35
|
+
@key_type = key_type
|
36
|
+
@get_method_name = get
|
37
|
+
@put_method_name = put
|
38
|
+
end
|
39
|
+
|
40
|
+
# Instance Methods
|
41
|
+
# ======================================================================
|
42
|
+
|
43
|
+
def immutable?
|
44
|
+
@immutable
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
def key_for prop
|
49
|
+
case @key_type
|
50
|
+
when :name
|
51
|
+
prop.name
|
52
|
+
when :index
|
53
|
+
prop.index
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
def get instance, prop
|
59
|
+
instance.send @get_method_name, key_for( prop )
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
def put instance, prop, value
|
64
|
+
key = key_for prop
|
65
|
+
|
66
|
+
if immutable?
|
67
|
+
raise RuntimeError.new binding.erb <<~END
|
68
|
+
Properties of #{ instance.class.safe_name } are immutable.
|
69
|
+
|
70
|
+
Tried to set key
|
71
|
+
|
72
|
+
<%= key.pretty_inspect %>
|
73
|
+
|
74
|
+
to value
|
75
|
+
|
76
|
+
<%= value.pretty_inspect %>
|
77
|
+
|
78
|
+
in instance
|
79
|
+
|
80
|
+
<%= instance.pretty_inspect %>
|
81
|
+
|
82
|
+
END
|
83
|
+
end
|
84
|
+
|
85
|
+
instance.send @put_method_name, key, value
|
86
|
+
end
|
87
|
+
|
88
|
+
end # class NRSER::Props::Storage::Key
|
data/lib/nrser/props.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# Requirements
|
5
|
+
# =======================================================================
|
6
|
+
|
7
|
+
# Project / Package
|
8
|
+
# -----------------------------------------------------------------------
|
9
|
+
|
10
|
+
# Need {NRSER::MethodMissingForwarder}
|
11
|
+
require 'nrser/sugar/method_missing_forwarder'
|
12
|
+
|
13
|
+
|
14
|
+
# Definitions
|
15
|
+
# =======================================================================
|
16
|
+
|
17
|
+
# Some sugary sweet stuff that I find nice but seems irresponsible to
|
18
|
+
# monkey-patch in, so it's available as refinements.
|
19
|
+
#
|
20
|
+
module NRSER::Sugar
|
21
|
+
|
22
|
+
refine Object do
|
23
|
+
|
24
|
+
# Get {Method} objects using concise syntax.
|
25
|
+
#
|
26
|
+
# @example
|
27
|
+
# text = 'bee!'
|
28
|
+
# ['a', 'b', 'c'].any? { |char| text.meth.start_with? }
|
29
|
+
#
|
30
|
+
# @return [NRSER::MethodMissingForwarder]
|
31
|
+
# That forwards `#method_missing( symbol )` to `self.method( symbol )`.
|
32
|
+
#
|
33
|
+
def meth
|
34
|
+
NRSER::MethodMissingForwarder.new do |symbol|
|
35
|
+
self.method symbol
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end # refine Object
|
40
|
+
|
41
|
+
end # module NRSER::Sugar
|
data/lib/nrser/refinements.rb
CHANGED
@@ -1,17 +1,15 @@
|
|
1
|
-
#
|
2
|
-
module NRSER::Refinements; end
|
1
|
+
# TODO Remove me
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
require_relative './refinements/module'
|
3
|
+
require_relative './log'
|
4
|
+
|
5
|
+
NRSER.logger.warn <<~END
|
6
|
+
DEPRECIATED - `require 'nrser/refinements'` is now a no-op,
|
7
|
+
please remove the calls.
|
8
|
+
|
9
|
+
Require specific refinements, like:
|
10
|
+
|
11
|
+
require 'nrser/refinements/types'
|
12
|
+
require 'nrser/refinements/sugar'
|
13
|
+
|
14
|
+
Thank you, the management.
|
15
|
+
END
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module NRSER::RSpex::ExampleGroup
|
5
|
+
|
6
|
+
# Describe an attribute of the parent subject.
|
7
|
+
#
|
8
|
+
# @return [void]
|
9
|
+
#
|
10
|
+
def describe_attribute symbol, **metadata, &body
|
11
|
+
describe_x \
|
12
|
+
NRSER::RSpex::Format.md_code_quote( "##{ symbol }" ),
|
13
|
+
type: :attribute,
|
14
|
+
metadata: metadata,
|
15
|
+
subject_block: -> {
|
16
|
+
super().public_send symbol
|
17
|
+
},
|
18
|
+
&body
|
19
|
+
end # #describe_attribute
|
20
|
+
|
21
|
+
# Shorter name
|
22
|
+
alias_method :describe_attr, :describe_attribute
|
23
|
+
|
24
|
+
end # module NRSER::RSpex::ExampleGroup
|
@@ -31,12 +31,7 @@ module NRSER::RSpex::ExampleGroup
|
|
31
31
|
&body
|
32
32
|
end # #describe_called_with
|
33
33
|
|
34
|
-
#
|
35
|
-
# at the moment.
|
36
|
-
#
|
37
|
-
# The `when_` one sucks because Atom de-dents the line, and `describe_`
|
38
|
-
# is just clearer what the block is doing for people reading it.
|
34
|
+
# Short / old name
|
39
35
|
alias_method :called_with, :describe_called_with
|
40
|
-
alias_method :when_called_with, :describe_called_with
|
41
36
|
|
42
37
|
end # module NRSER::RSpex::ExampleGroup
|
@@ -6,13 +6,16 @@ module NRSER::RSpex::ExampleGroup
|
|
6
6
|
#
|
7
7
|
# @return [void]
|
8
8
|
#
|
9
|
-
def
|
9
|
+
def describe_case *description, where: {}, **metadata, &body
|
10
10
|
describe_x \
|
11
11
|
*description,
|
12
|
-
type: :
|
12
|
+
type: :case,
|
13
13
|
bindings: where,
|
14
14
|
metadata: metadata,
|
15
15
|
&body
|
16
|
-
end # #
|
16
|
+
end # #describe_case
|
17
|
+
|
18
|
+
# Older name
|
19
|
+
alias_method :describe_use_case, :describe_case
|
17
20
|
|
18
21
|
end # module NRSER::RSpex::ExampleGroup
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module NRSER::RSpex::ExampleGroup
|
5
|
+
|
6
|
+
# Describe a "group". Doesn't really do much. Didn't end up getting used
|
7
|
+
# much. Probably not long for this world.
|
8
|
+
#
|
9
|
+
# @param *description (see #describe_x)
|
10
|
+
#
|
11
|
+
# @param [Hash<Symbol, Object>] **metadata
|
12
|
+
# RSpec metadata to set for the example group.
|
13
|
+
#
|
14
|
+
# See the `metadata` keyword argument to {#describe_x}.
|
15
|
+
#
|
16
|
+
# @param &body (see #describe_x)
|
17
|
+
#
|
18
|
+
# @return (see #describe_x)
|
19
|
+
#
|
20
|
+
def describe_group *description, **metadata, &body
|
21
|
+
# Pass up to {#describe_x}
|
22
|
+
describe_x \
|
23
|
+
*description,
|
24
|
+
type: :group,
|
25
|
+
metadata: metadata,
|
26
|
+
&body
|
27
|
+
end # #describe_group
|
28
|
+
|
29
|
+
end # module NRSER::RSpex::ExampleGroup
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module NRSER::RSpex::ExampleGroup
|
5
|
+
|
6
|
+
# Describe a {NRSER::Message}. Useful when you have a message that you want
|
7
|
+
# to send to many receivers (see {#describe_sent_to}).
|
8
|
+
#
|
9
|
+
# @note
|
10
|
+
# Since the block is used for the example group body, if you want to
|
11
|
+
# describe a message with a {NRSER::Message#block} your need to create
|
12
|
+
# the message yourself and pass it as the only argument.
|
13
|
+
#
|
14
|
+
# @see #describe_x
|
15
|
+
#
|
16
|
+
# @param [Array] *args
|
17
|
+
# Passed to {NRSER::Message.from} to get or create the message instance.
|
18
|
+
#
|
19
|
+
# @param &body (see #describe_x)
|
20
|
+
#
|
21
|
+
# @return (see #describe_x)
|
22
|
+
#
|
23
|
+
def describe_message *args, &body
|
24
|
+
message = NRSER::Message.from *args
|
25
|
+
|
26
|
+
describe_x \
|
27
|
+
description,
|
28
|
+
type: :message,
|
29
|
+
metadata: {
|
30
|
+
message: message,
|
31
|
+
},
|
32
|
+
&body
|
33
|
+
end
|
34
|
+
|
35
|
+
end # module NRSER::RSpex::ExampleGroup
|
@@ -3,7 +3,7 @@
|
|
3
3
|
|
4
4
|
module NRSER::RSpex::ExampleGroup
|
5
5
|
|
6
|
-
#
|
6
|
+
# Describe a method of the parent subject.
|
7
7
|
#
|
8
8
|
# @return [void]
|
9
9
|
#
|
@@ -23,11 +23,32 @@ module NRSER::RSpex::ExampleGroup
|
|
23
23
|
'.'
|
24
24
|
end
|
25
25
|
|
26
|
+
method = if self.try( :metadata )
|
27
|
+
getter = if self.metadata.key?( :constructor_args )
|
28
|
+
:instance_method
|
29
|
+
else
|
30
|
+
:method
|
31
|
+
end
|
32
|
+
|
33
|
+
target = self.metadata[:class] || self.metadata[:module]
|
34
|
+
|
35
|
+
if target
|
36
|
+
begin
|
37
|
+
target.public_send getter, method_name
|
38
|
+
rescue
|
39
|
+
nil
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
26
44
|
name_string = NRSER::RSpex::Format.md_code_quote \
|
27
45
|
"#{ name_prefix }#{ method_name }"
|
28
46
|
|
29
47
|
# Create the RSpec example group context
|
30
|
-
describe_x
|
48
|
+
describe_x \
|
49
|
+
name_string,
|
50
|
+
NRSER::Meta::Source::Location.new( method ),
|
51
|
+
*description,
|
31
52
|
type: :method,
|
32
53
|
metadata: {
|
33
54
|
**metadata,
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module NRSER::RSpex::ExampleGroup
|
5
|
+
|
6
|
+
def describe_module mod, bind_subject: true, **metadata, &body
|
7
|
+
describe_x \
|
8
|
+
mod,
|
9
|
+
type: :module,
|
10
|
+
metadata: {
|
11
|
+
module: mod,
|
12
|
+
**metadata,
|
13
|
+
},
|
14
|
+
bind_subject: bind_subject,
|
15
|
+
subject_block: -> { mod },
|
16
|
+
&body
|
17
|
+
end # #describe_module
|
18
|
+
|
19
|
+
end # module NRSER::RSpex::ExampleGroup
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module NRSER::RSpex::ExampleGroup
|
5
|
+
|
6
|
+
# Describe the response of the subject to a {NRSER::Message}.
|
7
|
+
#
|
8
|
+
# Pretty much a short-cut for nesting {#describe_method} /
|
9
|
+
# {#describe_called_with}. Meh.
|
10
|
+
#
|
11
|
+
# @param [Array] *args
|
12
|
+
# Passed to {NRSER::Message.from} to get or create the message instance.
|
13
|
+
#
|
14
|
+
# @param &body (see #describe_x)
|
15
|
+
#
|
16
|
+
# @return (see #describe_x)
|
17
|
+
#
|
18
|
+
def describe_response_to *args, &body
|
19
|
+
msg = NRSER::Message.from *args
|
20
|
+
|
21
|
+
# Pass up to {#describe_x}
|
22
|
+
describe_x \
|
23
|
+
msg,
|
24
|
+
type: :response_to,
|
25
|
+
subject_block: -> { msg.send_to super() },
|
26
|
+
&body
|
27
|
+
end # #describe_response_to
|
28
|
+
|
29
|
+
# Old name
|
30
|
+
alias_method :describe_return_value, :describe_response_to
|
31
|
+
|
32
|
+
end # module NRSER::RSpex::ExampleGroup
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module NRSER::RSpex::ExampleGroup
|
5
|
+
|
6
|
+
# Describe a "section". Just like {RSpec.describe} except it:
|
7
|
+
#
|
8
|
+
# 1. Expects a string title.
|
9
|
+
#
|
10
|
+
# 2. Prepends a little section squiggle `§` to the title so sections are
|
11
|
+
# easier to pick out visually.
|
12
|
+
#
|
13
|
+
# 3. Adds `type: :section` metadata.
|
14
|
+
#
|
15
|
+
# @param *description (see #describe_x)
|
16
|
+
#
|
17
|
+
# @param [Hash<Symbol, Object>] **metadata
|
18
|
+
# RSpec metadata to set for the example group.
|
19
|
+
#
|
20
|
+
# See the `metadata` keyword argument to {#describe_x}.
|
21
|
+
#
|
22
|
+
# @param &body (see #describe_x)
|
23
|
+
#
|
24
|
+
# @return (see #describe_x)
|
25
|
+
#
|
26
|
+
def describe_section *description, **metadata, &body
|
27
|
+
# Pass up to {#describe_x}
|
28
|
+
describe_x \
|
29
|
+
*description,
|
30
|
+
type: :section,
|
31
|
+
metadata: metadata,
|
32
|
+
&body
|
33
|
+
end # #describe_section
|
34
|
+
|
35
|
+
# Old name
|
36
|
+
alias_method :describe_topic, :describe_section
|
37
|
+
|
38
|
+
end # module NRSER::RSpex::ExampleGroup
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module NRSER::RSpex::ExampleGroup
|
5
|
+
|
6
|
+
# For use when `subject` is a {NRSER::Message}. Create a new context for
|
7
|
+
# the `receiver` where the subject is the result of sending that message
|
8
|
+
# to the receiver.
|
9
|
+
#
|
10
|
+
# @param [Object] receiver
|
11
|
+
# Object that will receive the message to create the new subject.
|
12
|
+
#
|
13
|
+
# If it's a {Wrapper} it will be unwrapped in example contexts of the
|
14
|
+
# new example group.
|
15
|
+
#
|
16
|
+
# @param [Boolean] publicly:
|
17
|
+
# Send message publicly via {Object#public_send} (default) or privately
|
18
|
+
# via {Object.send}.
|
19
|
+
#
|
20
|
+
# @param bind_subject: (see #describe_x)
|
21
|
+
# @param &body (see #describe_x)
|
22
|
+
#
|
23
|
+
# @return (see #describe_x)
|
24
|
+
#
|
25
|
+
def describe_sent_to receiver,
|
26
|
+
publicly: true,
|
27
|
+
bind_subject: true,
|
28
|
+
&body
|
29
|
+
mode = if publicly
|
30
|
+
"publicly"
|
31
|
+
else
|
32
|
+
"privately"
|
33
|
+
end
|
34
|
+
|
35
|
+
describe_x \
|
36
|
+
receiver,
|
37
|
+
"(#{ mode })",
|
38
|
+
type: :sent_to,
|
39
|
+
bind_subject: bind_subject,
|
40
|
+
subject_block: -> {
|
41
|
+
super().send_to \
|
42
|
+
unwrap( receiver, context: self ),
|
43
|
+
publicly: publicly
|
44
|
+
},
|
45
|
+
&body
|
46
|
+
end # #describe_sent_to
|
47
|
+
|
48
|
+
# Aliases to other names I was using at first... not preferring their use
|
49
|
+
# at the moment.
|
50
|
+
alias_method :sent_to, :describe_sent_to
|
51
|
+
|
52
|
+
end # module NRSER::RSpex::ExampleGroup
|