Sha256: 89ee2bb6e39eba2e52a2628d508aa448a4c00a3267ebd4734a95dc433585c05e

Contents?: true

Size: 1.23 KB

Versions: 9

Compression:

Stored size: 1.23 KB

Contents

RSpec.describe "a double receiving to_ary" do
  shared_examples "to_ary" do
    it "can be overridden with a stub" do
      allow(obj).to receive(:to_ary) { :non_nil_value }
      expect(obj.to_ary).to be(:non_nil_value)
    end

    it "responds when overriden" do
      allow(obj).to receive(: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

9 entries across 9 versions & 2 rubygems

Version Path
opal-rspec-0.6.2 rspec-mocks/spec/rspec/mocks/to_ary_spec.rb
opal-rspec-0.6.1 rspec-mocks/spec/rspec/mocks/to_ary_spec.rb
opal-rspec-0.6.0 rspec-mocks/spec/rspec/mocks/to_ary_spec.rb
opal-rspec-0.6.0.beta1 rspec-mocks/spec/rspec/mocks/to_ary_spec.rb
opal-connect-rspec-0.5.0 rspec-mocks/spec/rspec/mocks/to_ary_spec.rb
opal-rspec-0.5.0 rspec-mocks/spec/rspec/mocks/to_ary_spec.rb
opal-rspec-0.5.0.beta3 rspec-mocks/spec/rspec/mocks/to_ary_spec.rb
opal-rspec-0.5.0.beta2 rspec-mocks/spec/rspec/mocks/to_ary_spec.rb
opal-rspec-0.5.0.beta1 rspec-mocks/spec/rspec/mocks/to_ary_spec.rb