File: standalone.feature

package info (click to toggle)
ruby-rspec 3.9.0c2e2m1s3-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 6,612 kB
  • sloc: ruby: 67,456; sh: 1,572; makefile: 98
file content (33 lines) | stat: -rw-r--r-- 1,055 bytes parent folder | download | duplicates (5)
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
Feature: Standalone

  `require "rspec/mocks/standalone"` to expose the API at the top level (e.g. `main`) outside
  the RSpec environment in a REPL like IRB or in a one-off script.

  Scenario: Allow a message outside RSpec
    Given a file named "example.rb" with:
      """ruby
      require "rspec/mocks/standalone"

      greeter = double("greeter")
      allow(greeter).to receive(:say_hi) { "Hello!" }
      puts greeter.say_hi
      """
    When I run `ruby example.rb`
    Then the output should contain "Hello!"

  Scenario: Expect a message outside RSpec
    Given a file named "example.rb" with:
      """ruby
      require "rspec/mocks/standalone"

      greeter = double("greeter")
      expect(greeter).to receive(:say_hi)

      RSpec::Mocks.verify
      """
    When I run `ruby example.rb`
    Then it should fail with the following output:
      | (Double "greeter").say_hi(*(any args)) |
      | RSpec::Mocks::MockExpectationError     |
      | expected: 1 time with any arguments    |
      | received: 0 times with any arguments   |