Skip to content

Commit 8bd228f

Browse files
Introduce Mix Task
In order for Cucumber to be runnable from a client application, a mix task has been created to facilitate accordingly. In addition to that, a few minor matters came to light when using in a client application: * Config was referring to wrong directory for where to find gherkin-languages and feature files * Introduction of report concept became important in connection to the mix task * Address a variety of warnings generated by cucumber_expressions
1 parent 0e3a0dd commit 8bd228f

File tree

13 files changed

+87
-30
lines changed

13 files changed

+87
-30
lines changed

apps/cucumber_expressions/lib/cucumber_expressions/matcher.ex

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ defmodule CucumberExpressions.Matcher do
216216
parse_tree.params[param_key]
217217
|> Map.put(:params, [{param_key, match} | params])
218218

219-
q ->
219+
_ ->
220220
parse_tree.params[param_key]
221221
|> Map.put(:params, [{param_key, Utils.strip_leading_space(current_word)} | params])
222222
end
@@ -240,7 +240,7 @@ defmodule CucumberExpressions.Matcher do
240240
next_keys,
241241
rest,
242242
parameter_types,
243-
m = matcher(current_word: current_word, ctx: ctx),
243+
m = matcher(ctx: ctx),
244244
parse_tree
245245
) do
246246
next_keys
@@ -325,7 +325,7 @@ defmodule CucumberExpressions.Matcher do
325325
parameter_types
326326
)
327327
|> case do
328-
{:error, operation, error} ->
328+
{:error, _, _} ->
329329
Failure.raise(
330330
ctx,
331331
%{param_key: current_key, value: to_be_matched},
@@ -342,8 +342,7 @@ defmodule CucumberExpressions.Matcher do
342342

343343
defp potential_param_to_value_match(
344344
potential_match,
345-
m =
346-
matcher(current_word: current_word, params: params, parameter_types: parameter_types),
345+
m = matcher(),
347346
parse_tree
348347
) do
349348
potential_match

apps/cucumber_expressions/lib/cucumber_expressions/matcher/submatcher.ex

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ defmodule CucumberExpressions.Matcher.Submatcher do
4242
potential_submatches: potential_submatches,
4343
previous_subsentence: previous_subsentence,
4444
current_word: current_word,
45-
parameter_types: parameter_types,
4645
only_spaces_so_far?: false
4746
),
4847
remainder_sentence = <<" ", rest::binary>>
@@ -84,7 +83,7 @@ defmodule CucumberExpressions.Matcher.Submatcher do
8483
end
8584

8685
defp retrieve(
87-
s =
86+
# s =
8887
submatcher(
8988
potential_submatches: potential_submatches,
9089
previous_subsentence: previous_subsentence,
3.91 KB
Binary file not shown.

apps/ex_cucumber/lib/ex_cucumber.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ defmodule ExCucumber do
22
@moduledoc """
33
Documentation for ExCucumber.
44
"""
5+
@external_resource "config/config.exs"
56

67
alias CucumberExpressions.ParameterType
78
use ExDebugger.Manual

apps/ex_cucumber/lib/ex_cucumber/config.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
defmodule ExCucumber.Config do
22
@moduledoc false
3+
@external_resource "config/config.exs"
4+
35
@macro_styles [:def, :module]
46
@error_detail_levels [:brief, :verbose]
57
@all_best_practices %{

apps/ex_cucumber/lib/ex_cucumber/exceptions/messages/configuration_error_messages/invalid_feature_dir.ex

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ defmodule ExCucumber.Exceptions.Messages.InvalidFeatureDir do
99
"""
1010
end
1111

12-
def render(%ConfigurationError{error_code: :invalid_feature_dir} = e, :verbose) do
13-
IO.inspect(e.ctx)
12+
def render(%ConfigurationError{error_code: :invalid_feature_dir}, :verbose) do
1413
"""
1514
# Invalid Value For Feature Directory Specified
1615
## Summary

apps/ex_cucumber/lib/ex_cucumber/exceptions/messages/match_failure_messages/unable_to_match.ex

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,6 @@ defmodule ExCucumber.Exceptions.Messages.UnableToMatch do
3838
}`
3939
* Module: `#{module_name}`
4040
* Cause: Missing `cucumber expression` for: #{Utils.smart_quotes(f.ctx.sentence)}
41-
* extra: #{inspect(f.extra, pretty: true)}
4241
"""
43-
44-
# * Gherkin Keyword: #{f.ctx.keyword}
45-
# * Gherkin Keyword Token: #{f.ctx.token}
46-
# * Macro: #{f.ctx.inferred.macro}
47-
# * Location Feature File:
48-
# - Line: #{f.ctx.location.line}
49-
# - Column: #{f.ctx.location.column}
5042
end
5143
end

apps/ex_cucumber/lib/ex_cucumber/exceptions/messages/messages.ex

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ defmodule ExCucumber.Exceptions.Messages do
5656
feature_file_not_found: {FeatureFileNotFound, @configuration_error_heading}
5757
}
5858

59-
def render(f) do
59+
def render(f, exit? \\ true)
60+
def render(f, exit?) when is_atom(exit?) do
6061
error_detail_level = ExCucumber.Config.error_detail_level()
6162
dd(:render)
6263

@@ -65,7 +66,7 @@ defmodule ExCucumber.Exceptions.Messages do
6566
IO.ANSI.Docs.print_heading(heading, @default_options)
6667
IO.ANSI.Docs.print(body, @default_options)
6768

68-
exit(:shutdown)
69+
if exit?, do: exit(:shutdown)
6970
else
7071
{_, body} = render(f, detail_level: :brief)
7172

@@ -75,6 +76,10 @@ defmodule ExCucumber.Exceptions.Messages do
7576
end
7677
end
7778

79+
def render(%CompileError{} = f, detail_level: detail_level) do
80+
raise f
81+
end
82+
7883
def render(%_{error_code: error_code} = f, detail_level: detail_level) do
7984
{module, heading} = Map.fetch!(@delegation_mappings, error_code)
8085

apps/ex_cucumber/lib/ex_cucumber/gherkin/gherkin_keywords.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
defmodule ExCucumber.Gherkin.Keywords do
22
@moduledoc false
3-
3+
@external_resource "config/config.exs"
4+
45
alias ExCucumber.Gherkin.Traverser.Ctx
56
alias ExCucumber.Config
67

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
defmodule ExCucumber.Report do
2+
@moduledoc false
3+
4+
defstruct [
5+
total: 0,
6+
passed: 0,
7+
failed: [],
8+
skipped: 0
9+
]
10+
11+
def new, do: %__MODULE__{}
12+
13+
def record(%__MODULE__{} = m, :passed), do: %{m | passed: m.passed + 1} |> total()
14+
def record(%__MODULE__{} = m, details), do: %{m | failed: [details | Map.fetch!(m, :failed)]} |> total()
15+
def total(%__MODULE__{} = m), do: %{m | total: m.total + 1}
16+
end

0 commit comments

Comments
 (0)