Skip to content

Commit

Permalink
Implement line option to work with context and describe
Browse files Browse the repository at this point in the history
  • Loading branch information
sirius248 committed Apr 1, 2017
1 parent c8cbc91 commit 4570579
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions lib/espec/suite_runner.ex
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,31 @@ defmodule ESpec.SuiteRunner do
opts = opts_for_file(file, file_opts)
line = Keyword.get(opts, :line)
if line do
closest = get_closest(Enum.map(exs, &(&1.line)), line)
acc ++ Enum.filter(exs, &(&1.line == closest))
block_filtered = filtered_examples_within_block(exs, line)
if Enum.empty?(block_filtered) do
closest = get_closest(Enum.map(exs, &(&1.line)), line)
acc ++ Enum.filter(exs, &(&1.line == closest))
else
acc ++ block_filtered
end
else
acc ++ exs
end
end)
filtered
end

defp filtered_examples_within_block(examples, line) do
examples
|> Enum.filter(fn(ex) ->
ex
|> Map.get(:context)
|> Enum.filter(fn(c) -> c.__struct__ == ESpec.Context end)
|> Enum.map(fn(c) -> c.line end)
|> Enum.member?(line)
end)
end

defp get_closest(arr, value) do
arr = Enum.sort(arr)
line = arr
Expand Down

0 comments on commit 4570579

Please sign in to comment.