-
Notifications
You must be signed in to change notification settings - Fork 131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error with nested describe blocks #166
Comments
I don't believe this is a I think I found the source of this problem. Given the following, class EventPolicyTest < ActiveSupport::TestCase
Given(:event) { Event.new }
describe 'for an admin' do
Given(:user) { users(:admin) }
describe 'when not bookable' do
Given(:event) { Event.new(is_bookable: false) }
Then { assert_permit(user, event, :show) }
end
end
end and that you're probably using the following base def permit(user, record, action)
klass = self.class.superclass.to_s.gsub(/Test/, '')
klass.constantize.new(user, record).public_send("#{action.to_s}?")
end then here are the class values, when turned to a string:
Thus the problem here is that there is too much inheritance. How to fix:Change your def permit(user, record, action)
test_name = self.class.ancestors.select { |a| a.to_s.match(/PolicyTest/) }.first
klass = test_name.to_s.gsub(/Test/, '')
klass.constantize.new(user, record).public_send("#{action.to_s}?")
end Instead of just assuming the |
@rpearce |
Unfortunately this didn't work as expected. See solution here. |
I've recently updated my Rails app to 4.2.0 on Ruby 2.2.0. I'm using version 2.1.1 of minitest-rails. In certain situations, I get this error:
NameError: wrong constant name ...
when nesting describe blocks. Here's my test file:The error for all 8 tests above is
NameError: wrong constant name for an administrator
. If I remove a level of describe blocks, all tests pass as expected.The text was updated successfully, but these errors were encountered: