Skip to content

Commit

Permalink
Merge branch 'main' into feat/date-like-objects-support
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmire authored Jan 30, 2024
2 parents a0decaf + 34e9609 commit 7a47251
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 53 deletions.
8 changes: 5 additions & 3 deletions .husky/pre-push
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

. "$(dirname -- "$0")/_/husky.sh"

echo "Fixing changed files with lint violations..."
echo "*** Checking for lint violations in changed files ***************"
echo

yarn prettier --write --ignore-unknown $(git diff "$(git merge-base main HEAD)" --name-only) || exit $?
yarn prettier --check --ignore-unknown $(git diff --cached "$(git merge-base main HEAD)" --name-only --diff-filter=d) || exit $?

echo
echo "Auditing dependencies..."
echo "*** Auditing dependencies ***************"
echo

yarn audit || exit $?

Expand Down
4 changes: 0 additions & 4 deletions lib/super_diff/errors.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
module SuperDiff
module Errors
autoload(
:NoDiffFormatterAvailableError,
"super_diff/errors/no_diff_formatter_available_error"
)
autoload(
:NoDifferAvailableError,
"super_diff/errors/no_differ_available_error"
Expand Down
21 changes: 0 additions & 21 deletions lib/super_diff/errors/no_diff_formatter_available_error.rb

This file was deleted.

22 changes: 0 additions & 22 deletions lib/super_diff/errors/no_operational_sequencer_available_error.rb

This file was deleted.

23 changes: 22 additions & 1 deletion lib/super_diff/rspec/monkey_patches.rb
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,10 @@ def failure_line_groups
}
end
end

@failure_line_groups << {
lines: extra_failure_lines,
already_colorized: true
}
@failure_line_groups
end
end
Expand All @@ -241,6 +244,24 @@ def failure_slash_error_lines
lines
end

# Override to ensure that each item in the array returned is one and
# only one line and doesn't contain any newline characters
def extra_failure_lines
@extra_failure_lines ||=
begin
original_lines = Array(example.metadata[:extra_failure_lines])
normalized_lines =
original_lines.flat_map { |line| line.split("\n") }
unless normalized_lines.empty?
unless normalized_lines.first == ""
normalized_lines.unshift("")
end
normalized_lines.push("") unless normalized_lines.last == ""
end
normalized_lines
end
end

# Exclude this file from being included in backtraces, so that the
# SnippetExtractor prints the right thing
def find_failed_line
Expand Down
51 changes: 51 additions & 0 deletions spec/integration/rspec/magic_metadata_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
require "spec_helper"

RSpec.describe "Integration with RSpec's magic metadata", type: :integration do
it "includes extra_failure_lines in failure messages" do
as_both_colored_and_uncolored do |color_enabled|
snippet = <<~TEST.strip
RSpec.describe "test" do
it { expect(true).to be(false) }
after do
RSpec.current_example.metadata[:extra_failure_lines] = "foo\nbar"
end
end
TEST
program =
make_plain_test_program(
snippet,
color_enabled: color_enabled,
preserve_as_whole_file: true
)

expected_output =
build_expected_output(
color_enabled: color_enabled,
test_name: "test is expected to equal false",
snippet: "it { expect(true).to be(false) }",
expectation:
proc do
line do
plain "Expected "
actual "true"
plain " to equal "
expected "false"
plain "."
end
end,
extra_failure_lines:
proc do
indent by: 5 do
line "foo"
line "bar"
end
end
)

expect(program).to produce_output_when_run(expected_output).in_color(
color_enabled
)
end
end
end
11 changes: 9 additions & 2 deletions spec/support/integration/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,17 @@ def build_expected_output(
color_enabled:,
snippet:,
expectation:,
test_name: "test passes",
key_enabled: true,
newline_before_expectation: false,
indentation: 7,
diff: nil
diff: nil,
extra_failure_lines: nil
)
colored(color_enabled: color_enabled) do
line "Failures:\n"

line "1) test passes", indent_by: 2
line "1) #{test_name}", indent_by: 2

line indent_by: 5 do
bold "Failure/Error: "
Expand Down Expand Up @@ -106,6 +108,11 @@ def build_expected_output(
newline
end
end

if extra_failure_lines
newline
evaluate_block(&extra_failure_lines)
end
end
end

Expand Down

0 comments on commit 7a47251

Please # to comment.