Skip to content

Commit f480ad7

Browse files
committed
add rspec tests
1 parent f72a767 commit f480ad7

File tree

2 files changed

+63
-21
lines changed

2 files changed

+63
-21
lines changed

spec/react_on_rails/prender_error_spec.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,30 @@ module ReactOnRails
4545
expect(expected_error.raven_context).to eq(expected_error_info)
4646
end
4747
end
48+
49+
describe "error message formatting" do
50+
context "when FULL_TEXT_ERRORS is true" do
51+
before { ENV["FULL_TEXT_ERRORS"] = "true" }
52+
after { ENV["FULL_TEXT_ERRORS"] = nil }
53+
54+
it "shows the full backtrace" do
55+
message = expected_error.message
56+
expect(message).to include(err.inspect)
57+
expect(message).to include(err.backtrace.join("\n"))
58+
expect(message).not_to include("The rest of the backtrace is hidden")
59+
end
60+
end
61+
62+
context "when FULL_TEXT_ERRORS is not set" do
63+
before { ENV["FULL_TEXT_ERRORS"] = nil }
64+
65+
it "shows truncated backtrace with notice" do
66+
message = expected_error.message
67+
expect(message).to include(err.inspect)
68+
expect(message).to include(err.backtrace.first(15).join("\n"))
69+
expect(message).to include("The rest of the backtrace is hidden")
70+
end
71+
end
72+
end
4873
end
4974
end

spec/react_on_rails/utils_spec.rb

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -310,30 +310,47 @@ module ReactOnRails
310310
end
311311

312312
describe ".smart_trim" do
313-
it "trims smartly" do
314-
s = "1234567890"
315-
316-
expect(described_class.smart_trim(s, -1)).to eq("1234567890")
317-
expect(described_class.smart_trim(s, 0)).to eq("1234567890")
318-
expect(described_class.smart_trim(s, 1)).to eq("1#{Utils::TRUNCATION_FILLER}")
319-
expect(described_class.smart_trim(s, 2)).to eq("1#{Utils::TRUNCATION_FILLER}0")
320-
expect(described_class.smart_trim(s, 3)).to eq("1#{Utils::TRUNCATION_FILLER}90")
321-
expect(described_class.smart_trim(s, 4)).to eq("12#{Utils::TRUNCATION_FILLER}90")
322-
expect(described_class.smart_trim(s, 5)).to eq("12#{Utils::TRUNCATION_FILLER}890")
323-
expect(described_class.smart_trim(s, 6)).to eq("123#{Utils::TRUNCATION_FILLER}890")
324-
expect(described_class.smart_trim(s, 7)).to eq("123#{Utils::TRUNCATION_FILLER}7890")
325-
expect(described_class.smart_trim(s, 8)).to eq("1234#{Utils::TRUNCATION_FILLER}7890")
326-
expect(described_class.smart_trim(s, 9)).to eq("1234#{Utils::TRUNCATION_FILLER}67890")
327-
expect(described_class.smart_trim(s, 10)).to eq("1234567890")
328-
expect(described_class.smart_trim(s, 11)).to eq("1234567890")
313+
let(:long_string) { "1234567890" }
314+
315+
context "when FULL_TEXT_ERRORS is true" do
316+
before { ENV["FULL_TEXT_ERRORS"] = "true" }
317+
after { ENV["FULL_TEXT_ERRORS"] = nil }
318+
319+
it "returns the full string regardless of length" do
320+
expect(described_class.smart_trim(long_string, 5)).to eq(long_string)
321+
end
322+
323+
it "handles a hash without trimming" do
324+
hash = { a: long_string }
325+
expect(described_class.smart_trim(hash, 5)).to eq(hash.to_s)
326+
end
329327
end
330328

331-
it "trims handles a hash" do
332-
s = { a: "1234567890" }
329+
context "when FULL_TEXT_ERRORS is not set" do
330+
before { ENV["FULL_TEXT_ERRORS"] = nil }
331+
332+
it "trims smartly" do
333+
expect(described_class.smart_trim(long_string, -1)).to eq("1234567890")
334+
expect(described_class.smart_trim(long_string, 0)).to eq("1234567890")
335+
expect(described_class.smart_trim(long_string, 1)).to eq("1#{Utils::TRUNCATION_FILLER}")
336+
expect(described_class.smart_trim(long_string, 2)).to eq("1#{Utils::TRUNCATION_FILLER}0")
337+
expect(described_class.smart_trim(long_string, 3)).to eq("1#{Utils::TRUNCATION_FILLER}90")
338+
expect(described_class.smart_trim(long_string, 4)).to eq("12#{Utils::TRUNCATION_FILLER}90")
339+
expect(described_class.smart_trim(long_string, 5)).to eq("12#{Utils::TRUNCATION_FILLER}890")
340+
expect(described_class.smart_trim(long_string, 6)).to eq("123#{Utils::TRUNCATION_FILLER}890")
341+
expect(described_class.smart_trim(long_string, 7)).to eq("123#{Utils::TRUNCATION_FILLER}7890")
342+
expect(described_class.smart_trim(long_string, 8)).to eq("1234#{Utils::TRUNCATION_FILLER}7890")
343+
expect(described_class.smart_trim(long_string, 9)).to eq("1234#{Utils::TRUNCATION_FILLER}67890")
344+
expect(described_class.smart_trim(long_string, 10)).to eq("1234567890")
345+
expect(described_class.smart_trim(long_string, 11)).to eq("1234567890")
346+
end
333347

334-
expect(described_class.smart_trim(s, 9)).to eq(
335-
"{:a=#{Utils::TRUNCATION_FILLER}890\"}"
336-
)
348+
it "trims handles a hash" do
349+
s = { a: "1234567890" }
350+
expect(described_class.smart_trim(s, 9)).to eq(
351+
"{:a=#{Utils::TRUNCATION_FILLER}890\"}"
352+
)
353+
end
337354
end
338355
end
339356

0 commit comments

Comments
 (0)