Reputation: 6652
How can I get the main class that is being described in RSpec 3? For example, I have the following spec:
describe User do
describe "fetching" do
describe "all" do
subject { described_class.new }
end
end
end
subject
currently returns something similar to User::fetching::all
but I want it to return User
only.
Upvotes: 3
Views: 6890
Reputation: 16793
Not sure I'm understanding your question correctly, but as far as I can see, if you just want to get the class name constant within your test, just using described_class
(without .new
) should get you what you want:
class User; end
describe User do
subject { described_class }
it { is_expected.to eq(User) }
end
Upvotes: 6