Reputation: 730
I have a class that I'm trying to test that includes ActiveModel::Validations
module SomeModule
class SomeClass
include ActiveModel::Validations
end
end
I'm trying to test it without spec_helper
to keep it fast, but a simple require 'activemodel'
at the top of the spec doesn't work. I keep getting an uninitialized constant SomeModule::SomeClass::ActiveModel(NameError)
. for the spec file:
require 'activemodel'
describe SomeModule::SomeClass do
end
Any tips on solving this? Thanks in advance!
Upvotes: 2
Views: 1712
Reputation: 3067
You will need to include active_model
in your module/class file.
# /some_class.rb
require 'active_model'
module SomeModule
class SomeClass
include ActiveModel::Validations
end
end
Spec,
# /some_class_spec.rb
require './some_class'
describe SomeModule::SomeClass do
end
You'll want to change the paths to match your files. I doubt this will speed up your specs when run with other specs that include the whole Rails stack, but when run by itself this will be a little faster.
Upvotes: 5