Sha256: 1c51e582aff2c30e12f0c0c7ca4a083f9d3765fbd539e073552e184ffa83938f

Contents?: true

Size: 1022 Bytes

Versions: 16

Compression:

Stored size: 1022 Bytes

Contents

require "spec_helper"

describe "a double receiving to_ary" do
  shared_examples "to_ary" do
    it "returns nil" do
      expect do
        expect(obj.to_ary).to be_nil
      end.to raise_error(NoMethodError)
    end

    it "doesn't respond" do
      expect(obj).not_to respond_to(:to_ary)
    end

    it "can be overridden with a stub" do
      Spy::Subroutine.new(obj, :to_ary).hook(force: true).and_return(:non_nil_value)
      expect(obj.to_ary).to be(:non_nil_value)
    end

    it "responds when overriden" do
      Spy::Subroutine.new(obj, :to_ary).hook(force: true).and_return(:non_nil_value)
      expect(obj).to respond_to(:to_ary)
    end

    it "supports Array#flatten" do
      obj = Spy.double('foo')
      expect([obj].flatten).to eq([obj])
    end
  end

  context "double as_null_object" do
    let(:obj) { Spy.double('obj').as_null_object }
    include_examples "to_ary"
  end

  context "double without as_null_object" do
    let(:obj) { Spy.double('obj') }
    include_examples "to_ary"
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
spy-1.0.3 spec/spy/to_ary_spec.rb
spy-1.0.2 spec/spy/to_ary_spec.rb
spy-1.0.1 spec/spy/to_ary_spec.rb
spy-1.0.0 spec/spy/to_ary_spec.rb
spy-0.4.5 spec/spy/to_ary_spec.rb
spy-0.4.3 spec/spy/to_ary_spec.rb
spy-0.4.2 spec/spy/to_ary_spec.rb
spy-0.4.1 spec/spy/to_ary_spec.rb
spy-0.4.0 spec/spy/to_ary_spec.rb
spy-0.3.1 spec/spy/to_ary_spec.rb
spy-0.3.0 spec/spy/to_ary_spec.rb
spy-0.2.5 spec/spy/to_ary_spec.rb
spy-0.2.4 spec/spy/to_ary_spec.rb
spy-0.2.3 spec/spy/to_ary_spec.rb
spy-0.2.2 spec/spy/to_ary_spec.rb
spy-0.2.1 spec/spy/to_ary_spec.rb