<NME> backtrace_exclusion_patterns.feature
<BEF> Feature: Excluding lines from the backtrace

  To reduce the noise when diagnosing failures, RSpec can exclude lines belonging to certain gems or matching given patterns.

  If you want to filter out backtrace lines belonging to specific gems, you can use `config.filter_gems_from_backtrace` like so:

  ```ruby
  config.filter_gems_from_backtrace "ignored_gem", "another_ignored_gem",
  ```

  For more control over which lines to ignore, you can use the the `backtrace_exclusion_patterns` option to either replace the default exclusion patterns, or append your own, e.g.

  ```ruby
  config.backtrace_exclusion_patterns = [/first pattern/, /second pattern/]
  config.backtrace_exclusion_patterns << /another pattern/
  ```

  The default exclusion patterns are:

  ```ruby
  /\/lib\d*\/ruby\//,
  /org\/jruby\//,
  /bin\//,
  /lib\/rspec\/(core|expectations|matchers|mocks)/
  ```

  Additionally, `rspec` can be run with the `--backtrace` option to skip backtrace cleaning entirely.


  Scenario: Using default `backtrace_exclusion_patterns`
    Given a file named "spec/failing_spec.rb" with:
    """ruby
    RSpec.describe "2 + 2" do
      it "is 5" do
        expect(2+2).to eq(5)
      end
    end
        /spec_helper/
      ]
    end

    def foo
      "bar"
    end
    """
    And a file named "spec/example_spec.rb" with:
    """ruby
    require 'spec_helper'
    RSpec.describe "foo" do
      it "returns baz" do
        expect(foo).to eq("baz")
      end
    end
    """
    """
    And a file named "spec/example_spec.rb" with:
    And the output should contain "lib/rspec/expectations"

  Scenario: Appending to `backtrace_exclusion_patterns`
    Given a file named "spec/matchers/be_baz_matcher.rb" with:
    """ruby
    RSpec::Matchers.define :be_baz do |_|
      match do |actual|
        actual == "baz"
      end
    end
    """
    And a file named "spec/example_spec.rb" with:
    """ruby
    RSpec.configure do |config|
      config.backtrace_exclusion_patterns << /be_baz_matcher/
    end

    RSpec.describe "bar" do
      it "is baz" do
        expect("bar").to be_baz
      end
    end
    """
    When I run `rspec`
    Then the output should contain "1 example, 1 failure"
    But the output should not contain "be_baz_matcher"
    And the output should not contain "lib/rspec/expectations"

  Scenario: Running `rspec` with the `--backtrace` option
    Given a file named "spec/matchers/be_baz_matcher.rb" with:
    """ruby
    RSpec::Matchers.define :be_baz do |_|
      match do |actual|
        actual == "baz"
      end
    end
    """
    And a file named "spec/example_spec.rb" with:
    """ruby
    RSpec.configure do |config|
      config.backtrace_exclusion_patterns << /be_baz_matcher/
    end

    RSpec.describe "bar" do
      it "is baz" do
        expect("bar").to be_baz
      end
    end
    """
    When I run `rspec --backtrace`
    Then the output should contain "1 example, 1 failure"
    And the output should not contain "be_baz_matcher"

  Scenario: Using `filter_gems_from_backtrace` to filter the named gem
    Given a vendored gem named "my_gem" containing a file named "lib/my_gem.rb" with:
    end
    """
    When I run `rspec --backtrace`
    Then the output should contain "1 example, 1 failure"
    And the output should contain "spec/support/custom_helper.rb:2:in `assert_baz'"
    And the output should contain "lib/rspec/expectations"
    And the output should contain "lib/rspec/core"

  Scenario: Using `filter_gems_from_backtrace` to filter the named gem
    Given a vendored gem named "my_gem" containing a file named "lib/my_gem.rb" with:
      """ruby
      class MyGem
        def self.do_amazing_things!
          # intentional bug to trigger an exception
          impossible_math = 10 / 0
          "10 div 0 is: #{impossible_math}"
        end
      end
      """
    And a file named "spec/use_my_gem_spec.rb" with:
      """ruby
      require 'my_gem'

      RSpec.describe "Using my_gem" do
        it 'does amazing things' do
          expect(MyGem.do_amazing_things!).to include("10 div 0 is")
        end
      end
      """
    And a file named "spec/spec_helper.rb" with:
      """ruby
      RSpec.configure do |config|
        config.filter_gems_from_backtrace "my_gem"
      end
      """
    Then the output from `rspec` should contain "vendor/my_gem-1.2.3/lib/my_gem.rb:4:in `do_amazing_things!'"
    But the output from `rspec --require spec_helper` should not contain "vendor/my_gem-1.2.3/lib/my_gem.rb:4:in `do_amazing_things!'"

