pboling / flag_shih_tzu

Bit fields for ActiveRecord
http://railsbling.com/flag_shih_tzu
MIT License
496 stars 64 forks source link

Testing documentation missing #81

Closed dcangulo closed 5 years ago

dcangulo commented 5 years ago

I am using RSpec to test my app and when I used the gem, the tests starts failing. It tells me that the methods generated by this gem are undefined.

To make it work, I added the following lines in my spec/rails_helper.rb file:

RSpec.configure do |config|
  config.include FlagShihTzu
end

I would be glad to open a PR for this if you're interested.

pboling commented 5 years ago

This is a really bad solution to the problem, because what you are doing is adding FlagShihTzu's methods to every object in Ruby, and thereby probably breaking all sorts of unexpected things.

It seems that this must be happening because the gem isn't loading in your test environment by default.

This would be incorrect behavior, as it should be loading FlagShihTzu by default in all environments.

  1. Please check that you are loading the Rails environment in spec/rails_helper.rb
  2. Please check that you are requiring the gem via bundler in your Gemfile by not adding require: false:
      gem 'flag_shih_tzu`
  3. Please ensure that when you load the rails console in the test environment, the gem's methods are available on your models.
dcangulo commented 5 years ago

@pboling As per your suggestion, I decided to remove config.include FlagShihTzu from my spec/rails_helper.rb file.

I don't know what happened but it works now without it and I didn't change anything.

Thanks.