cucumber 3.1.2 → 5.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +281 -14
- data/CONTRIBUTING.md +11 -25
- data/README.md +4 -5
- data/bin/cucumber +1 -1
- data/lib/autotest/cucumber_mixin.rb +46 -53
- data/lib/cucumber.rb +1 -1
- data/lib/cucumber/cli/configuration.rb +5 -5
- data/lib/cucumber/cli/main.rb +12 -12
- data/lib/cucumber/cli/options.rb +97 -76
- data/lib/cucumber/cli/profile_loader.rb +49 -26
- data/lib/cucumber/configuration.rb +44 -29
- data/lib/cucumber/constantize.rb +2 -5
- data/lib/cucumber/deprecate.rb +31 -7
- data/lib/cucumber/errors.rb +5 -7
- data/lib/cucumber/events.rb +13 -6
- data/lib/cucumber/events/envelope.rb +9 -0
- data/lib/cucumber/events/gherkin_source_parsed.rb +11 -0
- data/lib/cucumber/events/hook_test_step_created.rb +13 -0
- data/lib/cucumber/events/step_activated.rb +2 -1
- data/lib/cucumber/events/test_case_created.rb +13 -0
- data/lib/cucumber/events/test_case_ready.rb +12 -0
- data/lib/cucumber/events/test_step_created.rb +13 -0
- data/lib/cucumber/events/undefined_parameter_type.rb +10 -0
- data/lib/cucumber/file_specs.rb +6 -6
- data/lib/cucumber/filters.rb +1 -0
- data/lib/cucumber/filters/activate_steps.rb +5 -3
- data/lib/cucumber/filters/broadcast_test_case_ready_event.rb +12 -0
- data/lib/cucumber/filters/prepare_world.rb +5 -9
- data/lib/cucumber/filters/quit.rb +1 -3
- data/lib/cucumber/filters/tag_limits/verifier.rb +2 -4
- data/lib/cucumber/formatter/ansicolor.rb +40 -45
- data/lib/cucumber/formatter/ast_lookup.rb +163 -0
- data/lib/cucumber/formatter/backtrace_filter.rb +9 -8
- data/lib/cucumber/formatter/console.rb +58 -66
- data/lib/cucumber/formatter/console_counts.rb +4 -9
- data/lib/cucumber/formatter/console_issues.rb +6 -3
- data/lib/cucumber/formatter/duration.rb +1 -1
- data/lib/cucumber/formatter/duration_extractor.rb +3 -1
- data/lib/cucumber/formatter/errors.rb +6 -0
- data/lib/cucumber/formatter/fanout.rb +2 -0
- data/lib/cucumber/formatter/html.rb +11 -598
- data/lib/cucumber/formatter/http_io.rb +151 -0
- data/lib/cucumber/formatter/ignore_missing_messages.rb +1 -1
- data/lib/cucumber/formatter/interceptor.rb +11 -30
- data/lib/cucumber/formatter/io.rb +54 -12
- data/lib/cucumber/formatter/json.rb +101 -109
- data/lib/cucumber/formatter/junit.rb +55 -55
- data/lib/cucumber/formatter/message.rb +22 -0
- data/lib/cucumber/formatter/message_builder.rb +255 -0
- data/lib/cucumber/formatter/pretty.rb +359 -153
- data/lib/cucumber/formatter/progress.rb +30 -32
- data/lib/cucumber/formatter/publish_banner_printer.rb +77 -0
- data/lib/cucumber/formatter/query/hook_by_test_step.rb +31 -0
- data/lib/cucumber/formatter/query/pickle_by_test.rb +26 -0
- data/lib/cucumber/formatter/query/pickle_step_by_test_step.rb +26 -0
- data/lib/cucumber/formatter/query/step_definitions_by_test_step.rb +40 -0
- data/lib/cucumber/formatter/query/test_case_started_by_test_case.rb +40 -0
- data/lib/cucumber/formatter/rerun.rb +21 -3
- data/lib/cucumber/formatter/stepdefs.rb +1 -2
- data/lib/cucumber/formatter/steps.rb +2 -3
- data/lib/cucumber/formatter/summary.rb +16 -8
- data/lib/cucumber/formatter/unicode.rb +15 -17
- data/lib/cucumber/formatter/url_reporter.rb +30 -0
- data/lib/cucumber/formatter/usage.rb +11 -10
- data/lib/cucumber/gherkin/data_table_parser.rb +17 -6
- data/lib/cucumber/gherkin/formatter/ansi_escapes.rb +13 -17
- data/lib/cucumber/gherkin/formatter/escaping.rb +2 -2
- data/lib/cucumber/gherkin/steps_parser.rb +17 -8
- data/lib/cucumber/glue/hook.rb +34 -11
- data/lib/cucumber/glue/invoke_in_world.rb +13 -18
- data/lib/cucumber/glue/proto_world.rb +42 -33
- data/lib/cucumber/glue/registry_and_more.rb +42 -12
- data/lib/cucumber/glue/snippet.rb +23 -22
- data/lib/cucumber/glue/step_definition.rb +42 -19
- data/lib/cucumber/glue/world_factory.rb +1 -1
- data/lib/cucumber/hooks.rb +11 -11
- data/lib/cucumber/multiline_argument.rb +4 -6
- data/lib/cucumber/multiline_argument/data_table.rb +97 -64
- data/lib/cucumber/multiline_argument/data_table/diff_matrices.rb +2 -2
- data/lib/cucumber/multiline_argument/doc_string.rb +1 -1
- data/lib/cucumber/platform.rb +3 -3
- data/lib/cucumber/rake/task.rb +16 -18
- data/lib/cucumber/rspec/disable_option_parser.rb +9 -8
- data/lib/cucumber/rspec/doubles.rb +3 -5
- data/lib/cucumber/running_test_case.rb +2 -53
- data/lib/cucumber/runtime.rb +41 -58
- data/lib/cucumber/runtime/after_hooks.rb +8 -4
- data/lib/cucumber/runtime/before_hooks.rb +8 -4
- data/lib/cucumber/runtime/for_programming_languages.rb +4 -2
- data/lib/cucumber/runtime/step_hooks.rb +6 -2
- data/lib/cucumber/runtime/support_code.rb +13 -15
- data/lib/cucumber/runtime/user_interface.rb +6 -16
- data/lib/cucumber/step_definition_light.rb +4 -3
- data/lib/cucumber/step_definitions.rb +2 -2
- data/lib/cucumber/step_match.rb +12 -11
- data/lib/cucumber/step_match_search.rb +2 -1
- data/lib/cucumber/term/ansicolor.rb +9 -9
- data/lib/cucumber/term/banner.rb +56 -0
- data/lib/cucumber/version +1 -1
- metadata +254 -83
- data/lib/cucumber/events/gherkin_source_parsed.rb~ +0 -14
- data/lib/cucumber/formatter/ast_lookup.rb~ +0 -9
- data/lib/cucumber/formatter/cucumber.css +0 -286
- data/lib/cucumber/formatter/cucumber.sass +0 -247
- data/lib/cucumber/formatter/hook_query_visitor.rb +0 -42
- data/lib/cucumber/formatter/html_builder.rb +0 -121
- data/lib/cucumber/formatter/inline-js.js +0 -30
- data/lib/cucumber/formatter/jquery-min.js +0 -154
- data/lib/cucumber/formatter/json_pretty.rb +0 -11
- data/lib/cucumber/formatter/legacy_api/adapter.rb +0 -1028
- data/lib/cucumber/formatter/legacy_api/ast.rb +0 -394
- data/lib/cucumber/formatter/legacy_api/results.rb +0 -50
- data/lib/cucumber/formatter/legacy_api/runtime_facade.rb +0 -32
- data/lib/cucumber/step_argument.rb +0 -25
@@ -3,23 +3,27 @@
|
|
3
3
|
module Cucumber
|
4
4
|
class Runtime
|
5
5
|
class AfterHooks
|
6
|
-
def initialize(hooks, scenario)
|
6
|
+
def initialize(id_generator, hooks, scenario, event_bus)
|
7
7
|
@hooks = hooks
|
8
8
|
@scenario = scenario
|
9
|
+
@id_generator = id_generator
|
10
|
+
@event_bus = event_bus
|
9
11
|
end
|
10
12
|
|
11
13
|
def apply_to(test_case)
|
12
14
|
test_case.with_steps(
|
13
|
-
test_case.test_steps + after_hooks
|
15
|
+
test_case.test_steps + after_hooks.reverse
|
14
16
|
)
|
15
17
|
end
|
16
18
|
|
17
19
|
private
|
18
20
|
|
19
|
-
def after_hooks
|
21
|
+
def after_hooks
|
20
22
|
@hooks.map do |hook|
|
21
23
|
action = ->(result) { hook.invoke('After', @scenario.with_result(result)) }
|
22
|
-
Hooks.after_hook(
|
24
|
+
hook_step = Hooks.after_hook(@id_generator.new_id, hook.location, &action)
|
25
|
+
@event_bus.hook_test_step_created(hook_step, hook)
|
26
|
+
hook_step
|
23
27
|
end
|
24
28
|
end
|
25
29
|
end
|
@@ -5,23 +5,27 @@ require 'cucumber/hooks'
|
|
5
5
|
module Cucumber
|
6
6
|
class Runtime
|
7
7
|
class BeforeHooks
|
8
|
-
def initialize(hooks, scenario)
|
8
|
+
def initialize(id_generator, hooks, scenario, event_bus)
|
9
9
|
@hooks = hooks
|
10
10
|
@scenario = scenario
|
11
|
+
@id_generator = id_generator
|
12
|
+
@event_bus = event_bus
|
11
13
|
end
|
12
14
|
|
13
15
|
def apply_to(test_case)
|
14
16
|
test_case.with_steps(
|
15
|
-
before_hooks
|
17
|
+
before_hooks + test_case.test_steps
|
16
18
|
)
|
17
19
|
end
|
18
20
|
|
19
21
|
private
|
20
22
|
|
21
|
-
def before_hooks
|
23
|
+
def before_hooks
|
22
24
|
@hooks.map do |hook|
|
23
25
|
action_block = ->(result) { hook.invoke('Before', @scenario.with_result(result)) }
|
24
|
-
Hooks.before_hook(
|
26
|
+
hook_step = Hooks.before_hook(@id_generator.new_id, hook.location, &action_block)
|
27
|
+
@event_bus.hook_test_step_created(hook_step, hook)
|
28
|
+
hook_step
|
25
29
|
end
|
26
30
|
end
|
27
31
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'forwardable'
|
4
|
-
require 'cucumber/core/
|
4
|
+
require 'cucumber/core/test/doc_string'
|
5
5
|
|
6
6
|
module Cucumber
|
7
7
|
class Runtime
|
@@ -15,11 +15,13 @@ module Cucumber
|
|
15
15
|
attr_reader :support_code
|
16
16
|
|
17
17
|
def initialize(support_code, user_interface)
|
18
|
-
@support_code
|
18
|
+
@support_code = support_code
|
19
|
+
@user_interface = user_interface
|
19
20
|
end
|
20
21
|
|
21
22
|
def_delegators :@user_interface,
|
22
23
|
:embed,
|
24
|
+
:attach,
|
23
25
|
:ask,
|
24
26
|
:puts,
|
25
27
|
:features_paths,
|
@@ -3,8 +3,10 @@
|
|
3
3
|
module Cucumber
|
4
4
|
class Runtime
|
5
5
|
class StepHooks
|
6
|
-
def initialize(hooks)
|
6
|
+
def initialize(id_generator, hooks, event_bus)
|
7
7
|
@hooks = hooks
|
8
|
+
@id_generator = id_generator
|
9
|
+
@event_bus = event_bus
|
8
10
|
end
|
9
11
|
|
10
12
|
def apply(test_steps)
|
@@ -18,7 +20,9 @@ module Cucumber
|
|
18
20
|
def after_step_hooks(test_step)
|
19
21
|
@hooks.map do |hook|
|
20
22
|
action = ->(*args) { hook.invoke('AfterStep', [args, test_step]) }
|
21
|
-
Hooks.after_step_hook(
|
23
|
+
hook_step = Hooks.after_step_hook(@id_generator.new_id, test_step, hook.location, &action)
|
24
|
+
@event_bus.hook_test_step_created(hook_step, hook)
|
25
|
+
hook_step
|
22
26
|
end
|
23
27
|
end
|
24
28
|
end
|
@@ -22,19 +22,15 @@ module Cucumber
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def step(step)
|
25
|
-
location = Core::
|
25
|
+
location = Core::Test::Location.of_caller
|
26
26
|
@support_code.invoke_dynamic_step(step[:text], multiline_arg(step, location))
|
27
27
|
end
|
28
28
|
|
29
29
|
def multiline_arg(step, location)
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
MultilineArgument.from(argument[:content], location, argument[:content_type])
|
35
|
-
else
|
36
|
-
MultilineArgument::DataTable.from(argument[:rows].map { |row| row[:cells].map { |cell| cell[:value] } })
|
37
|
-
end
|
30
|
+
if !step[:doc_string].nil?
|
31
|
+
MultilineArgument.from(step[:doc_string][:content], location, step[:doc_string][:content_type])
|
32
|
+
elsif !step[:data_table].nil?
|
33
|
+
MultilineArgument::DataTable.from(step[:data_table][:rows].map { |row| row[:cells].map { |cell| cell[:value] } })
|
38
34
|
else
|
39
35
|
MultilineArgument.from(nil)
|
40
36
|
end
|
@@ -62,8 +58,8 @@ module Cucumber
|
|
62
58
|
# Given I have 8 cukes in my belly
|
63
59
|
# Then I should not be thirsty
|
64
60
|
# })
|
65
|
-
def invoke_dynamic_steps(steps_text,
|
66
|
-
parser = Cucumber::Gherkin::StepsParser.new(StepInvoker.new(self),
|
61
|
+
def invoke_dynamic_steps(steps_text, iso_code, _location)
|
62
|
+
parser = Cucumber::Gherkin::StepsParser.new(StepInvoker.new(self), iso_code)
|
67
63
|
parser.parse(steps_text)
|
68
64
|
end
|
69
65
|
|
@@ -108,26 +104,28 @@ module Cucumber
|
|
108
104
|
def find_after_step_hooks(test_case)
|
109
105
|
scenario = RunningTestCase.new(test_case)
|
110
106
|
hooks = registry.hooks_for(:after_step, scenario)
|
111
|
-
StepHooks.new hooks
|
107
|
+
StepHooks.new(@configuration.id_generator, hooks, @configuration.event_bus)
|
112
108
|
end
|
113
109
|
|
114
110
|
def apply_before_hooks(test_case)
|
111
|
+
return test_case if test_case.test_steps.empty?
|
115
112
|
scenario = RunningTestCase.new(test_case)
|
116
113
|
hooks = registry.hooks_for(:before, scenario)
|
117
|
-
BeforeHooks.new(hooks, scenario).apply_to(test_case)
|
114
|
+
BeforeHooks.new(@configuration.id_generator, hooks, scenario, @configuration.event_bus).apply_to(test_case)
|
118
115
|
end
|
119
116
|
|
120
117
|
def apply_after_hooks(test_case)
|
118
|
+
return test_case if test_case.test_steps.empty?
|
121
119
|
scenario = RunningTestCase.new(test_case)
|
122
120
|
hooks = registry.hooks_for(:after, scenario)
|
123
|
-
AfterHooks.new(hooks, scenario).apply_to(test_case)
|
121
|
+
AfterHooks.new(@configuration.id_generator, hooks, scenario, @configuration.event_bus).apply_to(test_case)
|
124
122
|
end
|
125
123
|
|
126
124
|
def find_around_hooks(test_case)
|
127
125
|
scenario = RunningTestCase.new(test_case)
|
128
126
|
|
129
127
|
registry.hooks_for(:around, scenario).map do |hook|
|
130
|
-
Hooks.around_hook
|
128
|
+
Hooks.around_hook do |run_scenario|
|
131
129
|
hook.invoke('Around', scenario, &run_scenario)
|
132
130
|
end
|
133
131
|
end
|
@@ -7,14 +7,6 @@ module Cucumber
|
|
7
7
|
module UserInterface
|
8
8
|
attr_writer :visitor
|
9
9
|
|
10
|
-
# Output +messages+ alongside the formatted output.
|
11
|
-
# This is an alternative to using Kernel#puts - it will display
|
12
|
-
# nicer, and in all outputs (in case you use several formatters)
|
13
|
-
#
|
14
|
-
def puts(*messages)
|
15
|
-
@visitor.puts(*messages)
|
16
|
-
end
|
17
|
-
|
18
10
|
# Suspends execution and prompts +question+ to the console (STDOUT).
|
19
11
|
# An operator (manual tester) can then enter a line of text and hit
|
20
12
|
# <ENTER>. The entered text is returned, and both +question+ and
|
@@ -48,20 +40,18 @@ module Cucumber
|
|
48
40
|
# be a path to a file, or if it's an image it may also be a Base64 encoded image.
|
49
41
|
# The embedded data may or may not be ignored, depending on what kind of formatter(s) are active.
|
50
42
|
#
|
51
|
-
def
|
52
|
-
@visitor.
|
43
|
+
def attach(src, media_type)
|
44
|
+
@visitor.attach(src, media_type)
|
53
45
|
end
|
54
46
|
|
55
47
|
private
|
56
48
|
|
57
49
|
def mri_gets(timeout_seconds)
|
58
|
-
|
59
|
-
|
60
|
-
STDIN.gets
|
61
|
-
end
|
62
|
-
rescue Timeout::Error
|
63
|
-
nil
|
50
|
+
Timeout.timeout(timeout_seconds) do
|
51
|
+
STDIN.gets
|
64
52
|
end
|
53
|
+
rescue Timeout::Error
|
54
|
+
nil
|
65
55
|
end
|
66
56
|
|
67
57
|
def jruby_gets(timeout_seconds)
|
@@ -9,11 +9,12 @@ module Cucumber
|
|
9
9
|
attr_reader :regexp_source, :location
|
10
10
|
|
11
11
|
def initialize(regexp_source, location)
|
12
|
-
@regexp_source
|
12
|
+
@regexp_source = regexp_source
|
13
|
+
@location = location
|
13
14
|
end
|
14
15
|
|
15
|
-
def eql?(
|
16
|
-
regexp_source ==
|
16
|
+
def eql?(other)
|
17
|
+
regexp_source == other.regexp_source && location == other.location
|
17
18
|
end
|
18
19
|
|
19
20
|
def hash
|
@@ -8,8 +8,8 @@ module Cucumber
|
|
8
8
|
@support_code.load_files_from_paths(configuration.autoload_code_paths)
|
9
9
|
end
|
10
10
|
|
11
|
-
def to_json
|
12
|
-
@support_code.step_definitions.map(&:to_hash).to_json
|
11
|
+
def to_json(obj = nil)
|
12
|
+
@support_code.step_definitions.map(&:to_hash).to_json(obj)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
data/lib/cucumber/step_match.rb
CHANGED
@@ -9,7 +9,9 @@ module Cucumber
|
|
9
9
|
|
10
10
|
def initialize(step_definition, step_name, step_arguments)
|
11
11
|
raise "step_arguments can't be nil (but it can be an empty array)" if step_arguments.nil?
|
12
|
-
@step_definition
|
12
|
+
@step_definition = step_definition
|
13
|
+
@name_to_match = step_name
|
14
|
+
@step_arguments = step_arguments
|
13
15
|
end
|
14
16
|
|
15
17
|
def args
|
@@ -21,7 +23,7 @@ module Cucumber
|
|
21
23
|
|
22
24
|
def activate(test_step)
|
23
25
|
test_step.with_action(@step_definition.location) do
|
24
|
-
invoke(MultilineArgument.from_core(test_step.
|
26
|
+
invoke(MultilineArgument.from_core(test_step.multiline_arg))
|
25
27
|
end
|
26
28
|
end
|
27
29
|
|
@@ -46,7 +48,7 @@ module Cucumber
|
|
46
48
|
#
|
47
49
|
# lambda { |param| "[#{param}]" }
|
48
50
|
#
|
49
|
-
def format_args(format =
|
51
|
+
def format_args(format = ->(a) { a }, &proc)
|
50
52
|
replace_arguments(@name_to_match, @step_arguments, format, &proc)
|
51
53
|
end
|
52
54
|
|
@@ -75,7 +77,7 @@ module Cucumber
|
|
75
77
|
|
76
78
|
replacement = if block_given?
|
77
79
|
yield(group.value)
|
78
|
-
elsif Proc
|
80
|
+
elsif Proc == format.class
|
79
81
|
format.call(group.value)
|
80
82
|
else
|
81
83
|
format % group.value
|
@@ -95,13 +97,13 @@ module Cucumber
|
|
95
97
|
private
|
96
98
|
|
97
99
|
def deep_clone_args
|
98
|
-
Marshal.load(
|
100
|
+
Marshal.load(Marshal.dump(args))
|
99
101
|
end
|
100
102
|
end
|
101
103
|
|
102
104
|
class SkippingStepMatch
|
103
105
|
def activate(test_step)
|
104
|
-
|
106
|
+
test_step.with_action { raise Core::Test::Result::Skipped }
|
105
107
|
end
|
106
108
|
end
|
107
109
|
|
@@ -123,8 +125,7 @@ module Cucumber
|
|
123
125
|
end
|
124
126
|
|
125
127
|
def file_colon_line
|
126
|
-
|
127
|
-
@step.file_colon_line
|
128
|
+
location.to_s
|
128
129
|
end
|
129
130
|
|
130
131
|
def backtrace_line
|
@@ -132,7 +133,7 @@ module Cucumber
|
|
132
133
|
end
|
133
134
|
|
134
135
|
def text_length
|
135
|
-
@step.
|
136
|
+
@step.text.length
|
136
137
|
end
|
137
138
|
|
138
139
|
def step_arguments
|
@@ -141,7 +142,7 @@ module Cucumber
|
|
141
142
|
|
142
143
|
def activate(test_step)
|
143
144
|
# noop
|
144
|
-
|
145
|
+
test_step
|
145
146
|
end
|
146
147
|
end
|
147
148
|
|
@@ -151,7 +152,7 @@ module Cucumber
|
|
151
152
|
end
|
152
153
|
|
153
154
|
def activate(test_step)
|
154
|
-
|
155
|
+
test_step.with_action { raise @error }
|
155
156
|
end
|
156
157
|
end
|
157
158
|
end
|
@@ -35,7 +35,7 @@ module Cucumber
|
|
35
35
|
[:on_magenta, 45],
|
36
36
|
[:on_cyan, 46],
|
37
37
|
[:on_white, 47]
|
38
|
-
]
|
38
|
+
].freeze
|
39
39
|
|
40
40
|
ATTRIBUTE_NAMES = ATTRIBUTES.transpose.first
|
41
41
|
# :startdoc:
|
@@ -54,8 +54,9 @@ module Cucumber
|
|
54
54
|
end
|
55
55
|
self.coloring = true
|
56
56
|
|
57
|
+
# rubocop:disable Security/Eval
|
57
58
|
ATTRIBUTES.each do |c, v|
|
58
|
-
eval
|
59
|
+
eval <<-END_EVAL, binding, __FILE__, __LINE__ + 1
|
59
60
|
def #{c}(string = nil)
|
60
61
|
result = String.new
|
61
62
|
result << "\e[#{v}m" if Cucumber::Term::ANSIColor.coloring?
|
@@ -71,23 +72,23 @@ module Cucumber
|
|
71
72
|
result << "\e[0m" if Cucumber::Term::ANSIColor.coloring?
|
72
73
|
result
|
73
74
|
end
|
74
|
-
|
75
|
+
END_EVAL
|
75
76
|
end
|
77
|
+
# rubocop:enable Security/Eval
|
76
78
|
|
77
79
|
# Regular expression that is used to scan for ANSI-sequences while
|
78
80
|
# uncoloring strings.
|
79
81
|
COLORED_REGEXP = /\e\[(?:[34][0-7]|[0-9])?m/
|
80
82
|
|
81
83
|
def self.included(klass)
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
end
|
84
|
+
return unless klass == String
|
85
|
+
ATTRIBUTES.delete(:clear)
|
86
|
+
ATTRIBUTE_NAMES.delete(:clear)
|
86
87
|
end
|
87
88
|
|
88
89
|
# Returns an uncolored version of the string, that is all
|
89
90
|
# ANSI-sequences are stripped from the string.
|
90
|
-
def uncolored(string = nil)
|
91
|
+
def uncolored(string = nil)
|
91
92
|
if block_given?
|
92
93
|
yield.gsub(COLORED_REGEXP, '')
|
93
94
|
elsif string
|
@@ -105,7 +106,6 @@ module Cucumber
|
|
105
106
|
def attributes
|
106
107
|
ATTRIBUTE_NAMES
|
107
108
|
end
|
108
|
-
extend self
|
109
109
|
end
|
110
110
|
end
|
111
111
|
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'cucumber/term/ansicolor'
|
2
|
+
|
3
|
+
module Cucumber
|
4
|
+
module Term
|
5
|
+
module Banner
|
6
|
+
def display_banner(lines, io, border_modifiers = nil)
|
7
|
+
BannerMaker.new.display_banner(lines, io, border_modifiers || %i[green bold])
|
8
|
+
end
|
9
|
+
|
10
|
+
class BannerMaker
|
11
|
+
include Term::ANSIColor
|
12
|
+
|
13
|
+
def display_banner(lines, io, border_modifiers)
|
14
|
+
lines = lines.split("\n") if lines.is_a? String
|
15
|
+
longest_line_length = lines.map { |line| line_length(line) }.max
|
16
|
+
|
17
|
+
io.puts apply_modifiers("┌#{'─' * (longest_line_length + 2)}┐", border_modifiers)
|
18
|
+
lines.map do |line|
|
19
|
+
padding = ' ' * (longest_line_length - line_length(line))
|
20
|
+
io.puts "#{apply_modifiers('│', border_modifiers)} #{display_line(line)}#{padding} #{apply_modifiers('│', border_modifiers)}"
|
21
|
+
end
|
22
|
+
io.puts apply_modifiers("└#{'─' * (longest_line_length + 2)}┘", border_modifiers)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def display_line(line)
|
28
|
+
line.is_a?(Array) ? line.map { |span| display_span(span) }.join : line
|
29
|
+
end
|
30
|
+
|
31
|
+
def display_span(span)
|
32
|
+
return apply_modifiers(span.shift, span) if span.is_a?(Array)
|
33
|
+
span
|
34
|
+
end
|
35
|
+
|
36
|
+
def apply_modifiers(str, modifiers)
|
37
|
+
display = str
|
38
|
+
modifiers.each { |modifier| display = send(modifier, display) }
|
39
|
+
display
|
40
|
+
end
|
41
|
+
|
42
|
+
def line_length(line)
|
43
|
+
if line.is_a?(Array)
|
44
|
+
line.map { |span| span_length(span) }.sum
|
45
|
+
else
|
46
|
+
line.length
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def span_length(span)
|
51
|
+
span.is_a?(Array) ? span[0].length : span.length
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|