Rails Fixtures not loading with rspec
If you want to set up your fixtures globally, inside your spec_helper
or rails_helper
you can add:
RSpec.configure do |config|
config.global_fixtures = :all
end
It took me a really long time to figure this out myself.
# spec/rails_helper.rb
RSpec.configure do |config|
# config.file_fixture_path = Rails.root / 'test' / 'fixtures' # <= incorrect
config.fixture_path = Rails.root / 'test' / 'fixtures'
then, as stated on other comments, use
RSpec.describe 'Events API', type: :request do
fixtures :events
If you define fixtures as 'users', then the way to use them is via the method with the same name:
describe PagesController do
integrate_views
fixtures :users
it "should render index template on index call when logged in" do
session[:user_id] = users(:foo).id
get 'index'
response.should render_template('index')
end
end
The singular is only relevant to the class itself (User). Hope you still have some hair left if this is just a one letter bug.