A new project with the RSpec 3.2 and Rails 4.2.
As a good citizen I'm trying to do the "right" thing with the new RSpec (disable monkey patching, do not infer the type of examples etc).
The problem I have is that I want to test this little class:
# app/models/session.rb
class Session # NOTE: This is a simple transient class, almost plain Ruby class
include ActiveModel::Model
attr_accessor :email, :password
end
with something like:
# spec/models/session_spec.rb
require 'spec_helper'
RSpec.describe Session, type: :model do
it { should validate_presence_of :email }
it { should validate_presence_of :password }
end
Obviously, when I run the spec I'm getting the uninitialized constant Session (NameError) which makes sense as the 'spec_helper' does not do anything to load that particular class.
I could have user the rails_helper instead but that is simply too much for that little class since it has nothing to do with rails at all.
Willing to do "the right" I'm puzzled with the following questions
- Does the
Sessionspec even need to be marked withtype: :model? - Should I modify the
spec_helperto change the$LOAD_PATH? - If not, is there a way to autoload
session.rbfile but without loading up the whole Rails? - Should the transient
Sessionclass be underapp/models? I treat it as a model, it's just not persistent.
The easiest thing to do is of course to just use rails_helper, but for what I need to do that is unnecessary and I'd love to keep the spec file fast.
Aucun commentaire:
Enregistrer un commentaire