File: exist.feature

package info (click to toggle)
ruby-rspec 3.13.0c0e0m0s1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,856 kB
  • sloc: ruby: 70,868; sh: 1,423; makefile: 99
file content (44 lines) | stat: -rw-r--r-- 1,288 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
Feature: `exist` matcher

  The `exist` matcher is used to specify that something exists (as indicated by `#exist?` or `#exists?`):

  ```ruby
    expect(obj).to exist # passes if obj.exist? or obj.exists?
  ```

  Scenario: Basic usage
    Given a file named "exist_matcher_spec.rb" with:
      """ruby
      class Planet
        attr_reader :name

        def initialize(name)
          @name = name
        end

        def inspect
          "<Planet: #{name}>"
        end

        def exist? # also works with exists?
          %w[Mercury Venus Earth Mars Jupiter Saturn Uranus Neptune].include?(name)
        end
      end

      RSpec.describe "Earth" do
        let(:earth) { Planet.new("Earth") }
        specify { expect(earth).to exist }
        specify { expect(earth).not_to exist } # deliberate failure
      end

      RSpec.describe "Tatooine" do
        let(:tatooine) { Planet.new("Tatooine") }
        specify { expect(tatooine).to exist } # deliberate failure
        specify { expect(tatooine).not_to exist }
      end
      """
    When I run `rspec exist_matcher_spec.rb`
    Then the output should contain all of these:
      | 4 examples, 2 failures                |
      | expected <Planet: Earth> not to exist |
      | expected <Planet: Tatooine> to exist  |