/vendor/bundle/jruby/2.1/gems/rspec-core-2.14.8/spec/rspec/core/backtrace_cleaner_spec.rb

https://github.com/delowong/logstash · Ruby · 68 lines · 57 code · 11 blank · 0 comment · 0 complexity · 549a13f01e5e0a855204173c78d41015 MD5 · raw file

  1. require "spec_helper"
  2. module RSpec::Core
  3. describe BacktraceCleaner do
  4. context "with no patterns" do
  5. it "keeps all lines" do
  6. lines = ["/tmp/a_file", "some_random_text", "hello\330\271!"]
  7. cleaner = BacktraceCleaner.new([], [])
  8. expect(lines.all? {|line| cleaner.exclude? line}).to be_false
  9. end
  10. it 'is considered a full backtrace' do
  11. expect(BacktraceCleaner.new([], []).full_backtrace?).to be_true
  12. end
  13. end
  14. context "with an exclusion pattern but no inclusion patterns" do
  15. it "excludes lines that match the exclusion pattern" do
  16. cleaner = BacktraceCleaner.new([], [/remove/])
  17. expect(cleaner.exclude? "remove me").to be_true
  18. end
  19. it "keeps lines that do not match the exclusion pattern" do
  20. cleaner = BacktraceCleaner.new([], [/remove/])
  21. expect(cleaner.exclude? "apple").to be_false
  22. end
  23. it 'is considered a partial backtrace' do
  24. expect(BacktraceCleaner.new([], [/remove/]).full_backtrace?).to be_false
  25. end
  26. end
  27. context "with an exclusion pattern and an inclusion pattern" do
  28. it "excludes lines that match the exclusion pattern but not the inclusion pattern" do
  29. cleaner = BacktraceCleaner.new([/keep/], [/discard/])
  30. expect(cleaner.exclude? "discard").to be_true
  31. end
  32. it "keeps lines that match the inclusion pattern and the exclusion pattern" do
  33. cleaner = BacktraceCleaner.new([/hi/], [/.*/])
  34. expect(cleaner.exclude? "hi").to be_false
  35. end
  36. it "keeps lines that match neither pattern" do
  37. cleaner = BacktraceCleaner.new([/hi/], [/delete/])
  38. expect(cleaner.exclude? "fish").to be_false
  39. end
  40. it 'is considered a partial backtrace' do
  41. expect(BacktraceCleaner.new([], [/remove/]).full_backtrace?).to be_false
  42. end
  43. end
  44. context "with an exclusion pattern that matches the current working directory" do
  45. it "defaults to having one inclusion pattern, the current working directory" do
  46. cleaner = BacktraceCleaner.new(nil, [/.*/])
  47. expect(Dir.getwd =~ cleaner.inclusion_patterns.first).to be_true
  48. end
  49. end
  50. context "with an exclusion pattern that does not match the current working directory" do
  51. it "defaults to having no exclusion patterns" do
  52. cleaner = BacktraceCleaner.new(nil, [/i_wont_match_a_directory/])
  53. expect(cleaner.inclusion_patterns.length).to be_zero
  54. end
  55. end
  56. end
  57. end