<MSG> Fix backtrace features to not be false greens

<DFF> @@ -38,17 +38,13 @@ Feature: Excluding lines from the backtrace
         /spec_helper/
       ]
     end
-
-    def foo
-      "bar"
-    end
     """
     And a file named "spec/example_spec.rb" with:
     """ruby
     require 'spec_helper'
     RSpec.describe "foo" do
       it "returns baz" do
-        expect(foo).to eq("baz")
+        expect("foo").to eq("baz")
       end
     end
     """
@@ -57,55 +53,65 @@ Feature: Excluding lines from the backtrace
     And the output should contain "lib/rspec/expectations"
 
   Scenario: Appending to `backtrace_exclusion_patterns`
-    Given a file named "spec/matchers/be_baz_matcher.rb" with:
+    Given a file named "spec/support/assert_baz.rb" with:
     """ruby
-    RSpec::Matchers.define :be_baz do |_|
-      match do |actual|
-        actual == "baz"
-      end
+    require "support/really_assert_baz"
+
+    def assert_baz(arg)
+      really_assert_baz(arg)
+    end
+    """
+    And a file named "spec/support/really_assert_baz.rb" with:
+    """ruby
+    def really_assert_baz(arg)
+      expect(arg).to eq("baz")
     end
     """
     And a file named "spec/example_spec.rb" with:
     """ruby
+    require "support/assert_baz"
     RSpec.configure do |config|
-      config.backtrace_exclusion_patterns << /be_baz_matcher/
+      config.backtrace_exclusion_patterns << /really/
     end
 
     RSpec.describe "bar" do
       it "is baz" do
-        expect("bar").to be_baz
+        assert_baz("bar")
       end
     end
     """
     When I run `rspec`
     Then the output should contain "1 example, 1 failure"
-    But the output should not contain "be_baz_matcher"
+    And the output should contain "assert_baz"
+    But the output should not contain "really_assert_baz"
     And the output should not contain "lib/rspec/expectations"
 
-  Scenario: Running `rspec` with the `--backtrace` option
-    Given a file named "spec/matchers/be_baz_matcher.rb" with:
+  Scenario: Running `rspec` with `--backtrace` prints unfiltered backtraces
+    Given a file named "spec/support/custom_helper.rb" with:
     """ruby
-    RSpec::Matchers.define :be_baz do |_|
-      match do |actual|
-        actual == "baz"
-      end
+    def assert_baz(arg)
+      expect(arg).to eq("baz")
     end
     """
     And a file named "spec/example_spec.rb" with:
     """ruby
+    require "support/custom_helper"
+
     RSpec.configure do |config|
-      config.backtrace_exclusion_patterns << /be_baz_matcher/
+      config.backtrace_exclusion_patterns << /custom_helper/
     end
 
     RSpec.describe "bar" do
       it "is baz" do
