File: stub_implementation.feature

package info (click to toggle)
ruby-rspec-mocks 2.14.5-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 868 kB
  • ctags: 725
  • sloc: ruby: 8,227; makefile: 4
file content (48 lines) | stat: -rw-r--r-- 1,419 bytes parent folder | download | duplicates (2)
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
45
46
47
48
Feature: stub with substitute implementation

  You can stub an implementation of a method (a.k.a. fake) by passing a block
  to the `stub` method.

  Scenario: stub implementation using `expect` syntax
  Given a file named "stub_implementation_spec.rb" with:
    """ruby
    describe "a stubbed implementation" do
      it "works" do
        object = Object.new
        allow(object).to receive(:foo) do |arg|
          if arg == :this
            "got this"
          elsif arg == :that
            "got that"
          end
        end

        expect(object.foo(:this)).to eq("got this")
        expect(object.foo(:that)).to eq("got that")
      end
    end
    """
  When I run `rspec stub_implementation_spec.rb`
  Then the output should contain "1 example, 0 failures"

  Scenario: stub implementation using `should` syntax
    Given a file named "stub_implementation_spec.rb" with:
      """ruby
      describe "a stubbed implementation" do
        it "works" do
          object = Object.new
          object.stub(:foo) do |arg|
            if arg == :this
              "got this"
            elsif arg == :that
              "got that"
            end
          end

          object.foo(:this).should eq("got this")
          object.foo(:that).should eq("got that")
        end
      end
      """
    When I run `rspec stub_implementation_spec.rb`
    Then the output should contain "1 example, 0 failures"