Sha256: 1171252273467bfe78bf0290bbae40fe5c1e9f259e4aa4b7aaa0043eed155e0e

Contents?: true

Size: 1.23 KB

Versions: 37

Compression:

Stored size: 1.23 KB

Contents

require "spec_helper"

describe "a double receiving to_ary" do
  shared_examples "to_ary" do
    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"

    it "does respond to to_ary" do
      expect(obj).to respond_to(:to_ary)
    end

    it "does respond to to_a" do
      expect(obj).to respond_to(:to_a)
    end

    it "returns nil" do
      expect(obj.to_ary).to eq nil
    end
  end

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

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

    it "doesn't respond to to_a", :if => ( RUBY_VERSION.to_f > 1.8 ) do
      expect(obj).not_to respond_to(:to_a)
    end

    it "raises " do
      expect { obj.to_ary }.to raise_error(NoMethodError)
    end
  end
end

Version data entries

37 entries across 37 versions & 8 rubygems

Version Path
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.4.0/gems/rspec-mocks-2.14.6/spec/rspec/mocks/to_ary_spec.rb
vagrant-unbundled-1.9.5.1 vendor/bundle/ruby/2.4.0/gems/rspec-mocks-2.14.6/spec/rspec/mocks/to_ary_spec.rb
vagrant-unbundled-1.9.1.1 vendor/bundle/ruby/2.4.0/gems/rspec-mocks-2.14.6/spec/rspec/mocks/to_ary_spec.rb
vagrant-unbundled-1.8.5.2 vendor/bundle/ruby/2.3.0/gems/rspec-mocks-2.14.6/spec/rspec/mocks/to_ary_spec.rb
vagrant-unbundled-1.8.5.1 vendor/bundle/ruby/2.3.0/gems/rspec-mocks-2.14.6/spec/rspec/mocks/to_ary_spec.rb
vagrant-unbundled-1.8.4.2 vendor/bundle/ruby/2.3.0/gems/rspec-mocks-2.14.6/spec/rspec/mocks/to_ary_spec.rb
vagrant-unbundled-1.8.4.1 vendor/bundle/ruby/2.3.0/gems/rspec-mocks-2.14.6/spec/rspec/mocks/to_ary_spec.rb
vagrant-unbundled-1.8.1.1 vendor/bundle/ruby/2.3.0/gems/rspec-mocks-2.14.6/spec/rspec/mocks/to_ary_spec.rb
rspec-mocks-2.99.4 spec/rspec/mocks/to_ary_spec.rb
vagrant-cloudstack-1.1.0 vendor/bundle/gems/rspec-mocks-2.14.6/spec/rspec/mocks/to_ary_spec.rb
rspec-mocks-2.99.3 spec/rspec/mocks/to_ary_spec.rb
rspec-mocks-2.99.2 spec/rspec/mocks/to_ary_spec.rb
dxruby_rp5-0.0.4 spec/vendor/rspec-mocks-2.14.4/spec/rspec/mocks/to_ary_spec.rb
rspec-mocks-2.99.1 spec/rspec/mocks/to_ary_spec.rb
rspec-mocks-2.99.0 spec/rspec/mocks/to_ary_spec.rb
rspec-mocks-2.99.0.rc1 spec/rspec/mocks/to_ary_spec.rb
rspec-mocks-2.14.6 spec/rspec/mocks/to_ary_spec.rb
rspec-mocks-3.0.0.beta2 spec/rspec/mocks/to_ary_spec.rb
rspec-mocks-2.99.0.beta2 spec/rspec/mocks/to_ary_spec.rb
rspec-mocks-2.14.5 spec/rspec/mocks/to_ary_spec.rb