RSpec troubleshooting
22 Aug 2016RSpec cannot find any project classes
NameError: uninitialized constant TestService
solution
by default rails generate rspec:install
creates this .rspec:
--color
--require spec_helper
but all project files are required in spec/rails_helper.rb using this line:
require File.expand_path('../../config/environment', __FILE__)
also spec/rails_helper.rb requires spec/spec_helper.rb.
=> just require rails_helper
instead of spec_helper
in .rspec:
--color
--require rails_helper
empty response when rendering views in specs
rendering views mysteriously returns empty string even though proper template must have been found (if renamed it’s not found).
solution
by default RSpec doesn’t render views - enable rendering by including this line in your spec:
render_views
Guard cannot find rspec
bundler: failed to load command: rspec (/Users/tap/.rbenv/versions/2.3.1/bin/rspec)
LoadError: cannot load such file -- rspec
solution
make sure rspec
gem is added in Gemfile:
group :development, :test do
...
gem `rspec`
...
end
undefined method `create’
when running specs (with guard
or via bundle exec rspec
):
NoMethodError:
undefined method `create' for #<RSpec::ExampleGroups::UserSave::SuccessExistingUserWithTheSameUid:0x00007fa728b8efd0>
solution
rails_helper.rb:
RSpec.configure do |config|
# ...
+ config.include FactoryBot::Syntax::Methods
end