Sha256: 40f1abf23c6347e9aeea72412dc8ed2ca407df73cac99f818818960e0a5ef52c

Contents?: true

Size: 1.16 KB

Versions: 2

Compression:

Stored size: 1.16 KB

Contents

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bogus-0.1.7 spec/bogus/ruby_2_support_spec.rb
bogus-0.1.6 spec/bogus/ruby_2_support_spec.rb