Sha256: eef95a7e09d22b92fc887717298692a3f8c1c91e7f1c43248378f3d50dca30eb

Contents?: true

Size: 926 Bytes

Versions: 14

Compression:

Stored size: 926 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
      obj.stub(:to_ary) { :non_nil_value }
      expect(obj.to_ary).to be(:non_nil_value)
    end

    it "responds when overriden" do
      obj.stub(:to_ary) { :non_nil_value }
      expect(obj).to respond_to(:to_ary)
    end

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

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

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

Version data entries

14 entries across 14 versions & 6 rubygems

Version Path
judge-2.0.5 vendor/bundle/ruby/2.1.0/gems/rspec-mocks-2.13.0/spec/rspec/mocks/to_ary_spec.rb
rspec-mocks-2.14.1 spec/rspec/mocks/to_ary_spec.rb
rspec-mocks-2.14.0 spec/rspec/mocks/to_ary_spec.rb
sshp-0.0.2 vendor/ruby/1.9.1/gems/rspec-mocks-2.13.1/spec/rspec/mocks/to_ary_spec.rb
sshp-0.0.1 vendor/ruby/1.9.1/gems/rspec-mocks-2.13.1/spec/rspec/mocks/to_ary_spec.rb
rspec-mocks-2.14.0.rc1 spec/rspec/mocks/to_ary_spec.rb
sidekiq-statsd-0.1.1 vendor/ruby/1.9.1/gems/rspec-mocks-2.13.1/spec/rspec/mocks/to_ary_spec.rb
sidekiq-statsd-0.1.0 vendor/ruby/1.9.1/gems/rspec-mocks-2.13.1/spec/rspec/mocks/to_ary_spec.rb
rspec-mocks-2.13.1 spec/rspec/mocks/to_ary_spec.rb
vagrant-actionio-0.0.9 vendor/bundle/gems/rspec-mocks-2.13.0/spec/rspec/mocks/to_ary_spec.rb
rspec-mocks-2.13.0 spec/rspec/mocks/to_ary_spec.rb
remq-0.0.4 vendor/bundle/gems/rspec-mocks-2.12.2/spec/rspec/mocks/to_ary_spec.rb
remq-0.0.3 vendor/bundle/gems/rspec-mocks-2.12.2/spec/rspec/mocks/to_ary_spec.rb
rspec-mocks-2.12.2 spec/rspec/mocks/to_ary_spec.rb