-        expect("bar").to be_baz
+        assert_baz("bar")
       end
     end
     """
     When I run `rspec --backtrace`
     Then the output should contain "1 example, 1 failure"
-    And the output should not contain "be_baz_matcher"
+    And the output should contain "spec/support/custom_helper.rb:2:in `assert_baz'"
+    And the output should contain "lib/rspec/expectations"
+    And the output should contain "lib/rspec/core"
 
   Scenario: Using `filter_gems_from_backtrace` to filter the named gem
     Given a vendored gem named "my_gem" containing a file named "lib/my_gem.rb" with:

{'commit': 'diff --git a/features/configuration/backtrace_exclusion_patterns.feature b/features/configuration/backtrace_exclusion_patterns.feature\nindex 3945f0a2..95fee755 100644\n--- a/features/configuration/backtrace_exclusion_patterns.feature\n+++ b/features/configuration/backtrace_exclusion_patterns.feature\n@@ -38,17 +38,13 @@ Feature: Excluding lines from the backtrace\n         /spec_helper/\n       ]\n     end\n-\n-    def foo\n-      "bar"\n-    end\n     """\n     And a file named "spec/example_spec.rb" with:\n     """ruby\n     require \'spec_helper\'\n     RSpec.describe "foo" do\n       it "returns baz" do\n-        expect(foo).to eq("baz")\n+        expect("foo").to eq("baz")\n       end\n     end\n     """\n@@ -57,55 +53,65 @@ Feature: Excluding lines from the backtrace\n     And the output should contain "lib/rspec/expectations"\n \n   Scenario: Appending to `backtrace_exclusion_patterns`\n-    Given a file named "spec/matchers/be_baz_matcher.rb" with:\n+    Given a file named "spec/support/assert_baz.rb" with:\n     """ruby\n-    RSpec::Matchers.define :be_baz do |_|\n-      match do |actual|\n-        actual == "baz"\n-      end\n+    require "support/really_assert_baz"\n+\n+    def assert_baz(arg)\n+      really_assert_baz(arg)\n+    end\n+    """\n+    And a file named "spec/support/really_assert_baz.rb" with:\n+    """ruby\n+    def really_assert_baz(arg)\n+      expect(arg).to eq("baz")\n     end\n     """\n     And a file named "spec/example_spec.rb" with:\n     """ruby\n+    require "support/assert_baz"\n     RSpec.configure do |config|\n-      config.backtrace_exclusion_patterns << /be_baz_matcher/\n+      config.backtrace_exclusion_patterns << /really/\n     end\n \n     RSpec.describe "bar" do\n       it "is baz" do\n-        expect("bar").to be_baz\n+        assert_baz("bar")\n       end\n     end\n     """\n     When I run `rspec`\n     Then the output should contain "1 example, 1 failure"\n-    But the output should not contain "be_baz_matcher"\n+    And the output should contain "assert_baz"\n+    But the output should not contain "really_assert_baz"\n     And the output should not contain "lib/rspec/expectations"\n \n-  Scenario: Running `rspec` with the `--backtrace` option\n-    Given a file named "spec/matchers/be_baz_matcher.rb" with:\n+  Scenario: Running `rspec` with `--backtrace` prints unfiltered backtraces\n+    Given a file named "spec/support/custom_helper.rb" with:\n     """ruby\n-    RSpec::Matchers.define :be_baz do |_|\n-      match do |actual|\n-        actual == "baz"\n-      end\n+    def assert_baz(arg)\n+      expect(arg).to eq("baz")\n     end\n     """\n     And a file named "spec/example_spec.rb" with:\n     """ruby\n+    require "support/custom_helper"\n+\n     RSpec.configure do |config|\n-      config.backtrace_exclusion_patterns << /be_baz_matcher/\n+      config.backtrace_exclusion_patterns << /custom_helper/\n     end\n \n     RSpec.describe "bar" do\n       it "is baz" do\n-        expect("bar").to be_baz\n+        assert_baz("bar")\n       end\n     end\n     """\n     When I run `rspec --backtrace`\n     Then the output should contain "1 example, 1 failure"\n-    And the output should not contain "be_baz_matcher"\n+    And the output should contain "spec/support/custom_helper.rb:2:in `assert_baz\'"\n+    And the output should contain "lib/rspec/expectations"\n+    And the output should contain "lib/rspec/core"\n \n   Scenario: Using `filter_gems_from_backtrace` to filter the named gem\n     Given a vendored gem named "my_gem" containing a file named "lib/my_gem.rb" with:\n', 'commit_subject': 'Fix backtrace features to not be false greens', 'repo_name': 'rspec/rspec-core', 'committer': {'name': 'Ben Moss', 'email': '73675debcd8a436be48ec22211dcf44fe0df0a64@mossity.com', 'time_sec': '1419701041', 'tz_offset': '-300', 'date': {'seconds': '1419701041'}}, 'commit_tree': 'beb8db7a6c03b729e3ad69bebe37c3549f6d54a4', 'commit_message': 'Fix backtrace features to not be false greens\n', 'language_name': 'Ruby', 'license': 'mit', 'hunks': '@@ -38,17 +38,13 @@ Feature: Excluding lines from the backtrace\n         /spec_helper/\n       ]\n     end\n-\n-    def foo\n-      "bar"\n-    end\n     """\n     And a file named "spec/example_spec.rb" with:\n     """ruby\n     require \'spec_helper\'\n     RSpec.describe "foo" do\n       it "returns baz" do\n-        expect(foo).to eq("baz")\n+        expect("foo").to eq("baz")\n       end\n     end\n     """\n@@ -57,55 +53,65 @@ Feature: Excluding lines from the backtrace\n     And the output should contain "lib/rspec/expectations"\n \n   Scenario: Appending to `backtrace_exclusion_patterns`\n-    Given a file named "spec/matchers/be_baz_matcher.rb" with:\n+    Given a file named "spec/support/assert_baz.rb" with:\n     """ruby\n-    RSpec::Matchers.define :be_baz do |_|\n-      match do |actual|\n-        actual == "baz"\n-      end\n+    require "support/really_assert_baz"\n+\n+    def assert_baz(arg)\n+      really_assert_baz(arg)\n+    end\n+    """\n+    And a file named "spec/support/really_assert_baz.rb" with:\n+    """ruby\n+    def really_assert_baz(arg)\n+      expect(arg).to eq("baz")\n     end\n     """\n     And a file named "spec/example_spec.rb" with:\n     """ruby\n+    require "support/assert_baz"\n     RSpec.configure do |config|\n-      config.backtrace_exclusion_patterns << /be_baz_matcher/\n+      config.backtrace_exclusion_patterns << /really/\n     end\n \n     RSpec.describe "bar" do\n       it "is baz" do\n-        expect("bar").to be_baz\n+        assert_baz("bar")\n       end\n     end\n     """\n     When I run `rspec`\n     Then the output should contain "1 example, 1 failure"\n-    But the output should not contain "be_baz_matcher"\n+    And the output should contain "assert_baz"\n+    But the output should not contain "really_assert_baz"\n     And the output should not contain "lib/rspec/expectations"\n \n-  Scenario: Running `rspec` with the `--backtrace` option\n-    Given a file named "spec/matchers/be_baz_matcher.rb" with:\n+  Scenario: Running `rspec` with `--backtrace` prints unfiltered backtraces\n+    Given a file named "spec/support/custom_helper.rb" with:\n     """ruby\n-    RSpec::Matchers.define :be_baz do |_|\n-      match do |actual|\n-        actual == "baz"\n-      end\n+    def assert_baz(arg)\n+      expect(arg).to eq("baz")\n     end\n     """\n     And a file named "spec/example_spec.rb" with:\n     """ruby\n+    require "support/custom_helper"\n+\n     RSpec.configure do |config|\n-      config.backtrace_exclusion_patterns << /be_baz_matcher/\n+      config.backtrace_exclusion_patterns << /custom_helper/\n     end\n \n     RSpec.describe "bar" do\n       it "is baz" do\n-        expect("bar").to be_baz\n+        assert_baz("bar")\n       end\n     end\n     """\n     When I run `rspec --backtrace`\n     Then the output should contain "1 example, 1 failure"\n-    And the output should not contain "be_baz_matcher"\n+    And the output should contain "spec/support/custom_helper.rb:2:in `assert_baz\'"\n+    And the output should contain "lib/rspec/expectations"\n+    And the output should contain "lib/rspec/core"\n \n   Scenario: Using `filter_gems_from_backtrace` to filter the named gem\n     Given a vendored gem named "my_gem" containing a file named "lib/my_gem.rb" with:\n', 'addition_count': 28, 'deletion_count': 22, 'src_file': 'a/features/configuration/backtrace_exclusion_patterns.feature', 'tgt_file': 'b/features/configuration/backtrace_exclusion_patterns.feature', 'file_extension': '.feature', 'before_file': 'Feature: Excluding lines from the backtrace\n\n  To reduce the noise when diagnosing failures, RSpec can exclude lines belonging to certain gems or matching given patterns.\n\n  If you want to filter out backtrace lines belonging to specific gems, you can use `config.filter_gems_from_backtrace` like so:\n\n  ```ruby\n  config.filter_gems_from_backtrace "ignored_gem", "another_ignored_gem",\n  ```\n\n  For more control over which lines to ignore, you can use the the `backtrace_exclusion_patterns` option to either replace the default exclusion patterns, or append your own, e.g.\n\n  ```ruby\n  config.backtrace_exclusion_patterns = [/first pattern/, /second pattern/]\n  config.backtrace_exclusion_patterns << /another pattern/\n  ```\n\n  The default exclusion patterns are:\n\n  ```ruby\n  /\\/lib\\d*\\/ruby\\//,\n  /org\\/jruby\\//,\n  /bin\\//,\n  /lib\\/rspec\\/(core|expectations|matchers|mocks)/\n  ```\n\n  Additionally, `rspec` can be run with the `--backtrace` option to skip backtrace cleaning entirely.\n\n\n  Scenario: Using default `backtrace_exclusion_patterns`\n    Given a file named "spec/failing_spec.rb" with:\n    """ruby\n    RSpec.describe "2 + 2" do\n      it "is 5" do\n        expect(2+2).to eq(5)\n      end\n    end\n        /spec_helper/\n      ]\n    end\n\n    def foo\n      "bar"\n    end\n    """\n    And a file named "spec/example_spec.rb" with:\n    """ruby\n    require \'spec_helper\'\n    RSpec.describe "foo" do\n      it "returns baz" do\n        expect(foo).to eq("baz")\n      end\n    end\n    """\n    """\n    And a file named "spec/example_spec.rb" with:\n    And the output should contain "lib/rspec/expectations"\n\n  Scenario: Appending to `backtrace_exclusion_patterns`\n    Given a file named "spec/matchers/be_baz_matcher.rb" with:\n    """ruby\n    RSpec::Matchers.define :be_baz do |_|\n      match do |actual|\n        actual == "baz"\n      end\n    end\n    """\n    And a file named "spec/example_spec.rb" with:\n    """ruby\n    RSpec.configure do |config|\n      config.backtrace_exclusion_patterns << /be_baz_matcher/\n    end\n\n    RSpec.describe "bar" do\n      it "is baz" do\n        expect("bar").to be_baz\n      end\n    end\n    """\n    When I run `rspec`\n    Then the output should contain "1 example, 1 failure"\n    But the output should not contain "be_baz_matcher"\n    And the output should not contain "lib/rspec/expectations"\n\n  Scenario: Running `rspec` with the `--backtrace` option\n    Given a file named "spec/matchers/be_baz_matcher.rb" with:\n    """ruby\n    RSpec::Matchers.define :be_baz do |_|\n      match do |actual|\n        actual == "baz"\n      end\n    end\n    """\n    And a file named "spec/example_spec.rb" with:\n    """ruby\n    RSpec.configure do |config|\n      config.backtrace_exclusion_patterns << /be_baz_matcher/\n    end\n\n    RSpec.describe "bar" do\n      it "is baz" do\n        expect("bar").to be_baz\n      end\n    end\n    """\n    When I run `rspec --backtrace`\n    Then the output should contain "1 example, 1 failure"\n    And the output should not contain "be_baz_matcher"\n\n  Scenario: Using `filter_gems_from_backtrace` to filter the named gem\n    Given a vendored gem named "my_gem" containing a file named "lib/my_gem.rb" with:\n    end\n    """\n    When I run `rspec --backtrace`\n    Then the output should contain "1 example, 1 failure"\n    And the output should contain "spec/support/custom_helper.rb:2:in `assert_baz\'"\n    And the output should contain "lib/rspec/expectations"\n    And the output should contain "lib/rspec/core"\n\n  Scenario: Using `filter_gems_from_backtrace` to filter the named gem\n    Given a vendored gem named "my_gem" containing a file named "lib/my_gem.rb" with:\n      """ruby\n      class MyGem\n        def self.do_amazing_things!\n          # intentional bug to trigger an exception\n          impossible_math = 10 / 0\n          "10 div 0 is: #{impossible_math}"\n        end\n      end\n      """\n    And a file named "spec/use_my_gem_spec.rb" with:\n      """ruby\n      require \'my_gem\'\n\n      RSpec.describe "Using my_gem" do\n        it \'does amazing things\' do\n          expect(MyGem.do_amazing_things!).to include("10 div 0 is")\n        end\n      end\n      """\n    And a file named "spec/spec_helper.rb" with:\n      """ruby\n      RSpec.configure do |config|\n        config.filter_gems_from_backtrace "my_gem"\n      end\n      """\n    Then the output from `rspec` should contain "vendor/my_gem-1.2.3/lib/my_gem.rb:4:in `do_amazing_things!\'"\n    But the output from `rspec --require spec_helper` should not contain "vendor/my_gem-1.2.3/lib/my_gem.rb:4:in `do_amazing_things!\'"\n', 'message': 'Fix backtrace features to not be false greens\n', 'author_name': 'Ben Moss', 'lang': 'feature'}