File: ruby_2_support_spec.rb

package info (click to toggle)
ruby-bogus 0.1.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 844 kB
  • sloc: ruby: 4,237; makefile: 8; sh: 2
file content (48 lines) | stat: -rw-r--r-- 1,190 bytes parent folder | download | duplicates (3)
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
require 'spec_helper'

if RubyFeatures.keyword_arguments?
  describe "Ruby 2.0 keyword arguments" do
    class ExampleForKeywordArgs
      eval "def foo(x: 1); end"
      eval "def bar(x: 1, **rest); end"
    end

    before do
      extend Bogus::MockingDSL
    end

    context "with regular objects" do
      subject { ExampleForKeywordArgs.new }

      it "allows calling the method without the optional keyword args" do
        stub(subject).foo(any_args)

        subject.foo

        expect(subject).to have_received.foo
      end

      include_examples "stubbing methods with keyword arguments"
      include_examples "stubbing methods with double splat"
    end

    context "with fakes" do
      subject { fake(:example_for_keyword_args) }

      it "allows spying without stubbing" do
        subject.foo(x: "test")

        expect(subject).to have_received.foo(x: "test")
      end

      it "allows calling the method without the optional keyword args" do
        subject.foo

        expect(subject).to have_received.foo
      end

      include_examples "stubbing methods with keyword arguments"
      include_examples "stubbing methods with double splat"
    end
  end
end