Skip to content

described_class behavior doesn't make sense when inner block is not a Class #31

@betesh

Description

@betesh

Gemfile:
gem 'rspec', '= 3.0.0'

spec/described_class_spec.rb:

describe Array do
  describe 'a string' do
     it { expect(described_class).to eq(Array) }
  end

  describe :a_symbol do
    it { expect(described_class).to eq(Array) }
  end

  describe Hash do
    it { expect(described_class).to eq(Hash) }
  end

  describe Hash.new do
    it { expect(described_class).to eq(Hash) }
  end
end

This results in two errors--one on :a_symbol and one on Hash.new. IMO this behavior is non-intuitive. rspec/rspec-core#1114 seems to have made an exception for when the inner describe is an instance of String, which makes sense, because described_class.should be_a(Class). However, I argue that this should be consistent for all cases where the inner describe is not a Class. Either take its class, or skip it and move to the outer describe block, but don't return an instance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureFreature request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions