File: arbitrary_methods.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 (40 lines) | stat: -rw-r--r-- 1,192 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
Feature: Defining arbitrary helper methods

  You can define methods in any example group using Ruby's `def` keyword or
  `define_method` method. These _helper_ methods are exposed to examples in the
  group in which they are defined and groups nested within that group, but not
  parent or sibling groups.

  Scenario: Use a method defined in the same group
    Given a file named "example_spec.rb" with:
      """ruby
      RSpec.describe "an example" do
        def help
          :available
        end

        it "has access to methods defined in its group" do
          expect(help).to be(:available)
        end
      end
      """
    When I run `rspec example_spec.rb`
    Then the examples should all pass

  Scenario: Use a method defined in a parent group
    Given a file named "example_spec.rb" with:
      """ruby
      RSpec.describe "an example" do
        def help
          :available
        end

        describe "in a nested group" do
          it "has access to methods defined in its parent group" do
            expect(help).to be(:available)
          end
        end
      end
      """
    When I run `rspec example_spec.rb`
    Then the examples should all pass