Skip to content

Commit

Permalink
Add failing test for OrderedOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
jas14 committed Nov 4, 2023
1 parent 7772aa1 commit 26e1f6c
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 0 deletions.
42 changes: 42 additions & 0 deletions spec/support/shared_examples/active_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,46 @@
end
end
end

context "when comparing OrderedOptions and Hash instances",
active_record: true do
it "produces the correct failure message when used in the positive" do
as_both_colored_and_uncolored do |color_enabled|
snippet = <<~RUBY
expected = {beep: :bip}
actual = ::ActiveSupport::OrderedOptions[beep: :boop]
expect(expected).to eq(actual)
RUBY
program =
make_rspec_rails_test_program(snippet, color_enabled: color_enabled)

expected_output =
build_expected_output(
color_enabled: color_enabled,
snippet: "expect(expected).to eq(actual)",
expectation:
proc do
line do
plain "Expected "
actual "{ beep: :bip }"
plain " to eq "
expected "#<OrderedOptions { beep: :boop }>"
plain "."
end
end,
diff:
proc do
plain_line " {"
expected_line "- beep: :boop"
actual_line "+ beep: :bip"
plain_line " }"
end
)

expect(program).to produce_output_when_run(expected_output).in_color(
color_enabled
)
end
end
end
end
62 changes: 62 additions & 0 deletions spec/unit/active_support/object_inspection_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
require "spec_helper"

RSpec.describe SuperDiff, type: :unit do
describe ".inspect_object",
"for ActiveSupport objects",
active_support: true do
context "given an ActiveSupport::OrderedOptions object" do
context "given as_lines: false" do
it "returns an inspected version of the object" do
string =
described_class.inspect_object(
::ActiveSupport::OrderedOptions[name: "Bob", age: 42],
as_lines: false
)
expect(string).to eq(%(#<OrderedOptions { name: "Bob", age: 42 }>))
end
end

context "given as_lines: true" do
it "returns an inspected version of the object as multiple Lines" do
tiered_lines =
described_class.inspect_object(
::ActiveSupport::OrderedOptions[name: "Bob", age: 42],
as_lines: true,
type: :delete,
indentation_level: 1
)
expect(tiered_lines).to match(
[
an_object_having_attributes(
type: :delete,
indentation_level: 1,
value: "#<OrderedOptions {",
collection_bookend: :open
),
an_object_having_attributes(
type: :delete,
indentation_level: 2,
prefix: "name: ",
value: "\"Bob\"",
add_comma: true
),
an_object_having_attributes(
type: :delete,
indentation_level: 2,
prefix: "age: ",
value: "42",
add_comma: false
),
an_object_having_attributes(
type: :delete,
indentation_level: 1,
value: "}>",
collection_bookend: :close
)
]
)
end
end
end
end
end

0 comments on commit 26e1f6c

Please sign in to comment.